diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-24 15:23:28 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-24 15:23:28 +0000 |
commit | 0ee3999d13b662d233dfc7decdd4d691cd66fdda (patch) | |
tree | 283bf4908f787f50a90cb84c014a580485307a9b /applets/busybox.c | |
parent | 7cea262273659e9894d446a3f9ea6b83fb18892a (diff) | |
download | busybox-w32-0ee3999d13b662d233dfc7decdd4d691cd66fdda.tar.gz busybox-w32-0ee3999d13b662d233dfc7decdd4d691cd66fdda.tar.bz2 busybox-w32-0ee3999d13b662d233dfc7decdd4d691cd66fdda.zip |
random tiny size savings
Diffstat (limited to 'applets/busybox.c')
-rw-r--r-- | applets/busybox.c | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/applets/busybox.c b/applets/busybox.c index bb9eb3af7..9ca12ac2b 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -14,8 +14,8 @@ const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; | |||
14 | * this should be consistent w/ the enum, busybox.h::Location, | 14 | * this should be consistent w/ the enum, busybox.h::Location, |
15 | * or else... | 15 | * or else... |
16 | */ | 16 | */ |
17 | static const char usr_bin [] ="/usr/bin"; | 17 | static const char usr_bin [] = "/usr/bin"; |
18 | static const char usr_sbin[] ="/usr/sbin"; | 18 | static const char usr_sbin[] = "/usr/sbin"; |
19 | 19 | ||
20 | static const char* const install_dir[] = { | 20 | static const char* const install_dir[] = { |
21 | &usr_bin [8], /* "", equivalent to "/" for concat_path_file() */ | 21 | &usr_bin [8], /* "", equivalent to "/" for concat_path_file() */ |
@@ -26,25 +26,25 @@ static const char* const install_dir[] = { | |||
26 | }; | 26 | }; |
27 | 27 | ||
28 | /* abstract link() */ | 28 | /* abstract link() */ |
29 | typedef int (*__link_f)(const char *, const char *); | 29 | typedef int (*link_func)(const char *, const char *); |
30 | 30 | ||
31 | /* create (sym)links for each applet */ | 31 | /* create (sym)links for each applet */ |
32 | static void install_links(const char *busybox, int use_symbolic_links) | 32 | static void install_links(const char *busybox, int use_symbolic_links) |
33 | { | 33 | { |
34 | __link_f Link = link; | 34 | link_func lf = link; |
35 | |||
36 | char *fpc; | 35 | char *fpc; |
37 | int i; | 36 | int i; |
38 | int rc; | 37 | int rc; |
39 | 38 | ||
40 | if (use_symbolic_links) | 39 | if (use_symbolic_links) |
41 | Link = symlink; | 40 | lf = symlink; |
42 | 41 | ||
43 | for (i = 0; applets[i].name != NULL; i++) { | 42 | for (i = 0; applets[i].name != NULL; i++) { |
44 | fpc = concat_path_file( | 43 | fpc = concat_path_file( |
45 | install_dir[applets[i].location], applets[i].name); | 44 | install_dir[applets[i].location], |
46 | rc = Link(busybox, fpc); | 45 | applets[i].name); |
47 | if (rc!=0 && errno!=EEXIST) { | 46 | rc = lf(busybox, fpc); |
47 | if (rc != 0 && errno != EEXIST) { | ||
48 | bb_perror_msg("%s", fpc); | 48 | bb_perror_msg("%s", fpc); |
49 | } | 49 | } |
50 | free(fpc); | 50 | free(fpc); |
@@ -59,10 +59,11 @@ int main(int argc, char **argv) | |||
59 | { | 59 | { |
60 | const char *s; | 60 | const char *s; |
61 | 61 | ||
62 | applet_name=argv[0]; | 62 | applet_name = argv[0]; |
63 | if (*applet_name == '-') applet_name++; | 63 | if (*applet_name == '-') |
64 | for (s = applet_name; *s ;) | 64 | applet_name++; |
65 | if (*(s++) == '/') applet_name = s; | 65 | while ((s = strchr(applet_name, '/'))) |
66 | applet_name = s + 1; | ||
66 | 67 | ||
67 | /* Set locale for everybody except 'init' */ | 68 | /* Set locale for everybody except 'init' */ |
68 | if (ENABLE_LOCALE_SUPPORT && getpid() != 1) | 69 | if (ENABLE_LOCALE_SUPPORT && getpid() != 1) |
@@ -81,44 +82,41 @@ int busybox_main(int argc, char **argv) | |||
81 | */ | 82 | */ |
82 | if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) { | 83 | if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) { |
83 | int use_symbolic_links = 0; | 84 | int use_symbolic_links = 0; |
84 | int rc = 0; | ||
85 | char *busybox; | 85 | char *busybox; |
86 | 86 | ||
87 | /* to use symlinks, or not to use symlinks... */ | 87 | /* to use symlinks, or not to use symlinks... */ |
88 | if (argc > 2) { | 88 | if (argc > 2) |
89 | if ((strcmp(argv[2], "-s") == 0)) { | 89 | if (strcmp(argv[2], "-s") == 0) |
90 | use_symbolic_links = 1; | 90 | use_symbolic_links = 1; |
91 | } | ||
92 | } | ||
93 | 91 | ||
94 | /* link */ | 92 | /* link */ |
95 | // XXX: FIXME: this is broken. Why not just use argv[0] ? | 93 | // XXX: FIXME: this is broken. Why not just use argv[0] ? |
96 | busybox = xreadlink("/proc/self/exe"); | 94 | busybox = xreadlink("/proc/self/exe"); |
97 | if (busybox) { | 95 | if (!busybox) |
98 | install_links(busybox, use_symbolic_links); | 96 | return 1; |
97 | install_links(busybox, use_symbolic_links); | ||
98 | if (ENABLE_FEATURE_CLEAN_UP) | ||
99 | free(busybox); | 99 | free(busybox); |
100 | } else { | 100 | return 0; |
101 | rc = 1; | ||
102 | } | ||
103 | return rc; | ||
104 | } | 101 | } |
105 | 102 | ||
106 | /* Deal with --help. (Also print help when called with no arguments) */ | 103 | /* Deal with --help. (Also print help when called with no arguments) */ |
107 | 104 | ||
108 | if (argc==1 || !strcmp(argv[1],"--help") ) { | 105 | if (argc == 1 || !strcmp(argv[1], "--help") ) { |
109 | if (argc>2) { | 106 | if (argc > 2) { |
110 | applet_name = argv[2]; | 107 | applet_name = argv[2]; |
111 | run_applet_by_name(applet_name, 2, argv); | 108 | run_applet_by_name(applet_name, 2, argv); |
112 | } else { | 109 | } else { |
113 | const struct BB_applet *a; | 110 | const struct BB_applet *a; |
114 | int col, output_width; | 111 | int col, output_width; |
115 | 112 | ||
113 | output_width = 80 - sizeof("start-stop-daemon, ") - 8; | ||
116 | if (ENABLE_FEATURE_AUTOWIDTH) { | 114 | if (ENABLE_FEATURE_AUTOWIDTH) { |
117 | /* Obtain the terminal width. */ | 115 | /* Obtain the terminal width. */ |
118 | get_terminal_width_height(0, &output_width, NULL); | 116 | get_terminal_width_height(0, &output_width, NULL); |
119 | /* leading tab and room to wrap */ | 117 | /* leading tab and room to wrap */ |
120 | output_width -= sizeof("start-stop-daemon, ") + 8; | 118 | output_width -= sizeof("start-stop-daemon, ") + 8; |
121 | } else output_width = 80 - sizeof("start-stop-daemon, ") - 8; | 119 | } |
122 | 120 | ||
123 | printf("%s\n" | 121 | printf("%s\n" |
124 | "Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n" | 122 | "Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n" |
@@ -130,19 +128,19 @@ int busybox_main(int argc, char **argv) | |||
130 | "\tlink to busybox for each function they wish to use and BusyBox\n" | 128 | "\tlink to busybox for each function they wish to use and BusyBox\n" |
131 | "\twill act like whatever it was invoked as!\n" | 129 | "\twill act like whatever it was invoked as!\n" |
132 | "\nCurrently defined functions:\n", bb_msg_full_version); | 130 | "\nCurrently defined functions:\n", bb_msg_full_version); |
133 | 131 | col = 0; | |
134 | col=0; | ||
135 | for(a = applets; a->name;) { | 132 | for(a = applets; a->name;) { |
136 | col += printf("%s%s", (col ? ", " : "\t"), (a++)->name); | 133 | col += printf("%s%s", (col ? ", " : "\t"), a->name); |
134 | a++; | ||
137 | if (col > output_width && a->name) { | 135 | if (col > output_width && a->name) { |
138 | printf(",\n"); | 136 | puts(","); |
139 | col = 0; | 137 | col = 0; |
140 | } | 138 | } |
141 | } | 139 | } |
142 | printf("\n\n"); | 140 | puts("\n"); |
143 | exit(0); | 141 | return 0; |
144 | } | 142 | } |
145 | } else run_applet_by_name(argv[1], argc-1, argv+1); | 143 | } else run_applet_by_name(argv[1], argc - 1, argv + 1); |
146 | 144 | ||
147 | bb_error_msg_and_die("applet not found"); | 145 | bb_error_msg_and_die("applet not found"); |
148 | } | 146 | } |