aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-03-31 13:14:05 +0100
committerRon Yorston <rmy@pobox.com>2018-03-31 13:14:05 +0100
commit8fa3366615f197e5c2b66b16029d42817965fa52 (patch)
treeab32568a75561a066923a4498cc37fe116ae94b3
parentada909acfa49fa59bbd8005e5b118c32447dfad0 (diff)
downloadbusybox-w32-8fa3366615f197e5c2b66b16029d42817965fa52.tar.gz
busybox-w32-8fa3366615f197e5c2b66b16029d42817965fa52.tar.bz2
busybox-w32-8fa3366615f197e5c2b66b16029d42817965fa52.zip
libbb: improve stripping of extension from argv[0]
Use library routines to reduce the amount of code needed to strip the extension from argv[0] in the BusyBox main function. The name of the executable can now have any of the standard extensions, none at all, or a trailing dot. Related to GitHub issue #20.
-rw-r--r--libbb/appletlib.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 491eb4208..210f9ff4d 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -1142,24 +1142,20 @@ int main(int argc UNUSED_PARAM, char **argv)
1142 applet_name = argv[0]; 1142 applet_name = argv[0];
1143 if (applet_name[0] == '-') 1143 if (applet_name[0] == '-')
1144 applet_name++; 1144 applet_name++;
1145 if (ENABLE_PLATFORM_MINGW32) { 1145# if ENABLE_PLATFORM_MINGW32
1146 if ( argv[1] && argv[2] && strcmp(argv[1], "--busybox") == 0 ) { 1146 if ( argv[1] && argv[2] && strcmp(argv[1], "--busybox") == 0 ) {
1147 argv += 2; 1147 argv += 2;
1148 applet_name = argv[0]; 1148 applet_name = argv[0];
1149 } 1149 }
1150 else { 1150 else {
1151 char *s = argv[0]; 1151 char *s;
1152 int i, len = strlen(s);
1153 1152
1154 for ( i=0; i < len; ++i ) { 1153 str_tolower(argv[0]);
1155 s[i] = tolower(s[i]); 1154 if (has_exe_suffix_or_dot(argv[0]) && !(s=strrchr(argv[0], '.'))) {
1156 } 1155 *s = '\0';
1157 if (len > 4 && !strcmp(s+len-4, ".exe")) {
1158 len -= 4;
1159 s[len] = '\0';
1160 }
1161 } 1156 }
1162 } 1157 }
1158# endif
1163 applet_name = bb_basename(applet_name); 1159 applet_name = bb_basename(applet_name);
1164 1160
1165 /* If we are a result of execv("/proc/self/exe"), fix ugly comm of "exe" */ 1161 /* If we are a result of execv("/proc/self/exe"), fix ugly comm of "exe" */