aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c107
1 files changed, 103 insertions, 4 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index cbca7ef17..6330b6f8b 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -97,6 +97,7 @@ static const char usage_messages[] ALIGN1 = UNPACKED_USAGE;
97#if ENABLE_FEATURE_COMPRESS_USAGE 97#if ENABLE_FEATURE_COMPRESS_USAGE
98 98
99static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; 99static const char packed_usage[] ALIGN1 = { PACKED_USAGE };
100#define BB_ARCHIVE_PUBLIC
100# include "bb_archive.h" 101# include "bb_archive.h"
101static const char *unpack_usage_messages(void) 102static const char *unpack_usage_messages(void)
102{ 103{
@@ -157,7 +158,7 @@ void FAST_FUNC bb_show_usage(void)
157 ap--; 158 ap--;
158 } 159 }
159 full_write2_str(bb_banner); 160 full_write2_str(bb_banner);
160 full_write2_str(" multi-call binary.\n"); 161 full_write2_str(" multi-call binary\n");
161 if (*p == '\b') 162 if (*p == '\b')
162 full_write2_str("\nNo help available.\n\n"); 163 full_write2_str("\nNo help available.\n\n");
163 else { 164 else {
@@ -301,6 +302,22 @@ int FAST_FUNC find_applet_by_name(const char *name)
301#endif 302#endif
302} 303}
303 304
305# if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_NOFORK
306int FAST_FUNC long_running_applet(int applet_no)
307{
308 int ret = 0;
309
310#if defined(APPLET_NO_seq)
311 ret |= (applet_no == APPLET_NO_seq);
312#endif
313#if defined(APPLET_NO_yes)
314 ret |= (applet_no == APPLET_NO_yes);
315#endif
316
317 return ret;
318}
319#endif
320
304 321
305void lbb_prepare(const char *applet 322void lbb_prepare(const char *applet
306 IF_FEATURE_INDIVIDUAL(, char **argv)) 323 IF_FEATURE_INDIVIDUAL(, char **argv))
@@ -317,6 +334,10 @@ void lbb_prepare(const char *applet
317 if (ENABLE_LOCALE_SUPPORT) 334 if (ENABLE_LOCALE_SUPPORT)
318 setlocale(LC_ALL, ""); 335 setlocale(LC_ALL, "");
319 336
337#if ENABLE_PLATFORM_MINGW32
338 init_winsock();
339#endif
340
320#if ENABLE_FEATURE_INDIVIDUAL 341#if ENABLE_FEATURE_INDIVIDUAL
321 /* Redundant for busybox (run_applet_and_exit covers that case) 342 /* Redundant for busybox (run_applet_and_exit covers that case)
322 * but needed for "individual applet" mode */ 343 * but needed for "individual applet" mode */
@@ -707,6 +728,7 @@ static void check_suid(int applet_no)
707 728
708 729
709# if ENABLE_FEATURE_INSTALLER 730# if ENABLE_FEATURE_INSTALLER
731# if !ENABLE_PLATFORM_MINGW32
710static const char usr_bin [] ALIGN1 = "/usr/bin/"; 732static const char usr_bin [] ALIGN1 = "/usr/bin/";
711static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; 733static const char usr_sbin[] ALIGN1 = "/usr/sbin/";
712static const char *const install_dir[] = { 734static const char *const install_dir[] = {
@@ -751,6 +773,29 @@ static void install_links(const char *busybox, int use_symbolic_links,
751 continue; 773 continue;
752 } 774 }
753} 775}
776# else /* ENABLE_PLATFORM_MINGW32 */
777static void install_links(const char *busybox,
778 int use_symbolic_links UNUSED_PARAM, char *custom_install_dir)
779{
780 char *fpc;
781 const char *appname = applet_names;
782 int rc;
783
784 if (!is_directory(custom_install_dir, FALSE))
785 bb_error_msg_and_die("'%s' is not a directory", custom_install_dir);
786
787 while (*appname) {
788 fpc = xasprintf("%s/%s.exe", custom_install_dir, appname);
789 rc = link(busybox, fpc);
790 if (rc != 0 && errno != EEXIST) {
791 bb_simple_perror_msg(fpc);
792 }
793 free(fpc);
794 while (*appname++ != '\0')
795 continue;
796 }
797}
798# endif
754# elif ENABLE_BUSYBOX 799# elif ENABLE_BUSYBOX
755static void install_links(const char *busybox UNUSED_PARAM, 800static void install_links(const char *busybox UNUSED_PARAM,
756 int use_symbolic_links UNUSED_PARAM, 801 int use_symbolic_links UNUSED_PARAM,
@@ -790,16 +835,26 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
790 835
791 dup2(1, 2); 836 dup2(1, 2);
792 full_write2_str(bb_banner); /* reuse const string */ 837 full_write2_str(bb_banner); /* reuse const string */
793 full_write2_str(" multi-call binary.\n"); /* reuse */ 838 full_write2_str(" multi-call binary\n"); /* reuse */
839#if defined(MINGW_VER)
840 if (strlen(MINGW_VER)) {
841 full_write2_str(MINGW_VER "\n\n");
842 }
843#endif
794 full_write2_str( 844 full_write2_str(
795 "BusyBox is copyrighted by many authors between 1998-2015.\n" 845 "BusyBox is copyrighted by many authors between 1998-2015.\n"
796 "Licensed under GPLv2. See source distribution for detailed\n" 846 "Licensed under GPLv2. See source distribution for detailed\n"
797 "copyright notices.\n" 847 "copyright notices.\n"
798 "\n" 848 "\n"
799 "Usage: busybox [function [arguments]...]\n" 849 "Usage: busybox [function [arguments]...]\n"
850 IF_NOT_PLATFORM_MINGW32(
800 " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" 851 " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n"
852 )
853 IF_PLATFORM_MINGW32(
854 " or: busybox --list\n"
855 )
801 IF_FEATURE_INSTALLER( 856 IF_FEATURE_INSTALLER(
802 " or: busybox --install [-s] [DIR]\n" 857 " or: busybox --install "IF_NOT_PLATFORM_MINGW32("[-s] ")"[DIR]\n"
803 ) 858 )
804 " or: function [arguments]...\n" 859 " or: function [arguments]...\n"
805 "\n" 860 "\n"
@@ -817,6 +872,11 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
817 "\tTo run external program, use full path (/sbin/ip instead of ip).\n" 872 "\tTo run external program, use full path (/sbin/ip instead of ip).\n"
818 ) 873 )
819 "\n" 874 "\n"
875#if ENABLE_GLOBBING
876 "\tSupport for native Windows wildcards is enabled. In some\n"
877 "\tcases this may result in wildcards being processed twice.\n"
878 "\n"
879#endif
820 "Currently defined functions:\n" 880 "Currently defined functions:\n"
821 ); 881 );
822 col = 0; 882 col = 0;
@@ -848,7 +908,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
848 const char *a = applet_names; 908 const char *a = applet_names;
849 dup2(1, 2); 909 dup2(1, 2);
850 while (*a) { 910 while (*a) {
851# if ENABLE_FEATURE_INSTALLER 911# if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32
852 if (argv[1][6]) /* --list-full? */ 912 if (argv[1][6]) /* --list-full? */
853 full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); 913 full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
854# endif 914# endif
@@ -862,6 +922,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
862 } 922 }
863 923
864 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { 924 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
925#if !ENABLE_PLATFORM_MINGW32
865 int use_symbolic_links; 926 int use_symbolic_links;
866 const char *busybox; 927 const char *busybox;
867 928
@@ -882,6 +943,14 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
882 */ 943 */
883 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); 944 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv);
884 install_links(busybox, use_symbolic_links, argv[2]); 945 install_links(busybox, use_symbolic_links, argv[2]);
946#else
947 /* busybox --install [DIR]
948 * where DIR is the directory to install to. If DIR is not
949 * provided put the links in the same directory as busybox.
950 */
951 install_links(bb_busybox_exec_path, FALSE, argv[2] ? argv[2] :
952 dirname(xstrdup(bb_busybox_exec_path)));
953#endif
885 return 0; 954 return 0;
886 } 955 }
887 956
@@ -1021,6 +1090,18 @@ int main(int argc UNUSED_PARAM, char **argv)
1021 } 1090 }
1022#endif 1091#endif
1023 1092
1093#if defined(__MINGW64_VERSION_MAJOR)
1094 if ( stdin ) {
1095 _setmode(fileno(stdin), _O_BINARY);
1096 }
1097 if ( stdout ) {
1098 _setmode(fileno(stdout), _O_BINARY);
1099 }
1100 if ( stderr ) {
1101 _setmode(fileno(stderr), _O_BINARY);
1102 }
1103#endif
1104
1024#if defined(SINGLE_APPLET_MAIN) 1105#if defined(SINGLE_APPLET_MAIN)
1025 1106
1026 /* Only one applet is selected in .config */ 1107 /* Only one applet is selected in .config */
@@ -1052,6 +1133,24 @@ int main(int argc UNUSED_PARAM, char **argv)
1052 applet_name = argv[0]; 1133 applet_name = argv[0];
1053 if (applet_name[0] == '-') 1134 if (applet_name[0] == '-')
1054 applet_name++; 1135 applet_name++;
1136 if (ENABLE_PLATFORM_MINGW32) {
1137 if ( argv[1] && argv[2] && strcmp(argv[1], "--busybox") == 0 ) {
1138 argv += 2;
1139 applet_name = argv[0];
1140 }
1141 else {
1142 char *s = argv[0];
1143 int i, len = strlen(s);
1144
1145 for ( i=0; i < len; ++i ) {
1146 s[i] = tolower(s[i]);
1147 }
1148 if (len > 4 && !strcmp(s+len-4, ".exe")) {
1149 len -= 4;
1150 s[len] = '\0';
1151 }
1152 }
1153 }
1055 applet_name = bb_basename(applet_name); 1154 applet_name = bb_basename(applet_name);
1056 1155
1057 /* If we are a result of execv("/proc/self/exe"), fix ugly comm of "exe" */ 1156 /* If we are a result of execv("/proc/self/exe"), fix ugly comm of "exe" */