OSDN Git Service

libbb: add xunlink()
authorDenis Vlasenko <vda.linux@googlemail.com>
Thu, 5 Apr 2007 21:25:15 +0000 (21:25 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Thu, 5 Apr 2007 21:25:15 +0000 (21:25 -0000)
patch: do not try to delete same file twice

archival/bbunzip.c
editors/patch.c
include/libbb.h
libbb/xfuncs.c

index e16e6b0..3c3cc28 100644 (file)
@@ -105,8 +105,7 @@ int bbunpack(char **argv,
                                if (new_name == filename)
                                        filename[strlen(filename)] = '.';
                        }
-                       if (unlink(del) < 0)
-                               bb_perror_msg_and_die("cannot remove %s", del);
+                       xunlink(del);
 
 #if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
                        /* Extreme bloat for gunzip compat */
index 2c90804..4d1425e 100644 (file)
@@ -260,12 +260,9 @@ int patch_main(int argc, char **argv)
                        }
                        if ((dest_cur_line == 0) || (dest_beg_line == 0)) {
                                /* The new patched file is empty, remove it */
-                               if (unlink(new_filename) == -1) {
-                                       bb_perror_msg_and_die("cannot remove file %s", new_filename);
-                               }
-                               if (unlink(original_filename) == -1) {
-                                       bb_perror_msg_and_die("cannot remove original file %s", new_filename);
-                               }
+                               xunlink(new_filename);
+                               if (strcmp(new_filename, original_filename) != 0)
+                                       xunlink(original_filename);
                        }
                }
        }
index 91715c1..b563526 100644 (file)
@@ -293,14 +293,15 @@ extern void sig_pause(void);
 
 
 
-extern void xsetgid(gid_t gid);
-extern void xsetuid(uid_t uid);
-extern void xchdir(const char *path);
-extern void xsetenv(const char *key, const char *value);
-extern int xopen(const char *pathname, int flags);
-extern int xopen3(const char *pathname, int flags, int mode);
-extern off_t xlseek(int fd, off_t offset, int whence);
-extern off_t fdlength(int fd);
+void xsetgid(gid_t gid);
+void xsetuid(uid_t uid);
+void xchdir(const char *path);
+void xsetenv(const char *key, const char *value);
+void xunlink(const char *pathname);
+int xopen(const char *pathname, int flags);
+int xopen3(const char *pathname, int flags, int mode);
+off_t xlseek(int fd, off_t offset, int whence);
+off_t fdlength(int fd);
 
 
 int xsocket(int domain, int type, int protocol);
index b08f92d..c18a1d9 100644 (file)
@@ -122,6 +122,12 @@ int xopen3(const char *pathname, int flags, int mode)
        return ret;
 }
 
+void xunlink(const char *pathname)
+{
+       if (unlink(pathname))
+               bb_perror_msg_and_die("cannot remove file '%s'", pathname);
+}
+
 // Turn on nonblocking I/O on a fd
 int ndelay_on(int fd)
 {