1 /* vi: set sw=4 ts=4: */
8 #if ENABLE_LOCALE_SUPPORT
11 #define setlocale(x,y)
14 const char *bb_applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
16 #ifdef CONFIG_FEATURE_INSTALLER
19 * this should be consistent w/ the enum, busybox.h::Location,
22 static const char usr_bin [] ="/usr/bin";
23 static const char usr_sbin[] ="/usr/sbin";
25 static const char* const install_dir[] = {
26 &usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
27 &usr_bin [4], /* "/bin" */
28 &usr_sbin[4], /* "/sbin" */
34 typedef int (*__link_f)(const char *, const char *);
36 /* create (sym)links for each applet */
37 static void install_links(const char *busybox, int use_symbolic_links)
45 if (use_symbolic_links)
48 for (i = 0; applets[i].name != NULL; i++) {
49 fpc = concat_path_file(
50 install_dir[applets[i].location], applets[i].name);
51 rc = Link(busybox, fpc);
52 if (rc!=0 && errno!=EEXIST) {
53 bb_perror_msg("%s", fpc);
60 #define install_links(x,y)
61 #endif /* CONFIG_FEATURE_INSTALLER */
63 int main(int argc, char **argv)
67 bb_applet_name=argv[0];
68 if (*bb_applet_name == '-') bb_applet_name++;
69 for (s = bb_applet_name; *s ;)
70 if (*(s++) == '/') bb_applet_name = s;
72 /* Set locale for everybody except `init' */
73 if(ENABLE_LOCALE_SUPPORT && getpid() != 1)
74 setlocale(LC_ALL, "");
76 run_applet_by_name(bb_applet_name, argc, argv);
77 bb_error_msg_and_die("applet not found");
80 int busybox_main(int argc, char **argv)
83 * This style of argument parsing doesn't scale well
84 * in the event that busybox starts wanting more --options.
85 * If someone has a cleaner approach, by all means implement it.
87 if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) {
88 int use_symbolic_links = 0;
92 /* to use symlinks, or not to use symlinks... */
94 if ((strcmp(argv[2], "-s") == 0)) {
95 use_symbolic_links = 1;
100 busybox = xreadlink("/proc/self/exe");
102 install_links(busybox, use_symbolic_links);
110 /* Deal with --help. (Also print help when called with no arguments) */
112 if (argc==1 || !strcmp(argv[1],"--help") ) {
114 run_applet_by_name(bb_applet_name=argv[2], 2, argv);
116 const struct BB_applet *a;
117 int col, output_width;
119 if (ENABLE_FEATURE_AUTOWIDTH) {
120 /* Obtain the terminal width. */
121 get_terminal_width_height(0, &output_width, NULL);
122 /* leading tab and room to wrap */
124 } else output_width = 60;
127 "Usage: busybox [function] [arguments]...\n"
128 " or: [function] [arguments]...\n\n"
129 "\tBusyBox is a multi-call binary that combines many common Unix\n"
130 "\tutilities into a single executable. Most people will create a\n"
131 "\tlink to busybox for each function they wish to use and BusyBox\n"
132 "\twill act like whatever it was invoked as!\n"
133 "\nCurrently defined functions:\n", bb_msg_full_version);
136 for(a = applets; a->name;) {
137 col += printf("%s%s", (col ? ", " : "\t"), (a++)->name);
138 if (col > output_width && a->name) {
146 } else run_applet_by_name(argv[1], argc-1, argv+1);
148 bb_error_msg_and_die("applet not found");
153 c-file-style: "linux"