aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-05 21:25:15 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-05 21:25:15 +0000
commit1bb552b1d9da749050274e0a9cb10b672db22d77 (patch)
treea638c7bbef95bd2c9d72c2e16a5cf4f7b6298458
parent9020d850bf2b0fd547b545e5e366c7ed284a33cb (diff)
downloadbusybox-w32-1bb552b1d9da749050274e0a9cb10b672db22d77.tar.gz
busybox-w32-1bb552b1d9da749050274e0a9cb10b672db22d77.tar.bz2
busybox-w32-1bb552b1d9da749050274e0a9cb10b672db22d77.zip
libbb: add xunlink()
patch: do not try to delete same file twice
-rw-r--r--archival/bbunzip.c3
-rw-r--r--editors/patch.c9
-rw-r--r--include/libbb.h17
-rw-r--r--libbb/xfuncs.c6
4 files changed, 19 insertions, 16 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index e16e6b083..3c3cc2886 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -105,8 +105,7 @@ int bbunpack(char **argv,
105 if (new_name == filename) 105 if (new_name == filename)
106 filename[strlen(filename)] = '.'; 106 filename[strlen(filename)] = '.';
107 } 107 }
108 if (unlink(del) < 0) 108 xunlink(del);
109 bb_perror_msg_and_die("cannot remove %s", del);
110 109
111#if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */ 110#if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
112 /* Extreme bloat for gunzip compat */ 111 /* Extreme bloat for gunzip compat */
diff --git a/editors/patch.c b/editors/patch.c
index 2c908040f..4d1425edc 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -260,12 +260,9 @@ int patch_main(int argc, char **argv)
260 } 260 }
261 if ((dest_cur_line == 0) || (dest_beg_line == 0)) { 261 if ((dest_cur_line == 0) || (dest_beg_line == 0)) {
262 /* The new patched file is empty, remove it */ 262 /* The new patched file is empty, remove it */
263 if (unlink(new_filename) == -1) { 263 xunlink(new_filename);
264 bb_perror_msg_and_die("cannot remove file %s", new_filename); 264 if (strcmp(new_filename, original_filename) != 0)
265 } 265 xunlink(original_filename);
266 if (unlink(original_filename) == -1) {
267 bb_perror_msg_and_die("cannot remove original file %s", new_filename);
268 }
269 } 266 }
270 } 267 }
271 } 268 }
diff --git a/include/libbb.h b/include/libbb.h
index 91715c16a..b56352626 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -293,14 +293,15 @@ extern void sig_pause(void);
293 293
294 294
295 295
296extern void xsetgid(gid_t gid); 296void xsetgid(gid_t gid);
297extern void xsetuid(uid_t uid); 297void xsetuid(uid_t uid);
298extern void xchdir(const char *path); 298void xchdir(const char *path);
299extern void xsetenv(const char *key, const char *value); 299void xsetenv(const char *key, const char *value);
300extern int xopen(const char *pathname, int flags); 300void xunlink(const char *pathname);
301extern int xopen3(const char *pathname, int flags, int mode); 301int xopen(const char *pathname, int flags);
302extern off_t xlseek(int fd, off_t offset, int whence); 302int xopen3(const char *pathname, int flags, int mode);
303extern off_t fdlength(int fd); 303off_t xlseek(int fd, off_t offset, int whence);
304off_t fdlength(int fd);
304 305
305 306
306int xsocket(int domain, int type, int protocol); 307int xsocket(int domain, int type, int protocol);
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index b08f92d81..c18a1d998 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -122,6 +122,12 @@ int xopen3(const char *pathname, int flags, int mode)
122 return ret; 122 return ret;
123} 123}
124 124
125void xunlink(const char *pathname)
126{
127 if (unlink(pathname))
128 bb_perror_msg_and_die("cannot remove file '%s'", pathname);
129}
130
125// Turn on nonblocking I/O on a fd 131// Turn on nonblocking I/O on a fd
126int ndelay_on(int fd) 132int ndelay_on(int fd)
127{ 133{