1 /* vi: set sw=4 ts=4: */
8 #ifdef CONFIG_LOCALE_SUPPORT
12 const char *bb_applet_name;
14 #ifdef CONFIG_FEATURE_INSTALLER
17 * this should be consistent w/ the enum, busybox.h::Location,
20 static const char usr_bin [] ="/usr/bin";
21 static const char usr_sbin[] ="/usr/sbin";
23 static const char* const install_dir[] = {
24 &usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
25 &usr_bin [4], /* "/bin" */
26 &usr_sbin[4], /* "/sbin" */
32 typedef int (*__link_f)(const char *, const char *);
34 /* create (sym)links for each applet */
35 static void install_links(const char *busybox, int use_symbolic_links)
43 if (use_symbolic_links)
46 for (i = 0; applets[i].name != NULL; i++) {
47 fpc = concat_path_file(
48 install_dir[applets[i].location], applets[i].name);
49 rc = Link(busybox, fpc);
50 if (rc!=0 && errno!=EEXIST) {
51 bb_perror_msg("%s", fpc);
57 #endif /* CONFIG_FEATURE_INSTALLER */
59 int main(int argc, char **argv)
63 bb_applet_name=argv[0];
64 if (*bb_applet_name == '-') bb_applet_name++;
65 for (s = bb_applet_name; *s ;)
66 if (*(s++) == '/') bb_applet_name = s;
68 /* Set locale for everybody except `init' */
69 if(ENABLE_LOCALE_SUPPORT && (!ENABLE_INIT || getpid()==1))
70 setlocale(LC_ALL, "");
72 run_applet_by_name(bb_applet_name, argc, argv);
73 bb_error_msg_and_die("applet not found");
76 int busybox_main(int argc, char **argv)
79 * This style of argument parsing doesn't scale well
80 * in the event that busybox starts wanting more --options.
81 * If someone has a cleaner approach, by all means implement it.
83 if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) {
84 int use_symbolic_links = 0;
88 /* to use symlinks, or not to use symlinks... */
90 if ((strcmp(argv[2], "-s") == 0)) {
91 use_symbolic_links = 1;
96 busybox = xreadlink("/proc/self/exe");
98 install_links(busybox, use_symbolic_links);
106 /* Deal with --help. (Also print help when called with no arguments) */
108 if (argc==1 || !strcmp(argv[1],"--help") ) {
109 if (argc>2) run_applet_by_name(bb_applet_name=argv[2], argc, argv);
111 const struct BB_applet *a;
112 int col, output_width;
114 if (ENABLE_FEATURE_AUTOWIDTH) {
115 /* Obtain the terminal width. */
116 get_terminal_width_height(0, &output_width, NULL);
117 /* leading tab and room to wrap */
119 } else output_width = 60;
122 "Usage: busybox [function] [arguments]...\n"
123 " or: [function] [arguments]...\n\n"
124 "\tBusyBox is a multi-call binary that combines many common Unix\n"
125 "\tutilities into a single executable. Most people will create a\n"
126 "\tlink to busybox for each function they wish to use and BusyBox\n"
127 "\twill act like whatever it was invoked as!\n"
128 "\nCurrently defined functions:\n", bb_msg_full_version);
131 for(a = applets; a->name;) {
132 col += printf("%s%s", (col ? ", " : "\t"), (a++)->name);
133 if (col > output_width && a->name) {
141 } else run_applet_by_name(bb_applet_name=argv[1], argc-1, argv+1);
143 bb_error_msg_and_die("applet not found");
148 c-file-style: "linux"