diff options
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r-- | libbb/appletlib.c | 87 |
1 files changed, 85 insertions, 2 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index fa28d433b..abd9e3243 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 | { |
@@ -325,6 +326,10 @@ void lbb_prepare(const char *applet | |||
325 | if (ENABLE_LOCALE_SUPPORT) | 326 | if (ENABLE_LOCALE_SUPPORT) |
326 | setlocale(LC_ALL, ""); | 327 | setlocale(LC_ALL, ""); |
327 | 328 | ||
329 | #if ENABLE_PLATFORM_MINGW32 | ||
330 | init_winsock(); | ||
331 | #endif | ||
332 | |||
328 | #if ENABLE_FEATURE_INDIVIDUAL | 333 | #if ENABLE_FEATURE_INDIVIDUAL |
329 | /* Redundant for busybox (run_applet_and_exit covers that case) | 334 | /* Redundant for busybox (run_applet_and_exit covers that case) |
330 | * but needed for "individual applet" mode */ | 335 | * but needed for "individual applet" mode */ |
@@ -715,6 +720,7 @@ static void check_suid(int applet_no) | |||
715 | 720 | ||
716 | 721 | ||
717 | # if ENABLE_FEATURE_INSTALLER | 722 | # if ENABLE_FEATURE_INSTALLER |
723 | # if !ENABLE_PLATFORM_MINGW32 | ||
718 | static const char usr_bin [] ALIGN1 = "/usr/bin/"; | 724 | static const char usr_bin [] ALIGN1 = "/usr/bin/"; |
719 | static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; | 725 | static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; |
720 | static const char *const install_dir[] = { | 726 | static const char *const install_dir[] = { |
@@ -759,6 +765,29 @@ static void install_links(const char *busybox, int use_symbolic_links, | |||
759 | continue; | 765 | continue; |
760 | } | 766 | } |
761 | } | 767 | } |
768 | # else /* ENABLE_PLATFORM_MINGW32 */ | ||
769 | static void install_links(const char *busybox, | ||
770 | int use_symbolic_links UNUSED_PARAM, char *custom_install_dir) | ||
771 | { | ||
772 | char *fpc; | ||
773 | const char *appname = applet_names; | ||
774 | int rc; | ||
775 | |||
776 | if (!is_directory(custom_install_dir, FALSE)) | ||
777 | bb_error_msg_and_die("'%s' is not a directory", custom_install_dir); | ||
778 | |||
779 | while (*appname) { | ||
780 | fpc = xasprintf("%s/%s.exe", custom_install_dir, appname); | ||
781 | rc = link(busybox, fpc); | ||
782 | if (rc != 0 && errno != EEXIST) { | ||
783 | bb_simple_perror_msg(fpc); | ||
784 | } | ||
785 | free(fpc); | ||
786 | while (*appname++ != '\0') | ||
787 | continue; | ||
788 | } | ||
789 | } | ||
790 | # endif | ||
762 | # elif ENABLE_BUSYBOX | 791 | # elif ENABLE_BUSYBOX |
763 | static void install_links(const char *busybox UNUSED_PARAM, | 792 | static void install_links(const char *busybox UNUSED_PARAM, |
764 | int use_symbolic_links UNUSED_PARAM, | 793 | int use_symbolic_links UNUSED_PARAM, |
@@ -799,15 +828,25 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
799 | dup2(1, 2); | 828 | dup2(1, 2); |
800 | full_write2_str(bb_banner); /* reuse const string */ | 829 | full_write2_str(bb_banner); /* reuse const string */ |
801 | full_write2_str(" multi-call binary.\n"); /* reuse */ | 830 | full_write2_str(" multi-call binary.\n"); /* reuse */ |
831 | #if defined(MINGW_VER) | ||
832 | if (strlen(MINGW_VER)) { | ||
833 | full_write2_str(MINGW_VER "\n\n"); | ||
834 | } | ||
835 | #endif | ||
802 | full_write2_str( | 836 | full_write2_str( |
803 | "BusyBox is copyrighted by many authors between 1998-2015.\n" | 837 | "BusyBox is copyrighted by many authors between 1998-2015.\n" |
804 | "Licensed under GPLv2. See source distribution for detailed\n" | 838 | "Licensed under GPLv2. See source distribution for detailed\n" |
805 | "copyright notices.\n" | 839 | "copyright notices.\n" |
806 | "\n" | 840 | "\n" |
807 | "Usage: busybox [function [arguments]...]\n" | 841 | "Usage: busybox [function [arguments]...]\n" |
842 | IF_NOT_PLATFORM_MINGW32( | ||
808 | " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" | 843 | " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" |
844 | ) | ||
845 | IF_PLATFORM_MINGW32( | ||
846 | " or: busybox --list\n" | ||
847 | ) | ||
809 | IF_FEATURE_INSTALLER( | 848 | IF_FEATURE_INSTALLER( |
810 | " or: busybox --install [-s] [DIR]\n" | 849 | " or: busybox --install "IF_NOT_PLATFORM_MINGW32("[-s] ")"[DIR]\n" |
811 | ) | 850 | ) |
812 | " or: function [arguments]...\n" | 851 | " or: function [arguments]...\n" |
813 | "\n" | 852 | "\n" |
@@ -825,6 +864,11 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
825 | "\tTo run external program, use full path (/sbin/ip instead of ip).\n" | 864 | "\tTo run external program, use full path (/sbin/ip instead of ip).\n" |
826 | ) | 865 | ) |
827 | "\n" | 866 | "\n" |
867 | #if ENABLE_GLOBBING | ||
868 | "\tSupport for native Windows wildcards is enabled. In some\n" | ||
869 | "\tcases this may result in wildcards being processed twice.\n" | ||
870 | "\n" | ||
871 | #endif | ||
828 | "Currently defined functions:\n" | 872 | "Currently defined functions:\n" |
829 | ); | 873 | ); |
830 | col = 0; | 874 | col = 0; |
@@ -856,7 +900,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
856 | const char *a = applet_names; | 900 | const char *a = applet_names; |
857 | dup2(1, 2); | 901 | dup2(1, 2); |
858 | while (*a) { | 902 | while (*a) { |
859 | # if ENABLE_FEATURE_INSTALLER | 903 | # if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32 |
860 | if (argv[1][6]) /* --list-full? */ | 904 | if (argv[1][6]) /* --list-full? */ |
861 | full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); | 905 | full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); |
862 | # endif | 906 | # endif |
@@ -870,6 +914,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
870 | } | 914 | } |
871 | 915 | ||
872 | if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { | 916 | if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { |
917 | #if !ENABLE_PLATFORM_MINGW32 | ||
873 | int use_symbolic_links; | 918 | int use_symbolic_links; |
874 | const char *busybox; | 919 | const char *busybox; |
875 | 920 | ||
@@ -890,6 +935,14 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
890 | */ | 935 | */ |
891 | use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); | 936 | use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); |
892 | install_links(busybox, use_symbolic_links, argv[2]); | 937 | install_links(busybox, use_symbolic_links, argv[2]); |
938 | #else | ||
939 | /* busybox --install [DIR] | ||
940 | * where DIR is the directory to install to. If DIR is not | ||
941 | * provided put the links in the same directory as busybox. | ||
942 | */ | ||
943 | install_links(bb_busybox_exec_path, FALSE, argv[2] ? argv[2] : | ||
944 | dirname(xstrdup(bb_busybox_exec_path))); | ||
945 | #endif | ||
893 | return 0; | 946 | return 0; |
894 | } | 947 | } |
895 | 948 | ||
@@ -1031,6 +1084,18 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
1031 | } | 1084 | } |
1032 | #endif | 1085 | #endif |
1033 | 1086 | ||
1087 | #if defined(__MINGW64_VERSION_MAJOR) | ||
1088 | if ( stdin ) { | ||
1089 | _setmode(fileno(stdin), _O_BINARY); | ||
1090 | } | ||
1091 | if ( stdout ) { | ||
1092 | _setmode(fileno(stdout), _O_BINARY); | ||
1093 | } | ||
1094 | if ( stderr ) { | ||
1095 | _setmode(fileno(stderr), _O_BINARY); | ||
1096 | } | ||
1097 | #endif | ||
1098 | |||
1034 | #if defined(SINGLE_APPLET_MAIN) | 1099 | #if defined(SINGLE_APPLET_MAIN) |
1035 | 1100 | ||
1036 | /* Only one applet is selected in .config */ | 1101 | /* Only one applet is selected in .config */ |
@@ -1062,6 +1127,24 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
1062 | applet_name = argv[0]; | 1127 | applet_name = argv[0]; |
1063 | if (applet_name[0] == '-') | 1128 | if (applet_name[0] == '-') |
1064 | applet_name++; | 1129 | applet_name++; |
1130 | if (ENABLE_PLATFORM_MINGW32) { | ||
1131 | if ( argv[1] && argv[2] && strcmp(argv[1], "--busybox") == 0 ) { | ||
1132 | argv += 2; | ||
1133 | applet_name = argv[0]; | ||
1134 | } | ||
1135 | else { | ||
1136 | char *s = argv[0]; | ||
1137 | int i, len = strlen(s); | ||
1138 | |||
1139 | for ( i=0; i < len; ++i ) { | ||
1140 | s[i] = tolower(s[i]); | ||
1141 | } | ||
1142 | if (len > 4 && !strcmp(s+len-4, ".exe")) { | ||
1143 | len -= 4; | ||
1144 | s[len] = '\0'; | ||
1145 | } | ||
1146 | } | ||
1147 | } | ||
1065 | applet_name = bb_basename(applet_name); | 1148 | applet_name = bb_basename(applet_name); |
1066 | 1149 | ||
1067 | # if defined(__linux__) | 1150 | # if defined(__linux__) |