diff options
author | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-04-12 07:35:12 +0000 |
---|---|---|
committer | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-04-12 07:35:12 +0000 |
commit | 721e61dc4ddec000c9917f004b6c0a68ea40a565 (patch) | |
tree | 4459d66dd948b019c4a96730eea224f79520ad8c | |
parent | ab8d64334188e25031953f21fe92fb7839ffa806 (diff) | |
download | busybox-w32-721e61dc4ddec000c9917f004b6c0a68ea40a565.tar.gz busybox-w32-721e61dc4ddec000c9917f004b6c0a68ea40a565.tar.bz2 busybox-w32-721e61dc4ddec000c9917f004b6c0a68ea40a565.zip |
- add and use bb_opendir(), bb_xopendir().
text data bss dec hex filename
889445 9392 1035784 1934621 1d851d busybox.gcc-4.2.orig
889297 9392 1035784 1934473 1d8489 busybox.gcc-4.2
889009 9820 1037860 1936689 1d8d31 busybox.gcc-4.1.orig
888817 9820 1037860 1936497 1d8c71 busybox.gcc-4.1
git-svn-id: svn://busybox.net/trunk/busybox@14830 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | coreutils/diff.c | 4 | ||||
-rw-r--r-- | coreutils/du.c | 18 | ||||
-rw-r--r-- | coreutils/ls.c | 17 | ||||
-rw-r--r-- | debianutils/start_stop_daemon.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 3 | ||||
-rw-r--r-- | libbb/Makefile.in | 10 | ||||
-rw-r--r-- | libbb/copy_file.c | 3 | ||||
-rw-r--r-- | libbb/opendir.c | 37 | ||||
-rw-r--r-- | libbb/procps.c | 4 | ||||
-rw-r--r-- | libbb/recursive_action.c | 17 | ||||
-rw-r--r-- | libbb/remove_file.c | 17 | ||||
-rw-r--r-- | libbb/run_parts.c | 9 | ||||
-rw-r--r-- | procps/sysctl.c | 13 |
13 files changed, 66 insertions, 90 deletions
diff --git a/coreutils/diff.c b/coreutils/diff.c index 2c89a66e4..12c61ca1e 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c | |||
@@ -1114,8 +1114,8 @@ static char **get_dir(char *path) { | |||
1114 | else { | 1114 | else { |
1115 | DIR *dp; | 1115 | DIR *dp; |
1116 | struct dirent *ep; | 1116 | struct dirent *ep; |
1117 | if ((dp = opendir(path)) == NULL) | 1117 | |
1118 | bb_error_msg("Error reading directory"); | 1118 | dp = bb_opendir(path); |
1119 | while ((ep = readdir(dp))) { | 1119 | while ((ep = readdir(dp))) { |
1120 | if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, "."))) | 1120 | if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, "."))) |
1121 | continue; | 1121 | continue; |
diff --git a/coreutils/du.c b/coreutils/du.c index d453ba412..38790f83b 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -6,20 +6,7 @@ | |||
6 | * Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org> | 6 | * Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org> |
7 | * Copyright (C) 2002 Edward Betts <edward@debian.org> | 7 | * Copyright (C) 2002 Edward Betts <edward@debian.org> |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | */ | 10 | */ |
24 | 11 | ||
25 | /* BB_AUDIT SUSv3 compliant (unless default blocksize set to 1k) */ | 12 | /* BB_AUDIT SUSv3 compliant (unless default blocksize set to 1k) */ |
@@ -134,9 +121,8 @@ static long du(char *filename) | |||
134 | struct dirent *entry; | 121 | struct dirent *entry; |
135 | char *newfile; | 122 | char *newfile; |
136 | 123 | ||
137 | dir = opendir(filename); | 124 | dir = bb_opendir(filename); |
138 | if (!dir) { | 125 | if (!dir) { |
139 | bb_perror_msg("%s", filename); | ||
140 | status = EXIT_FAILURE; | 126 | status = EXIT_FAILURE; |
141 | return sum; | 127 | return sum; |
142 | } | 128 | } |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 964e7c964..c9d24ff4a 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -3,19 +3,7 @@ | |||
3 | * tiny-ls.c version 0.1.0: A minimalist 'ls' | 3 | * tiny-ls.c version 0.1.0: A minimalist 'ls' |
4 | * Copyright (C) 1996 Brian Candler <B.Candler@pobox.com> | 4 | * Copyright (C) 1996 Brian Candler <B.Candler@pobox.com> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | 7 | */ |
20 | 8 | ||
21 | /* | 9 | /* |
@@ -592,9 +580,8 @@ static struct dnode **list_dir(const char *path) | |||
592 | 580 | ||
593 | dn = NULL; | 581 | dn = NULL; |
594 | nfiles = 0; | 582 | nfiles = 0; |
595 | dir = opendir(path); | 583 | dir = bb_opendir(path); |
596 | if (dir == NULL) { | 584 | if (dir == NULL) { |
597 | bb_perror_msg("%s", path); | ||
598 | status = EXIT_FAILURE; | 585 | status = EXIT_FAILURE; |
599 | return (NULL); /* could not open the dir */ | 586 | return (NULL); /* could not open the dir */ |
600 | } | 587 | } |
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 1dd2231dc..5b689740e 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -143,9 +143,7 @@ do_procinit(void) | |||
143 | return; | 143 | return; |
144 | } | 144 | } |
145 | 145 | ||
146 | procdir = opendir("/proc"); | 146 | procdir = bb_xopendir("/proc"); |
147 | if (!procdir) | ||
148 | bb_perror_msg_and_die ("opendir /proc"); | ||
149 | 147 | ||
150 | foundany = 0; | 148 | foundany = 0; |
151 | while ((entry = readdir(procdir)) != NULL) { | 149 | while ((entry = readdir(procdir)) != NULL) { |
diff --git a/include/libbb.h b/include/libbb.h index 759df8d26..d3634f95d 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <sys/types.h> | 17 | #include <sys/types.h> |
18 | #include <sys/stat.h> | 18 | #include <sys/stat.h> |
19 | #include <termios.h> | 19 | #include <termios.h> |
20 | #include <dirent.h> | ||
20 | #include <stdint.h> | 21 | #include <stdint.h> |
21 | 22 | ||
22 | #include <netinet/in.h> | 23 | #include <netinet/in.h> |
@@ -98,6 +99,8 @@ extern int bb_echo(int argc, char** argv); | |||
98 | 99 | ||
99 | extern const char *bb_mode_string(int mode); | 100 | extern const char *bb_mode_string(int mode); |
100 | extern int is_directory(const char *name, int followLinks, struct stat *statBuf); | 101 | extern int is_directory(const char *name, int followLinks, struct stat *statBuf); |
102 | extern DIR *bb_opendir(const char *path); | ||
103 | extern DIR *bb_xopendir(const char *path); | ||
101 | 104 | ||
102 | extern int remove_file(const char *path, int flags); | 105 | extern int remove_file(const char *path, int flags); |
103 | extern int copy_file(const char *source, const char *dest, int flags); | 106 | extern int copy_file(const char *source, const char *dest, int flags); |
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 2d9a1745d..de511fc9b 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
@@ -105,12 +105,18 @@ LIBBB_MOBJ6:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ6)) | |||
105 | $(LIBBB_MOBJ6):$(LIBBB_MSRC6) | 105 | $(LIBBB_MOBJ6):$(LIBBB_MSRC6) |
106 | $(compile.c) -DL_$(notdir $*) | 106 | $(compile.c) -DL_$(notdir $*) |
107 | 107 | ||
108 | LIBBB_MSRC7:=$(srcdir)/opendir.c | ||
109 | LIBBB_MOBJ7:=bb_opendir.o bb_xopendir.o | ||
110 | LIBBB_MOBJ7:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ7)) | ||
111 | $(LIBBB_MOBJ7):$(LIBBB_MSRC7) | ||
112 | $(compile.c) -DL_$(notdir $*) | ||
108 | 113 | ||
109 | # We need the names of the object files built from MSRC for the L_ defines | 114 | # We need the names of the object files built from MSRC for the L_ defines |
110 | LIBBB_ALL_MOBJ:=$(LIBBB_MOBJ0) $(LIBBB_MOBJ1) $(LIBBB_MOBJ2) $(LIBBB_MOBJ3) $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6) | 115 | LIBBB_ALL_MOBJ:=$(LIBBB_MOBJ0) $(LIBBB_MOBJ1) $(LIBBB_MOBJ2) $(LIBBB_MOBJ3) \ |
116 | $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6) $(LIBBB_MOBJ7) | ||
111 | 117 | ||
112 | LIBBB_ALL_MSRC:=$(LIBBB_MSRC0) $(LIBBB_MSRC1) $(LIBBB_MSRC2) $(LIBBB_MSRC3) \ | 118 | LIBBB_ALL_MSRC:=$(LIBBB_MSRC0) $(LIBBB_MSRC1) $(LIBBB_MSRC2) $(LIBBB_MSRC3) \ |
113 | $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6) | 119 | $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6) $(LIBBB_MSRC7) |
114 | 120 | ||
115 | LIBBB-y:=$(sort $(LIBBB-y) $(LIBBB_ALL_MSRC)) | 121 | LIBBB-y:=$(sort $(LIBBB-y) $(LIBBB_ALL_MSRC)) |
116 | 122 | ||
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 3b172ffe4..2f7514628 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -92,8 +92,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
92 | } | 92 | } |
93 | 93 | ||
94 | /* Recursively copy files in SOURCE. */ | 94 | /* Recursively copy files in SOURCE. */ |
95 | if ((dp = opendir(source)) == NULL) { | 95 | if ((dp = bb_opendir(source)) == NULL) { |
96 | bb_perror_msg("unable to open directory `%s'", source); | ||
97 | status = -1; | 96 | status = -1; |
98 | goto preserve_status; | 97 | goto preserve_status; |
99 | } | 98 | } |
diff --git a/libbb/opendir.c b/libbb/opendir.c new file mode 100644 index 000000000..e284db0db --- /dev/null +++ b/libbb/opendir.c | |||
@@ -0,0 +1,37 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * wrapper for opendir() | ||
4 | * | ||
5 | * Copyright (C) 2006 Bernhard Fischer <busybox@busybox.net> | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | |||
10 | #include <sys/types.h> | ||
11 | #include <dirent.h> | ||
12 | #include "libbb.h" | ||
13 | |||
14 | #ifdef L_bb_opendir | ||
15 | DIR *bb_opendir(const char *path) | ||
16 | { | ||
17 | DIR *dp; | ||
18 | |||
19 | if ((dp = opendir(path)) == NULL) { | ||
20 | bb_perror_msg("unable to open `%s'", path); | ||
21 | return NULL; | ||
22 | } | ||
23 | return dp; | ||
24 | } | ||
25 | #endif | ||
26 | |||
27 | #ifdef L_bb_xopendir | ||
28 | DIR *bb_xopendir(const char *path) | ||
29 | { | ||
30 | DIR *dp; | ||
31 | |||
32 | if ((dp = opendir(path)) == NULL) { | ||
33 | bb_perror_msg_and_die("unable to open `%s'", path); | ||
34 | } | ||
35 | return dp; | ||
36 | } | ||
37 | #endif | ||
diff --git a/libbb/procps.c b/libbb/procps.c index e73c0dc64..25f42ffc8 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -50,9 +50,7 @@ procps_status_t * procps_scan(int save_user_arg0) | |||
50 | struct stat sb; | 50 | struct stat sb; |
51 | 51 | ||
52 | if (!dir) { | 52 | if (!dir) { |
53 | dir = opendir("/proc"); | 53 | dir = bb_xopendir("/proc"); |
54 | if(!dir) | ||
55 | bb_error_msg_and_die("Can't open /proc"); | ||
56 | } | 54 | } |
57 | for(;;) { | 55 | for(;;) { |
58 | if((entry = readdir(dir)) == NULL) { | 56 | if((entry = readdir(dir)) == NULL) { |
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c index d27629829..6b005e22d 100644 --- a/libbb/recursive_action.c +++ b/libbb/recursive_action.c | |||
@@ -4,19 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 8 | */ |
21 | 9 | ||
22 | #include <stdio.h> | 10 | #include <stdio.h> |
@@ -94,9 +82,8 @@ int recursive_action(const char *fileName, | |||
94 | } else if (status == SKIP) | 82 | } else if (status == SKIP) |
95 | return TRUE; | 83 | return TRUE; |
96 | } | 84 | } |
97 | dir = opendir(fileName); | 85 | dir = bb_opendir(fileName); |
98 | if (!dir) { | 86 | if (!dir) { |
99 | bb_perror_msg("%s", fileName); | ||
100 | return FALSE; | 87 | return FALSE; |
101 | } | 88 | } |
102 | status = TRUE; | 89 | status = TRUE; |
diff --git a/libbb/remove_file.c b/libbb/remove_file.c index ee1aaa5cd..2fa6596ee 100644 --- a/libbb/remove_file.c +++ b/libbb/remove_file.c | |||
@@ -4,19 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu> | 5 | * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 8 | */ |
21 | 9 | ||
22 | #include <stdio.h> | 10 | #include <stdio.h> |
@@ -71,8 +59,7 @@ int remove_file(const char *path, int flags) | |||
71 | return 0; | 59 | return 0; |
72 | } | 60 | } |
73 | 61 | ||
74 | if ((dp = opendir(path)) == NULL) { | 62 | if ((dp = bb_opendir(path)) == NULL) { |
75 | bb_perror_msg("unable to open `%s'", path); | ||
76 | return -1; | 63 | return -1; |
77 | } | 64 | } |
78 | 65 | ||
diff --git a/libbb/run_parts.c b/libbb/run_parts.c index 864460d0d..7bdae5b38 100644 --- a/libbb/run_parts.c +++ b/libbb/run_parts.c | |||
@@ -7,12 +7,7 @@ | |||
7 | * rewrite to vfork usage by | 7 | * rewrite to vfork usage by |
8 | * Copyright (C) 2002 by Vladimir Oleynik <dzo@simtreas.ru> | 8 | * Copyright (C) 2002 by Vladimir Oleynik <dzo@simtreas.ru> |
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or modify | 10 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * | ||
16 | */ | 11 | */ |
17 | 12 | ||
18 | 13 | ||
@@ -69,7 +64,7 @@ int run_parts(char **args, const unsigned char test_mode, char **env) | |||
69 | if (test_mode & 2) { | 64 | if (test_mode & 2) { |
70 | return(2); | 65 | return(2); |
71 | } | 66 | } |
72 | bb_perror_msg_and_die("failed to open directory %s", arg0); | 67 | bb_perror_msg_and_die("unable to open `%s'", arg0); |
73 | } | 68 | } |
74 | 69 | ||
75 | for (i = 0; i < entries; i++) { | 70 | for (i = 0; i < entries; i++) { |
diff --git a/procps/sysctl.c b/procps/sysctl.c index b8835c0d8..bcd229fdd 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c | |||
@@ -4,13 +4,8 @@ | |||
4 | * | 4 | * |
5 | * | 5 | * |
6 | * "Copyright 1999 George Staikos | 6 | * "Copyright 1999 George Staikos |
7 | * This file may be used subject to the terms and conditions of the | 7 | * |
8 | * GNU General Public License Version 2, or any later version | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
9 | * at your option, as published by the Free Software Foundation. | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details." | ||
14 | * | 9 | * |
15 | * Changelog: | 10 | * Changelog: |
16 | * v1.01: | 11 | * v1.01: |
@@ -57,7 +52,6 @@ static const char ERR_UNKNOWN_READING[] = | |||
57 | "error: unknown error %d reading key '%s'\n"; | 52 | "error: unknown error %d reading key '%s'\n"; |
58 | static const char ERR_PERMISSION_DENIED[] = | 53 | static const char ERR_PERMISSION_DENIED[] = |
59 | "error: permission denied on key '%s'\n"; | 54 | "error: permission denied on key '%s'\n"; |
60 | static const char ERR_OPENING_DIR[] = "error: unable to open directory '%s'\n"; | ||
61 | static const char ERR_PRELOAD_FILE[] = | 55 | static const char ERR_PRELOAD_FILE[] = |
62 | "error: unable to open preload file '%s'\n"; | 56 | "error: unable to open preload file '%s'\n"; |
63 | static const char WARN_BAD_LINE[] = | 57 | static const char WARN_BAD_LINE[] = |
@@ -316,8 +310,7 @@ int sysctl_display_all(const char *path, int output, int show_table) | |||
316 | char *tmpdir; | 310 | char *tmpdir; |
317 | struct stat ts; | 311 | struct stat ts; |
318 | 312 | ||
319 | if (!(dp = opendir(path))) { | 313 | if (!(dp = bb_opendir(path))) { |
320 | bb_perror_msg(ERR_OPENING_DIR, path); | ||
321 | retval = -1; | 314 | retval = -1; |
322 | } else { | 315 | } else { |
323 | while ((de = readdir(dp)) != NULL) { | 316 | while ((de = readdir(dp)) != NULL) { |