summaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorDenis Vlasenko2008-04-01 14:47:57 +0000
committerDenis Vlasenko2008-04-01 14:47:57 +0000
commit468aea2d8800cc0496383616d82d7c957ae8bc50 (patch)
tree8a2f3d80dc2440dd007caed4cfa235b3858c9170 /libbb/appletlib.c
parent165f5b394fa337e71e08435b51108f4394199b2b (diff)
downloadbusybox-468aea2d8800cc0496383616d82d7c957ae8bc50.zip
busybox-468aea2d8800cc0496383616d82d7c957ae8bc50.tar.gz
shells: do not frocibly enable test, echo and kill _applets_,
just build relevant source and use xxx_main functions. build system: add a special case when we have exactly one applet enabled (makes "true", "false", "basename" REALLY tiny). getopt32: do not use stdio. function old new delta getopt32 1385 1412 +27 make_device 1187 1200 +13 basename_main 120 127 +7 tcpudpsvd_main 1922 1926 +4 testcmd 5 - -5 echocmd 5 - -5 fuser_main 1243 1231 -12 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 4/1 up/down: 51/-22) Total: 29 bytes
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index e2bb378..a48a260 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -36,6 +36,13 @@ static const char usage_messages[] ALIGN1 = ""
/* Include generated applet names, pointers to <applet>_main, etc */
#include "applet_tables.h"
+/* ...and if applet_tables generator says we have only one applet... */
+#ifdef SINGLE_APPLET_MAIN
+#undef ENABLE_FEATURE_INDIVIDUAL
+#define ENABLE_FEATURE_INDIVIDUAL 1
+#undef USE_FEATURE_INDIVIDUAL
+#define USE_FEATURE_INDIVIDUAL(...) __VA_ARGS__
+#endif
#if ENABLE_FEATURE_COMPRESS_USAGE
@@ -77,6 +84,23 @@ static const char *unpack_usage_messages(void)
void bb_show_usage(void)
{
if (ENABLE_SHOW_USAGE) {
+#ifdef SINGLE_APPLET_STR
+ /* Imagine that this applet is "true". Dont suck in printf! */
+ const char *p;
+ const char *usage_string = p = unpack_usage_messages();
+
+ if (*p == '\b') {
+ write(2, "\nNo help available.\n\n",
+ sizeof("\nNo help available.\n\n") - 1);
+ } else {
+ write(2, "\nUsage: "SINGLE_APPLET_STR" ",
+ sizeof("\nUsage: "SINGLE_APPLET_STR" ") - 1);
+ write(2, p, strlen(p));
+ write(2, "\n\n", 2);
+ }
+ dealloc_usage_messages((char*)usage_string);
+#else
+// TODO: in this case, stdio is sucked in by busybox_main() anyway...
const char *format_string;
const char *p;
const char *usage_string = p = unpack_usage_messages();
@@ -84,18 +108,17 @@ void bb_show_usage(void)
if (ap < 0) /* never happens, paranoia */
xfunc_die();
-
while (ap) {
while (*p++) continue;
ap--;
}
-
fprintf(stderr, "%s multi-call binary\n", bb_banner);
format_string = "\nUsage: %s %s\n\n";
if (*p == '\b')
format_string = "\nNo help available.\n\n";
fprintf(stderr, format_string, applet_name, p);
dealloc_usage_messages((char*)usage_string);
+#endif
}
xfunc_die();
}
@@ -125,6 +148,9 @@ int *const bb_errno __attribute__ ((section (".data")));
void lbb_prepare(const char *applet
USE_FEATURE_INDIVIDUAL(, char **argv))
+ MAIN_EXTERNALLY_VISIBLE;
+void lbb_prepare(const char *applet
+ USE_FEATURE_INDIVIDUAL(, char **argv))
{
#ifdef __GLIBC__
(*(int **)&bb_errno) = __errno_location();
@@ -158,6 +184,9 @@ const char *applet_name;
bool re_execed;
#endif
+
+#if !ENABLE_FEATURE_INDIVIDUAL
+
USE_FEATURE_SUID(static uid_t ruid;) /* real uid */
#if ENABLE_FEATURE_SUID_CONFIG
@@ -660,6 +689,9 @@ void run_applet_and_exit(const char *name, char **argv)
exit(busybox_main(argv));
}
+#endif /* !ENABLE_FEATURE_INDIVIDUAL */
+
+
#if ENABLE_BUILD_LIBBUSYBOX
int lbb_main(char **argv)
@@ -667,6 +699,11 @@ int lbb_main(char **argv)
int main(int argc ATTRIBUTE_UNUSED, char **argv)
#endif
{
+#if ENABLE_FEATURE_INDIVIDUAL
+ /* Only one applet is selected by the user! */
+ lbb_prepare(SINGLE_APPLET_STR USE_FEATURE_INDIVIDUAL(, argv));
+ return SINGLE_APPLET_MAIN(argc, argv);
+#else
lbb_prepare("busybox" USE_FEATURE_INDIVIDUAL(, argv));
#if !BB_MMU
@@ -685,4 +722,5 @@ int main(int argc ATTRIBUTE_UNUSED, char **argv)
run_applet_and_exit(applet_name, argv);
bb_error_msg_and_die("applet not found");
+#endif
}