From 7af304a473d3dc20da215dc64215b656088eb419 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Mon, 5 Apr 2010 22:20:26 +0200 Subject: win32: appletlib: special way to recognize applet name on Windows argv[0] on Windows is always the executable path. We can't rely on it to extract the applet name. For single busybox executable, just pass an environment variable, BUSYBOX_APPLET_NAME. Also strip .exe suffix when looking for applet name. --- libbb/appletlib.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libbb') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 2d52c3db9..f287e4522 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -806,6 +806,18 @@ int main(int argc UNUSED_PARAM, char **argv) applet_name = argv[0]; if (applet_name[0] == '-') applet_name++; + if (ENABLE_PLATFORM_MINGW32) { + const char *applet_name_env = getenv("BUSYBOX_APPLET_NAME"); + if (applet_name_env && *applet_name_env) { + applet_name = applet_name_env; + unsetenv("BUSYBOX_APPLET_NAME"); + } + else { + int len = strlen(applet_name); + if (len > 4 && !strcmp(applet_name+len-4, ".exe")) + argv[0][applet_name-argv[0]+len-4] = '\0'; + } + } applet_name = bb_basename(applet_name); parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ -- cgit v1.2.3-55-g6feb