diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-13 12:45:04 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-13 12:45:04 +0000 |
commit | c2cb0f32b44a9918364af39c24b5643388c553f6 (patch) | |
tree | 378b5a002da81f8622913cc6a9aeac873e307ec9 | |
parent | 4f3d2deaa499af34c22a7f9be121131b0a5894b5 (diff) | |
download | busybox-w32-c2cb0f32b44a9918364af39c24b5643388c553f6.tar.gz busybox-w32-c2cb0f32b44a9918364af39c24b5643388c553f6.tar.bz2 busybox-w32-c2cb0f32b44a9918364af39c24b5643388c553f6.zip |
- patch from Denis Vlasenko to add and use bb_xopen3()
-rw-r--r-- | archival/gzip.c | 2 | ||||
-rw-r--r-- | coreutils/dd.c | 19 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/Makefile.in | 2 | ||||
-rw-r--r-- | libbb/xfuncs.c | 13 | ||||
-rw-r--r-- | miscutils/crontab.c | 29 | ||||
-rw-r--r-- | miscutils/mt.c | 3 | ||||
-rw-r--r-- | miscutils/rx.c | 10 | ||||
-rw-r--r-- | modutils/insmod.c | 19 | ||||
-rw-r--r-- | networking/vconfig.c | 3 | ||||
-rw-r--r-- | util-linux/mkfs_minix.c | 4 | ||||
-rw-r--r-- | util-linux/mkswap.c | 4 |
12 files changed, 38 insertions, 71 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 5fb118706..c31706af3 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -1228,7 +1228,7 @@ int gzip_main(int argc, char **argv) | |||
1228 | inFileNum = STDIN_FILENO; | 1228 | inFileNum = STDIN_FILENO; |
1229 | outFileNum = STDOUT_FILENO; | 1229 | outFileNum = STDOUT_FILENO; |
1230 | } else { | 1230 | } else { |
1231 | inFileNum = bb_xopen(argv[i], O_RDONLY); | 1231 | inFileNum = bb_xopen3(argv[i], O_RDONLY, 0); |
1232 | if (fstat(inFileNum, &statBuf) < 0) | 1232 | if (fstat(inFileNum, &statBuf) < 0) |
1233 | bb_perror_msg_and_die("%s", argv[i]); | 1233 | bb_perror_msg_and_die("%s", argv[i]); |
1234 | time_stamp = statBuf.st_ctime; | 1234 | time_stamp = statBuf.st_ctime; |
diff --git a/coreutils/dd.c b/coreutils/dd.c index cba90857f..ce8bcc6a5 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -5,20 +5,7 @@ | |||
5 | * | 5 | * |
6 | * Copyright (C) 2000,2001 Matt Kraai | 6 | * Copyright (C) 2000,2001 Matt Kraai |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | 9 | */ |
23 | 10 | ||
24 | #include <sys/types.h> | 11 | #include <sys/types.h> |
@@ -119,9 +106,7 @@ int dd_main(int argc, char **argv) | |||
119 | oflag |= O_TRUNC; | 106 | oflag |= O_TRUNC; |
120 | } | 107 | } |
121 | 108 | ||
122 | if ((ofd = open(outfile, oflag, 0666)) < 0) { | 109 | ofd = bb_xopen3(outfile, oflag, 0666); |
123 | bb_perror_msg_and_die("%s", outfile); | ||
124 | } | ||
125 | 110 | ||
126 | if (seek && trunc_flag) { | 111 | if (seek && trunc_flag) { |
127 | if (ftruncate(ofd, seek * bs) < 0) { | 112 | if (ftruncate(ofd, seek * bs) < 0) { |
diff --git a/include/libbb.h b/include/libbb.h index e1ac912f6..8fc2dbbc8 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -440,6 +440,7 @@ extern struct spwd *pwd_to_spwd(const struct passwd *pw); | |||
440 | extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); | 440 | extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); |
441 | 441 | ||
442 | extern int bb_xopen(const char *pathname, int flags); | 442 | extern int bb_xopen(const char *pathname, int flags); |
443 | extern int bb_xopen3(const char *pathname, int flags, int mode); | ||
443 | extern ssize_t bb_xread(int fd, void *buf, size_t count); | 444 | extern ssize_t bb_xread(int fd, void *buf, size_t count); |
444 | extern void bb_xread_all(int fd, void *buf, size_t count); | 445 | extern void bb_xread_all(int fd, void *buf, size_t count); |
445 | extern unsigned char bb_xread_char(int fd); | 446 | extern unsigned char bb_xread_char(int fd); |
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index eac14c60c..102047d73 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
@@ -68,7 +68,7 @@ $(LIBBB_MOBJ0):$(LIBBB_MSRC0) | |||
68 | 68 | ||
69 | LIBBB_MSRC1:=$(srcdir)/xfuncs.c | 69 | LIBBB_MSRC1:=$(srcdir)/xfuncs.c |
70 | LIBBB_MOBJ1:=xmalloc.o xrealloc.o xcalloc.o xstrdup.o xstrndup.o \ | 70 | LIBBB_MOBJ1:=xmalloc.o xrealloc.o xcalloc.o xstrdup.o xstrndup.o \ |
71 | xfopen.o xopen.o xread.o xread_all.o xread_char.o \ | 71 | xfopen.o xopen.o xopen3.o xread.o xread_all.o xread_char.o \ |
72 | xferror.o xferror_stdout.o xfflush_stdout.o strlen.o | 72 | xferror.o xferror_stdout.o xfflush_stdout.o strlen.o |
73 | LIBBB_MOBJ1:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ1)) | 73 | LIBBB_MOBJ1:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ1)) |
74 | $(LIBBB_MOBJ1):$(LIBBB_MSRC1) | 74 | $(LIBBB_MOBJ1):$(LIBBB_MSRC1) |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 9ee4fcd65..3db526b85 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -100,10 +100,17 @@ FILE *bb_xfopen(const char *path, const char *mode) | |||
100 | #ifdef L_xopen | 100 | #ifdef L_xopen |
101 | int bb_xopen(const char *pathname, int flags) | 101 | int bb_xopen(const char *pathname, int flags) |
102 | { | 102 | { |
103 | return bb_xopen3(pathname, flags, 0777); | ||
104 | } | ||
105 | #endif | ||
106 | |||
107 | #ifdef L_xopen3 | ||
108 | int bb_xopen3(const char *pathname, int flags, int mode) | ||
109 | { | ||
103 | int ret; | 110 | int ret; |
104 | 111 | ||
105 | ret = open(pathname, flags, 0777); | 112 | ret = open(pathname, flags, mode); |
106 | if (ret == -1) { | 113 | if (ret < 0) { |
107 | bb_perror_msg_and_die("%s", pathname); | 114 | bb_perror_msg_and_die("%s", pathname); |
108 | } | 115 | } |
109 | return ret; | 116 | return ret; |
@@ -116,7 +123,7 @@ ssize_t bb_xread(int fd, void *buf, size_t count) | |||
116 | ssize_t size; | 123 | ssize_t size; |
117 | 124 | ||
118 | size = read(fd, buf, count); | 125 | size = read(fd, buf, count); |
119 | if (size == -1) { | 126 | if (size < 0) { |
120 | bb_perror_msg_and_die(bb_msg_read_error); | 127 | bb_perror_msg_and_die(bb_msg_read_error); |
121 | } | 128 | } |
122 | return(size); | 129 | return(size); |
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 703d01ecc..1b2f46f3a 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -179,20 +179,16 @@ crontab_main(int ac, char **av) | |||
179 | char buf[1024]; | 179 | char buf[1024]; |
180 | 180 | ||
181 | snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid()); | 181 | snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid()); |
182 | if ((fd = open(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600)) >= 0) { | 182 | fd = bb_xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600); |
183 | chown(tmp, getuid(), getgid()); | 183 | chown(tmp, getuid(), getgid()); |
184 | if ((fi = fopen(pas->pw_name, "r"))) { | 184 | if ((fi = fopen(pas->pw_name, "r"))) { |
185 | while ((n = fread(buf, 1, sizeof(buf), fi)) > 0) | 185 | while ((n = fread(buf, 1, sizeof(buf), fi)) > 0) |
186 | write(fd, buf, n); | 186 | write(fd, buf, n); |
187 | } | ||
188 | EditFile(caller, tmp); | ||
189 | remove(tmp); | ||
190 | lseek(fd, 0L, 0); | ||
191 | repFd = fd; | ||
192 | } else { | ||
193 | bb_error_msg_and_die("unable to create %s", tmp); | ||
194 | } | 187 | } |
195 | 188 | EditFile(caller, tmp); | |
189 | remove(tmp); | ||
190 | lseek(fd, 0L, 0); | ||
191 | repFd = fd; | ||
196 | } | 192 | } |
197 | option = REPLACE; | 193 | option = REPLACE; |
198 | /* fall through */ | 194 | /* fall through */ |
@@ -289,11 +285,8 @@ GetReplaceStream(const char *user, const char *file) | |||
289 | if (ChangeUser(user, 0) < 0) | 285 | if (ChangeUser(user, 0) < 0) |
290 | exit(0); | 286 | exit(0); |
291 | 287 | ||
292 | fd = open(file, O_RDONLY); | 288 | bb_default_error_retval = 0; |
293 | if (fd < 0) { | 289 | fd = bb_xopen3(file, O_RDONLY, 0); |
294 | bb_error_msg("unable to open %s", file); | ||
295 | exit(0); | ||
296 | } | ||
297 | buf[0] = 0; | 290 | buf[0] = 0; |
298 | write(filedes[1], buf, 1); | 291 | write(filedes[1], buf, 1); |
299 | while ((n = read(fd, buf, sizeof(buf))) > 0) { | 292 | while ((n = read(fd, buf, sizeof(buf))) > 0) { |
diff --git a/miscutils/mt.c b/miscutils/mt.c index 44efedbe3..368fc66b9 100644 --- a/miscutils/mt.c +++ b/miscutils/mt.c | |||
@@ -101,8 +101,7 @@ int mt_main(int argc, char **argv) | |||
101 | break; | 101 | break; |
102 | } | 102 | } |
103 | 103 | ||
104 | if ((fd = open(file, mode, 0)) < 0) | 104 | fd = bb_xopen3(file, mode, 0); |
105 | bb_perror_msg_and_die("%s", file); | ||
106 | 105 | ||
107 | switch (code->value) { | 106 | switch (code->value) { |
108 | case MTTELL: | 107 | case MTTELL: |
diff --git a/miscutils/rx.c b/miscutils/rx.c index c7e82ead5..3df461349 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /*------------------------------------------------------------------------- | 2 | /*------------------------------------------------------------------------- |
2 | * Filename: xmodem.c | 3 | * Filename: xmodem.c |
3 | * Version: $Id: rx.c,v 1.2 2004/03/15 08:28:46 andersen Exp $ | 4 | * Version: $Id: rx.c,v 1.2 2004/03/15 08:28:46 andersen Exp $ |
@@ -289,13 +290,8 @@ int rx_main(int argc, char **argv) | |||
289 | bb_show_usage(); | 290 | bb_show_usage(); |
290 | 291 | ||
291 | fn = argv[1]; | 292 | fn = argv[1]; |
292 | ttyfd = open("/dev/tty", O_RDWR); | 293 | ttyfd = bb_xopen3("/dev/tty", O_RDWR, 0); |
293 | if (ttyfd < 0) | 294 | filefd = bb_xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666); |
294 | bb_error_msg_and_die("%s: open on /dev/tty failed: %m\n", argv[0]); | ||
295 | |||
296 | filefd = open(fn, O_RDWR|O_CREAT|O_TRUNC, 0666); | ||
297 | if (filefd < 0) | ||
298 | bb_error_msg_and_die("%s: open on %s failed: %m\n", argv[0], fn); | ||
299 | 295 | ||
300 | if (tcgetattr(ttyfd, &tty) < 0) | 296 | if (tcgetattr(ttyfd, &tty) < 0) |
301 | bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]); | 297 | bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]); |
diff --git a/modutils/insmod.c b/modutils/insmod.c index 2eebf560f..f38daa257 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
@@ -55,20 +55,7 @@ | |||
55 | * Restructured (and partly rewritten) by: | 55 | * Restructured (and partly rewritten) by: |
56 | * Björn Ekwall <bj0rn@blox.se> February 1999 | 56 | * Björn Ekwall <bj0rn@blox.se> February 1999 |
57 | * | 57 | * |
58 | * This program is free software; you can redistribute it and/or modify | 58 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
59 | * it under the terms of the GNU General Public License as published by | ||
60 | * the Free Software Foundation; either version 2 of the License, or | ||
61 | * (at your option) any later version. | ||
62 | * | ||
63 | * This program is distributed in the hope that it will be useful, | ||
64 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
65 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
66 | * General Public License for more details. | ||
67 | * | ||
68 | * You should have received a copy of the GNU General Public License | ||
69 | * along with this program; if not, write to the Free Software | ||
70 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
71 | * | ||
72 | */ | 59 | */ |
73 | 60 | ||
74 | #include <stdlib.h> | 61 | #include <stdlib.h> |
@@ -4297,9 +4284,7 @@ int insmod_ng_main( int argc, char **argv) | |||
4297 | strcat(options, " "); | 4284 | strcat(options, " "); |
4298 | } | 4285 | } |
4299 | 4286 | ||
4300 | if ((fd = open(filename, O_RDONLY, 0)) < 0) { | 4287 | fd = bb_xopen3(filename, O_RDONLY, 0); |
4301 | bb_perror_msg_and_die("cannot open module `%s'", filename); | ||
4302 | } | ||
4303 | 4288 | ||
4304 | fstat(fd, &st); | 4289 | fstat(fd, &st); |
4305 | len = st.st_size; | 4290 | len = st.st_size; |
diff --git a/networking/vconfig.c b/networking/vconfig.c index 72729c7ed..6cbbb54ca 100644 --- a/networking/vconfig.c +++ b/networking/vconfig.c | |||
@@ -123,7 +123,8 @@ int vconfig_main(int argc, char **argv) | |||
123 | } | 123 | } |
124 | 124 | ||
125 | /* Don't bother closing the filedes. It will be closed on cleanup. */ | 125 | /* Don't bother closing the filedes. It will be closed on cleanup. */ |
126 | bb_xopen(conf_file_name, O_RDONLY); /* Will die if 802.1q is not present */ | 126 | /* Will die if 802.1q is not present */ |
127 | bb_xopen3(conf_file_name, O_RDONLY, 0); | ||
127 | 128 | ||
128 | memset(&ifr, 0, sizeof(struct vlan_ioctl_args)); | 129 | memset(&ifr, 0, sizeof(struct vlan_ioctl_args)); |
129 | 130 | ||
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c index 30bc9f12d..d9388b1d7 100644 --- a/util-linux/mkfs_minix.c +++ b/util-linux/mkfs_minix.c | |||
@@ -307,7 +307,7 @@ static inline int get_size(const char *file) | |||
307 | int fd; | 307 | int fd; |
308 | long size; | 308 | long size; |
309 | 309 | ||
310 | fd = bb_xopen(file, O_RDWR); | 310 | fd = bb_xopen3(file, O_RDWR, 0); |
311 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { | 311 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
312 | close(fd); | 312 | close(fd); |
313 | return (size * 512); | 313 | return (size * 512); |
@@ -820,7 +820,7 @@ goodbye: | |||
820 | tmp += dirsize; | 820 | tmp += dirsize; |
821 | *(short *) tmp = 2; | 821 | *(short *) tmp = 2; |
822 | strcpy(tmp + 2, ".badblocks"); | 822 | strcpy(tmp + 2, ".badblocks"); |
823 | DEV = bb_xopen(device_name, O_RDWR); | 823 | DEV = bb_xopen3(device_name, O_RDWR, 0); |
824 | if (fstat(DEV, &statbuf) < 0) | 824 | if (fstat(DEV, &statbuf) < 0) |
825 | bb_error_msg_and_die("unable to stat %s", device_name); | 825 | bb_error_msg_and_die("unable to stat %s", device_name); |
826 | if (!S_ISBLK(statbuf.st_mode)) | 826 | if (!S_ISBLK(statbuf.st_mode)) |
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index 32021fe08..44d809a36 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c | |||
@@ -258,7 +258,7 @@ static inline long get_size(const char *file) | |||
258 | int fd; | 258 | int fd; |
259 | long size; | 259 | long size; |
260 | 260 | ||
261 | fd = bb_xopen(file, O_RDONLY); | 261 | fd = bb_xopen3(file, O_RDONLY, 0); |
262 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { | 262 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
263 | size /= pagesize / 512; | 263 | size /= pagesize / 512; |
264 | } else { | 264 | } else { |
@@ -341,7 +341,7 @@ int mkswap_main(int argc, char **argv) | |||
341 | PAGES * goodpages); | 341 | PAGES * goodpages); |
342 | } | 342 | } |
343 | 343 | ||
344 | DEV = bb_xopen(device_name, O_RDWR); | 344 | DEV = bb_xopen3(device_name, O_RDWR, 0); |
345 | if (fstat(DEV, &statbuf) < 0) | 345 | if (fstat(DEV, &statbuf) < 0) |
346 | bb_perror_msg_and_die("%s", device_name); | 346 | bb_perror_msg_and_die("%s", device_name); |
347 | if (!S_ISBLK(statbuf.st_mode)) | 347 | if (!S_ISBLK(statbuf.st_mode)) |