diff options
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r-- | libbb/appletlib.c | 107 |
1 files changed, 103 insertions, 4 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index fa28d433b..401475f18 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -105,6 +105,7 @@ static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; | |||
105 | #if ENABLE_FEATURE_COMPRESS_USAGE | 105 | #if ENABLE_FEATURE_COMPRESS_USAGE |
106 | 106 | ||
107 | static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; | 107 | static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; |
108 | #define BB_ARCHIVE_PUBLIC | ||
108 | # include "bb_archive.h" | 109 | # include "bb_archive.h" |
109 | static const char *unpack_usage_messages(void) | 110 | static const char *unpack_usage_messages(void) |
110 | { | 111 | { |
@@ -165,7 +166,7 @@ void FAST_FUNC bb_show_usage(void) | |||
165 | ap--; | 166 | ap--; |
166 | } | 167 | } |
167 | full_write2_str(bb_banner); | 168 | full_write2_str(bb_banner); |
168 | full_write2_str(" multi-call binary.\n"); | 169 | full_write2_str(" multi-call binary\n"); |
169 | if (*p == '\b') | 170 | if (*p == '\b') |
170 | full_write2_str("\nNo help available.\n\n"); | 171 | full_write2_str("\nNo help available.\n\n"); |
171 | else { | 172 | else { |
@@ -309,6 +310,22 @@ int FAST_FUNC find_applet_by_name(const char *name) | |||
309 | #endif | 310 | #endif |
310 | } | 311 | } |
311 | 312 | ||
313 | # if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_NOFORK | ||
314 | int FAST_FUNC long_running_applet(int applet_no) | ||
315 | { | ||
316 | int ret = 0; | ||
317 | |||
318 | #if defined(APPLET_NO_seq) | ||
319 | ret |= (applet_no == APPLET_NO_seq); | ||
320 | #endif | ||
321 | #if defined(APPLET_NO_yes) | ||
322 | ret |= (applet_no == APPLET_NO_yes); | ||
323 | #endif | ||
324 | |||
325 | return ret; | ||
326 | } | ||
327 | #endif | ||
328 | |||
312 | 329 | ||
313 | void lbb_prepare(const char *applet | 330 | void lbb_prepare(const char *applet |
314 | IF_FEATURE_INDIVIDUAL(, char **argv)) | 331 | IF_FEATURE_INDIVIDUAL(, char **argv)) |
@@ -325,6 +342,10 @@ void lbb_prepare(const char *applet | |||
325 | if (ENABLE_LOCALE_SUPPORT) | 342 | if (ENABLE_LOCALE_SUPPORT) |
326 | setlocale(LC_ALL, ""); | 343 | setlocale(LC_ALL, ""); |
327 | 344 | ||
345 | #if ENABLE_PLATFORM_MINGW32 | ||
346 | init_winsock(); | ||
347 | #endif | ||
348 | |||
328 | #if ENABLE_FEATURE_INDIVIDUAL | 349 | #if ENABLE_FEATURE_INDIVIDUAL |
329 | /* Redundant for busybox (run_applet_and_exit covers that case) | 350 | /* Redundant for busybox (run_applet_and_exit covers that case) |
330 | * but needed for "individual applet" mode */ | 351 | * but needed for "individual applet" mode */ |
@@ -715,6 +736,7 @@ static void check_suid(int applet_no) | |||
715 | 736 | ||
716 | 737 | ||
717 | # if ENABLE_FEATURE_INSTALLER | 738 | # if ENABLE_FEATURE_INSTALLER |
739 | # if !ENABLE_PLATFORM_MINGW32 | ||
718 | static const char usr_bin [] ALIGN1 = "/usr/bin/"; | 740 | static const char usr_bin [] ALIGN1 = "/usr/bin/"; |
719 | static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; | 741 | static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; |
720 | static const char *const install_dir[] = { | 742 | static const char *const install_dir[] = { |
@@ -759,6 +781,29 @@ static void install_links(const char *busybox, int use_symbolic_links, | |||
759 | continue; | 781 | continue; |
760 | } | 782 | } |
761 | } | 783 | } |
784 | # else /* ENABLE_PLATFORM_MINGW32 */ | ||
785 | static void install_links(const char *busybox, | ||
786 | int use_symbolic_links UNUSED_PARAM, char *custom_install_dir) | ||
787 | { | ||
788 | char *fpc; | ||
789 | const char *appname = applet_names; | ||
790 | int rc; | ||
791 | |||
792 | if (!is_directory(custom_install_dir, FALSE)) | ||
793 | bb_error_msg_and_die("'%s' is not a directory", custom_install_dir); | ||
794 | |||
795 | while (*appname) { | ||
796 | fpc = xasprintf("%s/%s.exe", custom_install_dir, appname); | ||
797 | rc = link(busybox, fpc); | ||
798 | if (rc != 0 && errno != EEXIST) { | ||
799 | bb_simple_perror_msg(fpc); | ||
800 | } | ||
801 | free(fpc); | ||
802 | while (*appname++ != '\0') | ||
803 | continue; | ||
804 | } | ||
805 | } | ||
806 | # endif | ||
762 | # elif ENABLE_BUSYBOX | 807 | # elif ENABLE_BUSYBOX |
763 | static void install_links(const char *busybox UNUSED_PARAM, | 808 | static void install_links(const char *busybox UNUSED_PARAM, |
764 | int use_symbolic_links UNUSED_PARAM, | 809 | int use_symbolic_links UNUSED_PARAM, |
@@ -798,16 +843,26 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
798 | 843 | ||
799 | dup2(1, 2); | 844 | dup2(1, 2); |
800 | full_write2_str(bb_banner); /* reuse const string */ | 845 | full_write2_str(bb_banner); /* reuse const string */ |
801 | full_write2_str(" multi-call binary.\n"); /* reuse */ | 846 | full_write2_str(" multi-call binary\n"); /* reuse */ |
847 | #if defined(MINGW_VER) | ||
848 | if (strlen(MINGW_VER)) { | ||
849 | full_write2_str(MINGW_VER "\n\n"); | ||
850 | } | ||
851 | #endif | ||
802 | full_write2_str( | 852 | full_write2_str( |
803 | "BusyBox is copyrighted by many authors between 1998-2015.\n" | 853 | "BusyBox is copyrighted by many authors between 1998-2015.\n" |
804 | "Licensed under GPLv2. See source distribution for detailed\n" | 854 | "Licensed under GPLv2. See source distribution for detailed\n" |
805 | "copyright notices.\n" | 855 | "copyright notices.\n" |
806 | "\n" | 856 | "\n" |
807 | "Usage: busybox [function [arguments]...]\n" | 857 | "Usage: busybox [function [arguments]...]\n" |
858 | IF_NOT_PLATFORM_MINGW32( | ||
808 | " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" | 859 | " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" |
860 | ) | ||
861 | IF_PLATFORM_MINGW32( | ||
862 | " or: busybox --list\n" | ||
863 | ) | ||
809 | IF_FEATURE_INSTALLER( | 864 | IF_FEATURE_INSTALLER( |
810 | " or: busybox --install [-s] [DIR]\n" | 865 | " or: busybox --install "IF_NOT_PLATFORM_MINGW32("[-s] ")"[DIR]\n" |
811 | ) | 866 | ) |
812 | " or: function [arguments]...\n" | 867 | " or: function [arguments]...\n" |
813 | "\n" | 868 | "\n" |
@@ -825,6 +880,11 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
825 | "\tTo run external program, use full path (/sbin/ip instead of ip).\n" | 880 | "\tTo run external program, use full path (/sbin/ip instead of ip).\n" |
826 | ) | 881 | ) |
827 | "\n" | 882 | "\n" |
883 | #if ENABLE_GLOBBING | ||
884 | "\tSupport for native Windows wildcards is enabled. In some\n" | ||
885 | "\tcases this may result in wildcards being processed twice.\n" | ||
886 | "\n" | ||
887 | #endif | ||
828 | "Currently defined functions:\n" | 888 | "Currently defined functions:\n" |
829 | ); | 889 | ); |
830 | col = 0; | 890 | col = 0; |
@@ -856,7 +916,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
856 | const char *a = applet_names; | 916 | const char *a = applet_names; |
857 | dup2(1, 2); | 917 | dup2(1, 2); |
858 | while (*a) { | 918 | while (*a) { |
859 | # if ENABLE_FEATURE_INSTALLER | 919 | # if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32 |
860 | if (argv[1][6]) /* --list-full? */ | 920 | if (argv[1][6]) /* --list-full? */ |
861 | full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); | 921 | full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); |
862 | # endif | 922 | # endif |
@@ -870,6 +930,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
870 | } | 930 | } |
871 | 931 | ||
872 | if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { | 932 | if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { |
933 | #if !ENABLE_PLATFORM_MINGW32 | ||
873 | int use_symbolic_links; | 934 | int use_symbolic_links; |
874 | const char *busybox; | 935 | const char *busybox; |
875 | 936 | ||
@@ -890,6 +951,14 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
890 | */ | 951 | */ |
891 | use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); | 952 | use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); |
892 | install_links(busybox, use_symbolic_links, argv[2]); | 953 | install_links(busybox, use_symbolic_links, argv[2]); |
954 | #else | ||
955 | /* busybox --install [DIR] | ||
956 | * where DIR is the directory to install to. If DIR is not | ||
957 | * provided put the links in the same directory as busybox. | ||
958 | */ | ||
959 | install_links(bb_busybox_exec_path, FALSE, argv[2] ? argv[2] : | ||
960 | dirname(xstrdup(bb_busybox_exec_path))); | ||
961 | #endif | ||
893 | return 0; | 962 | return 0; |
894 | } | 963 | } |
895 | 964 | ||
@@ -1031,6 +1100,18 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
1031 | } | 1100 | } |
1032 | #endif | 1101 | #endif |
1033 | 1102 | ||
1103 | #if defined(__MINGW64_VERSION_MAJOR) | ||
1104 | if ( stdin ) { | ||
1105 | _setmode(fileno(stdin), _O_BINARY); | ||
1106 | } | ||
1107 | if ( stdout ) { | ||
1108 | _setmode(fileno(stdout), _O_BINARY); | ||
1109 | } | ||
1110 | if ( stderr ) { | ||
1111 | _setmode(fileno(stderr), _O_BINARY); | ||
1112 | } | ||
1113 | #endif | ||
1114 | |||
1034 | #if defined(SINGLE_APPLET_MAIN) | 1115 | #if defined(SINGLE_APPLET_MAIN) |
1035 | 1116 | ||
1036 | /* Only one applet is selected in .config */ | 1117 | /* Only one applet is selected in .config */ |
@@ -1062,6 +1143,24 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
1062 | applet_name = argv[0]; | 1143 | applet_name = argv[0]; |
1063 | if (applet_name[0] == '-') | 1144 | if (applet_name[0] == '-') |
1064 | applet_name++; | 1145 | applet_name++; |
1146 | if (ENABLE_PLATFORM_MINGW32) { | ||
1147 | if ( argv[1] && argv[2] && strcmp(argv[1], "--busybox") == 0 ) { | ||
1148 | argv += 2; | ||
1149 | applet_name = argv[0]; | ||
1150 | } | ||
1151 | else { | ||
1152 | char *s = argv[0]; | ||
1153 | int i, len = strlen(s); | ||
1154 | |||
1155 | for ( i=0; i < len; ++i ) { | ||
1156 | s[i] = tolower(s[i]); | ||
1157 | } | ||
1158 | if (len > 4 && !strcmp(s+len-4, ".exe")) { | ||
1159 | len -= 4; | ||
1160 | s[len] = '\0'; | ||
1161 | } | ||
1162 | } | ||
1163 | } | ||
1065 | applet_name = bb_basename(applet_name); | 1164 | applet_name = bb_basename(applet_name); |
1066 | 1165 | ||
1067 | # if defined(__linux__) | 1166 | # if defined(__linux__) |