aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-09-27 02:43:35 +0000
committerMatt Kraai <kraai@debian.org>2000-09-27 02:43:35 +0000
commitbbaef66b3f99213f06adf04df6b3e5e61278d75b (patch)
tree3838db4158e8e05a753fffd6e87cbbc7946425ad
parente0bcce09baff576b1b16b3ffe780b6d91c7710c2 (diff)
downloadbusybox-w32-bbaef66b3f99213f06adf04df6b3e5e61278d75b.tar.gz
busybox-w32-bbaef66b3f99213f06adf04df6b3e5e61278d75b.tar.bz2
busybox-w32-bbaef66b3f99213f06adf04df6b3e5e61278d75b.zip
Consolidate handling of some fopen failures.
-rw-r--r--console-tools/loadacm.c5
-rw-r--r--coreutils/wc.c9
-rw-r--r--editors/sed.c4
-rw-r--r--hostname.c20
-rw-r--r--lash.c5
-rw-r--r--loadacm.c5
-rw-r--r--more.c6
-rw-r--r--networking/hostname.c20
-rw-r--r--sed.c4
-rw-r--r--sh.c5
-rw-r--r--shell/lash.c5
-rw-r--r--util-linux/more.c6
-rw-r--r--utility.c2
-rw-r--r--wc.c9
14 files changed, 32 insertions, 73 deletions
diff --git a/console-tools/loadacm.c b/console-tools/loadacm.c
index 826c2a33f..f57737925 100644
--- a/console-tools/loadacm.c
+++ b/console-tools/loadacm.c
@@ -330,10 +330,7 @@ void saveoldmap(int fd, char *omfil)
330 } 330 }
331#endif 331#endif
332 332
333 if ((fp = fopen(omfil, "w")) == NULL) { 333 fp = xfopen(omfil, "w");
334 perror(omfil);
335 exit(1);
336 }
337#ifdef GIO_UNISCRNMAP 334#ifdef GIO_UNISCRNMAP
338 if (is_old_map) { 335 if (is_old_map) {
339#endif 336#endif
diff --git a/coreutils/wc.c b/coreutils/wc.c
index b1c9a51cd..9d569459d 100644
--- a/coreutils/wc.c
+++ b/coreutils/wc.c
@@ -134,13 +134,10 @@ int wc_main(int argc, char **argv)
134 134
135 if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) { 135 if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
136 wc_file(stdin, ""); 136 wc_file(stdin, "");
137 exit(TRUE); 137 return EXIT_SUCCESS;
138 } else { 138 } else {
139 while (optind < argc) { 139 while (optind < argc) {
140 file = fopen(argv[optind], "r"); 140 file = xfopen(argv[optind], "r");
141 if (file == NULL) {
142 fatalError(argv[optind]);
143 }
144 wc_file(file, argv[optind]); 141 wc_file(file, argv[optind]);
145 num_files_counted++; 142 num_files_counted++;
146 optind++; 143 optind++;
@@ -151,5 +148,5 @@ int wc_main(int argc, char **argv)
151 print_counts(total_lines, total_words, total_chars, 148 print_counts(total_lines, total_words, total_chars,
152 max_length, "total"); 149 max_length, "total");
153 150
154 return 0 ; 151 return EXIT_SUCCESS;
155} 152}
diff --git a/editors/sed.c b/editors/sed.c
index cb3f1bbf1..75435f67a 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -472,9 +472,7 @@ static void load_cmd_file(char *filename)
472 char *line; 472 char *line;
473 char *nextline; 473 char *nextline;
474 474
475 cmdfile = fopen(filename, "r"); 475 cmdfile = xfopen(filename, "r");
476 if (cmdfile == NULL)
477 fatalError(strerror(errno));
478 476
479 while ((line = get_line_from_file(cmdfile)) != NULL) { 477 while ((line = get_line_from_file(cmdfile)) != NULL) {
480 /* if a line ends with '\' it needs the next line appended to it */ 478 /* if a line ends with '\' it needs the next line appended to it */
diff --git a/hostname.c b/hostname.c
index 4320a968c..16a28ca43 100644
--- a/hostname.c
+++ b/hostname.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: hostname.c,v 1.13 2000/09/25 21:45:57 andersen Exp $ 3 * $Id: hostname.c,v 1.14 2000/09/27 02:43:35 kraai Exp $
4 * Mini hostname implementation for busybox 4 * Mini hostname implementation for busybox
5 * 5 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -46,18 +46,14 @@ void do_sethostname(char *s, int isfile)
46 exit(1); 46 exit(1);
47 } 47 }
48 } else { 48 } else {
49 if ((f = fopen(s, "r")) == NULL) { 49 f = xfopen(s, "r");
50 perror(s); 50 fgets(buf, 255, f);
51 fclose(f);
52 if (buf[strlen(buf) - 1] == '\n')
53 buf[strlen(buf) - 1] = 0;
54 if (sethostname(buf, strlen(buf)) < 0) {
55 perror("sethostname");
51 exit(1); 56 exit(1);
52 } else {
53 fgets(buf, 255, f);
54 fclose(f);
55 if (buf[strlen(buf) - 1] == '\n')
56 buf[strlen(buf) - 1] = 0;
57 if (sethostname(buf, strlen(buf)) < 0) {
58 perror("sethostname");
59 exit(1);
60 }
61 } 57 }
62 } 58 }
63} 59}
diff --git a/lash.c b/lash.c
index 77efc6aac..b10614259 100644
--- a/lash.c
+++ b/lash.c
@@ -1447,10 +1447,7 @@ int shell_main(int argc_l, char **argv_l)
1447 fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n"); 1447 fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n");
1448 } else if (local_pending_command==NULL) { 1448 } else if (local_pending_command==NULL) {
1449 //fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]); 1449 //fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
1450 input = fopen(argv[optind], "r"); 1450 input = xfopen(argv[optind], "r");
1451 if (!input) {
1452 fatalError("%s: %s\n", argv[optind], strerror(errno));
1453 }
1454 } 1451 }
1455 1452
1456 /* initialize the cwd -- this is never freed...*/ 1453 /* initialize the cwd -- this is never freed...*/
diff --git a/loadacm.c b/loadacm.c
index 826c2a33f..f57737925 100644
--- a/loadacm.c
+++ b/loadacm.c
@@ -330,10 +330,7 @@ void saveoldmap(int fd, char *omfil)
330 } 330 }
331#endif 331#endif
332 332
333 if ((fp = fopen(omfil, "w")) == NULL) { 333 fp = xfopen(omfil, "w");
334 perror(omfil);
335 exit(1);
336 }
337#ifdef GIO_UNISCRNMAP 334#ifdef GIO_UNISCRNMAP
338 if (is_old_map) { 335 if (is_old_map) {
339#endif 336#endif
diff --git a/more.c b/more.c
index caabc44e2..f95cb48ad 100644
--- a/more.c
+++ b/more.c
@@ -82,12 +82,8 @@ extern int more_main(int argc, char **argv)
82 if (argc == 0) { 82 if (argc == 0) {
83 file = stdin; 83 file = stdin;
84 } else 84 } else
85 file = fopen(*argv, "r"); 85 file = xfopen(*argv, "r");
86 86
87 if (file == NULL) {
88 perror(*argv);
89 exit(FALSE);
90 }
91 fstat(fileno(file), &st); 87 fstat(fileno(file), &st);
92 88
93#ifdef BB_FEATURE_USE_TERMIOS 89#ifdef BB_FEATURE_USE_TERMIOS
diff --git a/networking/hostname.c b/networking/hostname.c
index 4320a968c..16a28ca43 100644
--- a/networking/hostname.c
+++ b/networking/hostname.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: hostname.c,v 1.13 2000/09/25 21:45:57 andersen Exp $ 3 * $Id: hostname.c,v 1.14 2000/09/27 02:43:35 kraai Exp $
4 * Mini hostname implementation for busybox 4 * Mini hostname implementation for busybox
5 * 5 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -46,18 +46,14 @@ void do_sethostname(char *s, int isfile)
46 exit(1); 46 exit(1);
47 } 47 }
48 } else { 48 } else {
49 if ((f = fopen(s, "r")) == NULL) { 49 f = xfopen(s, "r");
50 perror(s); 50 fgets(buf, 255, f);
51 fclose(f);
52 if (buf[strlen(buf) - 1] == '\n')
53 buf[strlen(buf) - 1] = 0;
54 if (sethostname(buf, strlen(buf)) < 0) {
55 perror("sethostname");
51 exit(1); 56 exit(1);
52 } else {
53 fgets(buf, 255, f);
54 fclose(f);
55 if (buf[strlen(buf) - 1] == '\n')
56 buf[strlen(buf) - 1] = 0;
57 if (sethostname(buf, strlen(buf)) < 0) {
58 perror("sethostname");
59 exit(1);
60 }
61 } 57 }
62 } 58 }
63} 59}
diff --git a/sed.c b/sed.c
index cb3f1bbf1..75435f67a 100644
--- a/sed.c
+++ b/sed.c
@@ -472,9 +472,7 @@ static void load_cmd_file(char *filename)
472 char *line; 472 char *line;
473 char *nextline; 473 char *nextline;
474 474
475 cmdfile = fopen(filename, "r"); 475 cmdfile = xfopen(filename, "r");
476 if (cmdfile == NULL)
477 fatalError(strerror(errno));
478 476
479 while ((line = get_line_from_file(cmdfile)) != NULL) { 477 while ((line = get_line_from_file(cmdfile)) != NULL) {
480 /* if a line ends with '\' it needs the next line appended to it */ 478 /* if a line ends with '\' it needs the next line appended to it */
diff --git a/sh.c b/sh.c
index 77efc6aac..b10614259 100644
--- a/sh.c
+++ b/sh.c
@@ -1447,10 +1447,7 @@ int shell_main(int argc_l, char **argv_l)
1447 fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n"); 1447 fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n");
1448 } else if (local_pending_command==NULL) { 1448 } else if (local_pending_command==NULL) {
1449 //fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]); 1449 //fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
1450 input = fopen(argv[optind], "r"); 1450 input = xfopen(argv[optind], "r");
1451 if (!input) {
1452 fatalError("%s: %s\n", argv[optind], strerror(errno));
1453 }
1454 } 1451 }
1455 1452
1456 /* initialize the cwd -- this is never freed...*/ 1453 /* initialize the cwd -- this is never freed...*/
diff --git a/shell/lash.c b/shell/lash.c
index 77efc6aac..b10614259 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -1447,10 +1447,7 @@ int shell_main(int argc_l, char **argv_l)
1447 fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n"); 1447 fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n");
1448 } else if (local_pending_command==NULL) { 1448 } else if (local_pending_command==NULL) {
1449 //fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]); 1449 //fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
1450 input = fopen(argv[optind], "r"); 1450 input = xfopen(argv[optind], "r");
1451 if (!input) {
1452 fatalError("%s: %s\n", argv[optind], strerror(errno));
1453 }
1454 } 1451 }
1455 1452
1456 /* initialize the cwd -- this is never freed...*/ 1453 /* initialize the cwd -- this is never freed...*/
diff --git a/util-linux/more.c b/util-linux/more.c
index caabc44e2..f95cb48ad 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -82,12 +82,8 @@ extern int more_main(int argc, char **argv)
82 if (argc == 0) { 82 if (argc == 0) {
83 file = stdin; 83 file = stdin;
84 } else 84 } else
85 file = fopen(*argv, "r"); 85 file = xfopen(*argv, "r");
86 86
87 if (file == NULL) {
88 perror(*argv);
89 exit(FALSE);
90 }
91 fstat(fileno(file), &st); 87 fstat(fileno(file), &st);
92 88
93#ifdef BB_FEATURE_USE_TERMIOS 89#ifdef BB_FEATURE_USE_TERMIOS
diff --git a/utility.c b/utility.c
index d376a04fb..ae69baf4b 100644
--- a/utility.c
+++ b/utility.c
@@ -1718,7 +1718,7 @@ void xregcomp(regex_t *preg, const char *regex, int cflags)
1718} 1718}
1719#endif 1719#endif
1720 1720
1721#if defined BB_UNIQ 1721#if defined BB_HOSTNAME || defined BB_LOADACM || defined BB_MORE || defined BB_SED || defined BB_SH || defined BB_UNIQ || defined BB_WC
1722FILE *xfopen(const char *path, const char *mode) 1722FILE *xfopen(const char *path, const char *mode)
1723{ 1723{
1724 FILE *fp; 1724 FILE *fp;
diff --git a/wc.c b/wc.c
index b1c9a51cd..9d569459d 100644
--- a/wc.c
+++ b/wc.c
@@ -134,13 +134,10 @@ int wc_main(int argc, char **argv)
134 134
135 if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) { 135 if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
136 wc_file(stdin, ""); 136 wc_file(stdin, "");
137 exit(TRUE); 137 return EXIT_SUCCESS;
138 } else { 138 } else {
139 while (optind < argc) { 139 while (optind < argc) {
140 file = fopen(argv[optind], "r"); 140 file = xfopen(argv[optind], "r");
141 if (file == NULL) {
142 fatalError(argv[optind]);
143 }
144 wc_file(file, argv[optind]); 141 wc_file(file, argv[optind]);
145 num_files_counted++; 142 num_files_counted++;
146 optind++; 143 optind++;
@@ -151,5 +148,5 @@ int wc_main(int argc, char **argv)
151 print_counts(total_lines, total_words, total_chars, 148 print_counts(total_lines, total_words, total_chars,
152 max_length, "total"); 149 max_length, "total");
153 150
154 return 0 ; 151 return EXIT_SUCCESS;
155} 152}