aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c92
1 files changed, 90 insertions, 2 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index ee8b4ec14..ac3e414f5 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -61,6 +61,7 @@ static const char usage_messages[] ALIGN1 = UNPACKED_USAGE;
61#if ENABLE_FEATURE_COMPRESS_USAGE 61#if ENABLE_FEATURE_COMPRESS_USAGE
62 62
63static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; 63static const char packed_usage[] ALIGN1 = { PACKED_USAGE };
64#define BB_ARCHIVE_PUBLIC
64# include "bb_archive.h" 65# include "bb_archive.h"
65static const char *unpack_usage_messages(void) 66static const char *unpack_usage_messages(void)
66{ 67{
@@ -281,6 +282,10 @@ void lbb_prepare(const char *applet
281 if (ENABLE_LOCALE_SUPPORT) 282 if (ENABLE_LOCALE_SUPPORT)
282 setlocale(LC_ALL, ""); 283 setlocale(LC_ALL, "");
283 284
285#if ENABLE_PLATFORM_MINGW32
286 init_winsock();
287#endif
288
284#if ENABLE_FEATURE_INDIVIDUAL 289#if ENABLE_FEATURE_INDIVIDUAL
285 /* Redundant for busybox (run_applet_and_exit covers that case) 290 /* Redundant for busybox (run_applet_and_exit covers that case)
286 * but needed for "individual applet" mode */ 291 * but needed for "individual applet" mode */
@@ -656,6 +661,7 @@ static void check_suid(int applet_no)
656 661
657 662
658# if ENABLE_FEATURE_INSTALLER 663# if ENABLE_FEATURE_INSTALLER
664# if !ENABLE_PLATFORM_MINGW32
659static const char usr_bin [] ALIGN1 = "/usr/bin/"; 665static const char usr_bin [] ALIGN1 = "/usr/bin/";
660static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; 666static const char usr_sbin[] ALIGN1 = "/usr/sbin/";
661static const char *const install_dir[] = { 667static const char *const install_dir[] = {
@@ -700,6 +706,29 @@ static void install_links(const char *busybox, int use_symbolic_links,
700 continue; 706 continue;
701 } 707 }
702} 708}
709# else /* ENABLE_PLATFORM_MINGW32 */
710static void install_links(const char *busybox,
711 int use_symbolic_links UNUSED_PARAM, char *custom_install_dir)
712{
713 char *fpc;
714 const char *appname = applet_names;
715 int rc;
716
717 if (!is_directory(custom_install_dir, FALSE))
718 bb_error_msg_and_die("'%s' is not a directory", custom_install_dir);
719
720 while (*appname) {
721 fpc = xasprintf("%s/%s.exe", custom_install_dir, appname);
722 rc = link(busybox, fpc);
723 if (rc != 0 && errno != EEXIST) {
724 bb_simple_perror_msg(fpc);
725 }
726 free(fpc);
727 while (*appname++ != '\0')
728 continue;
729 }
730}
731# endif
703# elif ENABLE_BUSYBOX 732# elif ENABLE_BUSYBOX
704static void install_links(const char *busybox UNUSED_PARAM, 733static void install_links(const char *busybox UNUSED_PARAM,
705 int use_symbolic_links UNUSED_PARAM, 734 int use_symbolic_links UNUSED_PARAM,
@@ -729,15 +758,25 @@ static int busybox_main(char **argv)
729 dup2(1, 2); 758 dup2(1, 2);
730 full_write2_str(bb_banner); /* reuse const string */ 759 full_write2_str(bb_banner); /* reuse const string */
731 full_write2_str(" multi-call binary.\n"); /* reuse */ 760 full_write2_str(" multi-call binary.\n"); /* reuse */
761#if defined(MINGW_VER)
762 if (strlen(MINGW_VER)) {
763 full_write2_str(MINGW_VER "\n\n");
764 }
765#endif
732 full_write2_str( 766 full_write2_str(
733 "BusyBox is copyrighted by many authors between 1998-2015.\n" 767 "BusyBox is copyrighted by many authors between 1998-2015.\n"
734 "Licensed under GPLv2. See source distribution for detailed\n" 768 "Licensed under GPLv2. See source distribution for detailed\n"
735 "copyright notices.\n" 769 "copyright notices.\n"
736 "\n" 770 "\n"
737 "Usage: busybox [function [arguments]...]\n" 771 "Usage: busybox [function [arguments]...]\n"
772 IF_NOT_PLATFORM_MINGW32(
738 " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" 773 " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n"
774 )
775 IF_PLATFORM_MINGW32(
776 " or: busybox --list\n"
777 )
739 IF_FEATURE_INSTALLER( 778 IF_FEATURE_INSTALLER(
740 " or: busybox --install [-s] [DIR]\n" 779 " or: busybox --install "IF_NOT_PLATFORM_MINGW32("[-s] ")"[DIR]\n"
741 ) 780 )
742 " or: function [arguments]...\n" 781 " or: function [arguments]...\n"
743 "\n" 782 "\n"
@@ -755,6 +794,11 @@ static int busybox_main(char **argv)
755 "\tTo run external program, use full path (/sbin/ip instead of ip).\n" 794 "\tTo run external program, use full path (/sbin/ip instead of ip).\n"
756 ) 795 )
757 "\n" 796 "\n"
797#if ENABLE_GLOBBING
798 "\tSupport for native Windows wildcards is enabled. In some\n"
799 "\tcases this may result in wildcards being processed twice.\n"
800 "\n"
801#endif
758 "Currently defined functions:\n" 802 "Currently defined functions:\n"
759 ); 803 );
760 col = 0; 804 col = 0;
@@ -786,7 +830,7 @@ static int busybox_main(char **argv)
786 const char *a = applet_names; 830 const char *a = applet_names;
787 dup2(1, 2); 831 dup2(1, 2);
788 while (*a) { 832 while (*a) {
789# if ENABLE_FEATURE_INSTALLER 833# if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32
790 if (argv[1][6]) /* --list-full? */ 834 if (argv[1][6]) /* --list-full? */
791 full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); 835 full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
792# endif 836# endif
@@ -800,6 +844,7 @@ static int busybox_main(char **argv)
800 } 844 }
801 845
802 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { 846 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
847#if !ENABLE_PLATFORM_MINGW32
803 int use_symbolic_links; 848 int use_symbolic_links;
804 const char *busybox; 849 const char *busybox;
805 850
@@ -820,6 +865,14 @@ static int busybox_main(char **argv)
820 */ 865 */
821 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); 866 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv);
822 install_links(busybox, use_symbolic_links, argv[2]); 867 install_links(busybox, use_symbolic_links, argv[2]);
868#else
869 /* busybox --install [DIR]
870 * where DIR is the directory to install to. If DIR is not
871 * provided put the links in the same directory as busybox.
872 */
873 install_links(bb_busybox_exec_path, FALSE, argv[2] ? argv[2] :
874 dirname(xstrdup(bb_busybox_exec_path)));
875#endif
823 return 0; 876 return 0;
824 } 877 }
825 878
@@ -960,6 +1013,18 @@ int main(int argc UNUSED_PARAM, char **argv)
960 } 1013 }
961#endif 1014#endif
962 1015
1016#if defined(__MINGW64_VERSION_MAJOR)
1017 if ( stdin ) {
1018 _setmode(fileno(stdin), _O_BINARY);
1019 }
1020 if ( stdout ) {
1021 _setmode(fileno(stdout), _O_BINARY);
1022 }
1023 if ( stderr ) {
1024 _setmode(fileno(stderr), _O_BINARY);
1025 }
1026#endif
1027
963#if defined(SINGLE_APPLET_MAIN) 1028#if defined(SINGLE_APPLET_MAIN)
964 1029
965 /* Only one applet is selected in .config */ 1030 /* Only one applet is selected in .config */
@@ -987,6 +1052,29 @@ int main(int argc UNUSED_PARAM, char **argv)
987 applet_name = argv[0]; 1052 applet_name = argv[0];
988 if (applet_name[0] == '-') 1053 if (applet_name[0] == '-')
989 applet_name++; 1054 applet_name++;
1055 if (ENABLE_PLATFORM_MINGW32) {
1056 const char *applet_name_env = getenv("BUSYBOX_APPLET_NAME");
1057 if (applet_name_env && *applet_name_env) {
1058 applet_name = applet_name_env;
1059 unsetenv("BUSYBOX_APPLET_NAME");
1060 }
1061 else if ( argv[1] && argv[2] && strcmp(argv[1], "--busybox") == 0 ) {
1062 argv += 2;
1063 applet_name = argv[0];
1064 }
1065 else {
1066 char *s = argv[0];
1067 int i, len = strlen(s);
1068
1069 for ( i=0; i < len; ++i ) {
1070 s[i] = tolower(s[i]);
1071 }
1072 if (len > 4 && !strcmp(s+len-4, ".exe")) {
1073 len -= 4;
1074 s[len] = '\0';
1075 }
1076 }
1077 }
990 applet_name = bb_basename(applet_name); 1078 applet_name = bb_basename(applet_name);
991 parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ 1079 parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
992 run_applet_and_exit(applet_name, argv); 1080 run_applet_and_exit(applet_name, argv);