diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Kbuild.src | 21 | ||||
-rw-r--r-- | libbb/appletlib.c | 92 | ||||
-rw-r--r-- | libbb/copy_file.c | 3 | ||||
-rw-r--r-- | libbb/executable.c | 16 | ||||
-rw-r--r-- | libbb/find_mount_point.c | 37 | ||||
-rw-r--r-- | libbb/find_pid_by_name.c | 4 | ||||
-rw-r--r-- | libbb/get_last_path_component.c | 26 | ||||
-rw-r--r-- | libbb/get_line_from_file.c | 4 | ||||
-rw-r--r-- | libbb/getopt32.c | 2 | ||||
-rw-r--r-- | libbb/inode_hash.c | 2 | ||||
-rw-r--r-- | libbb/lineedit.c | 90 | ||||
-rw-r--r-- | libbb/make_directory.c | 25 | ||||
-rw-r--r-- | libbb/messages.c | 2 | ||||
-rw-r--r-- | libbb/printable_string.c | 2 | ||||
-rw-r--r-- | libbb/procps.c | 3 | ||||
-rw-r--r-- | libbb/read_printf.c | 5 | ||||
-rw-r--r-- | libbb/setup_environment.c | 11 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 4 | ||||
-rw-r--r-- | libbb/xconnect.c | 12 | ||||
-rw-r--r-- | libbb/xreadlink.c | 2 |
20 files changed, 339 insertions, 24 deletions
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index 52a90e9a1..39d9d907d 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src | |||
@@ -37,24 +37,19 @@ lib-y += fgets_str.o | |||
37 | lib-y += find_pid_by_name.o | 37 | lib-y += find_pid_by_name.o |
38 | lib-y += find_root_device.o | 38 | lib-y += find_root_device.o |
39 | lib-y += full_write.o | 39 | lib-y += full_write.o |
40 | lib-y += get_console.o | ||
41 | lib-y += get_last_path_component.o | 40 | lib-y += get_last_path_component.o |
42 | lib-y += get_line_from_file.o | 41 | lib-y += get_line_from_file.o |
43 | lib-y += getopt32.o | 42 | lib-y += getopt32.o |
44 | lib-y += getpty.o | ||
45 | lib-y += get_volsize.o | 43 | lib-y += get_volsize.o |
46 | lib-y += herror_msg.o | 44 | lib-y += herror_msg.o |
47 | lib-y += human_readable.o | 45 | lib-y += human_readable.o |
48 | lib-y += inet_common.o | 46 | lib-y += inet_common.o |
49 | lib-y += inode_hash.o | 47 | lib-y += inode_hash.o |
50 | lib-y += isdirectory.o | 48 | lib-y += isdirectory.o |
51 | lib-y += kernel_version.o | ||
52 | lib-y += last_char_is.o | 49 | lib-y += last_char_is.o |
53 | lib-y += lineedit.o lineedit_ptr_hack.o | 50 | lib-y += lineedit.o lineedit_ptr_hack.o |
54 | lib-y += llist.o | 51 | lib-y += llist.o |
55 | lib-y += login.o | ||
56 | lib-y += make_directory.o | 52 | lib-y += make_directory.o |
57 | lib-y += makedev.o | ||
58 | lib-y += hash_md5_sha.o | 53 | lib-y += hash_md5_sha.o |
59 | # Alternative (disabled) MD5 implementation | 54 | # Alternative (disabled) MD5 implementation |
60 | #lib-y += hash_md5prime.o | 55 | #lib-y += hash_md5prime.o |
@@ -75,7 +70,6 @@ lib-y += progress.o | |||
75 | lib-y += ptr_to_globals.o | 70 | lib-y += ptr_to_globals.o |
76 | lib-y += read.o | 71 | lib-y += read.o |
77 | lib-y += read_printf.o | 72 | lib-y += read_printf.o |
78 | lib-y += read_key.o | ||
79 | lib-y += recursive_action.o | 73 | lib-y += recursive_action.o |
80 | lib-y += remove_file.o | 74 | lib-y += remove_file.o |
81 | lib-y += run_shell.o | 75 | lib-y += run_shell.o |
@@ -84,7 +78,6 @@ lib-y += safe_poll.o | |||
84 | lib-y += safe_strncpy.o | 78 | lib-y += safe_strncpy.o |
85 | lib-y += safe_write.o | 79 | lib-y += safe_write.o |
86 | lib-y += setup_environment.o | 80 | lib-y += setup_environment.o |
87 | lib-y += signals.o | ||
88 | lib-y += simplify_path.o | 81 | lib-y += simplify_path.o |
89 | lib-y += single_argv.o | 82 | lib-y += single_argv.o |
90 | lib-y += skip_whitespace.o | 83 | lib-y += skip_whitespace.o |
@@ -109,10 +102,20 @@ lib-y += xfuncs.o | |||
109 | lib-y += xfuncs_printf.o | 102 | lib-y += xfuncs_printf.o |
110 | lib-y += xfunc_die.o | 103 | lib-y += xfunc_die.o |
111 | lib-y += xgetcwd.o | 104 | lib-y += xgetcwd.o |
112 | lib-y += xgethostbyname.o | ||
113 | lib-y += xreadlink.o | 105 | lib-y += xreadlink.o |
114 | lib-y += xrealloc_vector.o | 106 | lib-y += xrealloc_vector.o |
115 | 107 | ||
108 | lib-$(CONFIG_PLATFORM_POSIX) += get_console.o | ||
109 | lib-$(CONFIG_PLATFORM_POSIX) += getpty.o | ||
110 | lib-$(CONFIG_PLATFORM_POSIX) += inet_common.o | ||
111 | lib-$(CONFIG_PLATFORM_POSIX) += kernel_version.o | ||
112 | lib-$(CONFIG_PLATFORM_POSIX) += login.o | ||
113 | lib-$(CONFIG_PLATFORM_POSIX) += makedev.o | ||
114 | lib-$(CONFIG_PLATFORM_POSIX) += read_key.o | ||
115 | lib-$(CONFIG_PLATFORM_POSIX) += signals.o | ||
116 | lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o | ||
117 | lib-$(CONFIG_PLATFORM_POSIX) += xgethostbyname.o | ||
118 | |||
116 | lib-$(CONFIG_PLATFORM_LINUX) += match_fstype.o | 119 | lib-$(CONFIG_PLATFORM_LINUX) += match_fstype.o |
117 | 120 | ||
118 | lib-$(CONFIG_FEATURE_UTMP) += utmp.o | 121 | lib-$(CONFIG_FEATURE_UTMP) += utmp.o |
@@ -124,7 +127,7 @@ lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o | |||
124 | lib-$(CONFIG_UNICODE_SUPPORT) += unicode.o | 127 | lib-$(CONFIG_UNICODE_SUPPORT) += unicode.o |
125 | lib-$(CONFIG_FEATURE_CHECK_NAMES) += die_if_bad_username.o | 128 | lib-$(CONFIG_FEATURE_CHECK_NAMES) += die_if_bad_username.o |
126 | 129 | ||
127 | lib-$(CONFIG_NC) += udp_io.o | 130 | lib-$(CONFIG_NC_110_COMPAT) += udp_io.o |
128 | lib-$(CONFIG_DNSD) += udp_io.o | 131 | lib-$(CONFIG_DNSD) += udp_io.o |
129 | lib-$(CONFIG_NTPD) += udp_io.o | 132 | lib-$(CONFIG_NTPD) += udp_io.o |
130 | lib-$(CONFIG_TFTP) += udp_io.o | 133 | lib-$(CONFIG_TFTP) += udp_io.o |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 2d01a3ae7..4aa40454f 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 | ||
63 | static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; | 63 | static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; |
64 | #define BB_ARCHIVE_PUBLIC | ||
64 | # include "bb_archive.h" | 65 | # include "bb_archive.h" |
65 | static const char *unpack_usage_messages(void) | 66 | static 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 | ||
659 | static const char usr_bin [] ALIGN1 = "/usr/bin/"; | 665 | static const char usr_bin [] ALIGN1 = "/usr/bin/"; |
660 | static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; | 666 | static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; |
661 | static const char *const install_dir[] = { | 667 | static 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 */ | ||
710 | static 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 |
704 | static void install_links(const char *busybox UNUSED_PARAM, | 733 | static 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 | ||
@@ -959,6 +1012,18 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
959 | } | 1012 | } |
960 | #endif | 1013 | #endif |
961 | 1014 | ||
1015 | #if defined(__MINGW64_VERSION_MAJOR) | ||
1016 | if ( stdin ) { | ||
1017 | _setmode(fileno(stdin), _O_BINARY); | ||
1018 | } | ||
1019 | if ( stdout ) { | ||
1020 | _setmode(fileno(stdout), _O_BINARY); | ||
1021 | } | ||
1022 | if ( stderr ) { | ||
1023 | _setmode(fileno(stderr), _O_BINARY); | ||
1024 | } | ||
1025 | #endif | ||
1026 | |||
962 | #if defined(SINGLE_APPLET_MAIN) | 1027 | #if defined(SINGLE_APPLET_MAIN) |
963 | /* Only one applet is selected in .config */ | 1028 | /* Only one applet is selected in .config */ |
964 | if (argv[1] && is_prefixed_with(argv[0], "busybox")) { | 1029 | if (argv[1] && is_prefixed_with(argv[0], "busybox")) { |
@@ -978,6 +1043,29 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
978 | applet_name = argv[0]; | 1043 | applet_name = argv[0]; |
979 | if (applet_name[0] == '-') | 1044 | if (applet_name[0] == '-') |
980 | applet_name++; | 1045 | applet_name++; |
1046 | if (ENABLE_PLATFORM_MINGW32) { | ||
1047 | const char *applet_name_env = getenv("BUSYBOX_APPLET_NAME"); | ||
1048 | if (applet_name_env && *applet_name_env) { | ||
1049 | applet_name = applet_name_env; | ||
1050 | unsetenv("BUSYBOX_APPLET_NAME"); | ||
1051 | } | ||
1052 | else if ( argv[1] && argv[2] && strcmp(argv[1], "--busybox") == 0 ) { | ||
1053 | argv += 2; | ||
1054 | applet_name = argv[0]; | ||
1055 | } | ||
1056 | else { | ||
1057 | char *s = argv[0]; | ||
1058 | int i, len = strlen(s); | ||
1059 | |||
1060 | for ( i=0; i < len; ++i ) { | ||
1061 | s[i] = tolower(s[i]); | ||
1062 | } | ||
1063 | if (len > 4 && !strcmp(s+len-4, ".exe")) { | ||
1064 | len -= 4; | ||
1065 | s[len] = '\0'; | ||
1066 | } | ||
1067 | } | ||
1068 | } | ||
981 | applet_name = bb_basename(applet_name); | 1069 | applet_name = bb_basename(applet_name); |
982 | 1070 | ||
983 | parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ | 1071 | parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ |
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 23c0f8320..cb6d12359 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -105,12 +105,15 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags) | |||
105 | return -1; | 105 | return -1; |
106 | } | 106 | } |
107 | } else { | 107 | } else { |
108 | #if !ENABLE_PLATFORM_MINGW32 | ||
109 | /* MinGW does not have inode, and does not use device */ | ||
108 | if (source_stat.st_dev == dest_stat.st_dev | 110 | if (source_stat.st_dev == dest_stat.st_dev |
109 | && source_stat.st_ino == dest_stat.st_ino | 111 | && source_stat.st_ino == dest_stat.st_ino |
110 | ) { | 112 | ) { |
111 | bb_error_msg("'%s' and '%s' are the same file", source, dest); | 113 | bb_error_msg("'%s' and '%s' are the same file", source, dest); |
112 | return -1; | 114 | return -1; |
113 | } | 115 | } |
116 | #endif | ||
114 | dest_exists = 1; | 117 | dest_exists = 1; |
115 | } | 118 | } |
116 | 119 | ||
diff --git a/libbb/executable.c b/libbb/executable.c index 05e70312f..308c525a3 100644 --- a/libbb/executable.c +++ b/libbb/executable.c | |||
@@ -28,6 +28,10 @@ int FAST_FUNC file_is_executable(const char *name) | |||
28 | * return NULL otherwise; (PATHp is undefined) | 28 | * return NULL otherwise; (PATHp is undefined) |
29 | * in all cases (*PATHp) contents will be trashed (s/:/NUL/). | 29 | * in all cases (*PATHp) contents will be trashed (s/:/NUL/). |
30 | */ | 30 | */ |
31 | #if !ENABLE_PLATFORM_MINGW32 | ||
32 | #define next_path_sep(s) strchr(s, ':') | ||
33 | #endif | ||
34 | |||
31 | char* FAST_FUNC find_executable(const char *filename, char **PATHp) | 35 | char* FAST_FUNC find_executable(const char *filename, char **PATHp) |
32 | { | 36 | { |
33 | /* About empty components in $PATH: | 37 | /* About empty components in $PATH: |
@@ -39,10 +43,13 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) | |||
39 | * following the rest of the list. | 43 | * following the rest of the list. |
40 | */ | 44 | */ |
41 | char *p, *n; | 45 | char *p, *n; |
46 | #if ENABLE_PLATFORM_MINGW32 | ||
47 | char *w; | ||
48 | #endif | ||
42 | 49 | ||
43 | p = *PATHp; | 50 | p = *PATHp; |
44 | while (p) { | 51 | while (p) { |
45 | n = strchr(p, ':'); | 52 | n = (char*)next_path_sep(p); |
46 | if (n) | 53 | if (n) |
47 | *n++ = '\0'; | 54 | *n++ = '\0'; |
48 | p = concat_path_file( | 55 | p = concat_path_file( |
@@ -53,6 +60,13 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) | |||
53 | *PATHp = n; | 60 | *PATHp = n; |
54 | return p; | 61 | return p; |
55 | } | 62 | } |
63 | #if ENABLE_PLATFORM_MINGW32 | ||
64 | else if ((w=file_is_win32_executable(p))) { | ||
65 | *PATHp = n; | ||
66 | free(p); | ||
67 | return w; | ||
68 | } | ||
69 | #endif | ||
56 | free(p); | 70 | free(p); |
57 | p = n; | 71 | p = n; |
58 | } /* on loop exit p == NULL */ | 72 | } /* on loop exit p == NULL */ |
diff --git a/libbb/find_mount_point.c b/libbb/find_mount_point.c index 9676b5f52..de314a3c7 100644 --- a/libbb/find_mount_point.c +++ b/libbb/find_mount_point.c | |||
@@ -24,10 +24,18 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too) | |||
24 | struct mntent *mountEntry; | 24 | struct mntent *mountEntry; |
25 | dev_t devno_of_name; | 25 | dev_t devno_of_name; |
26 | bool block_dev; | 26 | bool block_dev; |
27 | #if ENABLE_PLATFORM_MINGW32 | ||
28 | static char mnt_fsname[4]; | ||
29 | static char mnt_dir[4]; | ||
30 | static struct mntent my_mount_entry = { mnt_fsname, mnt_dir, "", "", 0, 0 }; | ||
31 | char *current, *path; | ||
32 | DWORD len; | ||
33 | #endif | ||
27 | 34 | ||
28 | if (stat(name, &s) != 0) | 35 | if (stat(name, &s) != 0) |
29 | return NULL; | 36 | return NULL; |
30 | 37 | ||
38 | #if !ENABLE_PLATFORM_MINGW32 | ||
31 | devno_of_name = s.st_dev; | 39 | devno_of_name = s.st_dev; |
32 | block_dev = 0; | 40 | block_dev = 0; |
33 | /* Why S_ISCHR? - UBI volumes use char devices, not block */ | 41 | /* Why S_ISCHR? - UBI volumes use char devices, not block */ |
@@ -64,6 +72,35 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too) | |||
64 | break; | 72 | break; |
65 | } | 73 | } |
66 | endmntent(mtab_fp); | 74 | endmntent(mtab_fp); |
75 | #else | ||
76 | mountEntry = NULL; | ||
77 | path = NULL; | ||
78 | current = NULL; | ||
79 | |||
80 | if ( isalpha(name[0]) && name[1] == ':' ) { | ||
81 | path = name; | ||
82 | } | ||
83 | else { | ||
84 | if ( (len=GetCurrentDirectory(0, NULL)) > 0 && | ||
85 | (current=malloc(len+1)) != NULL && | ||
86 | GetCurrentDirectory(len, current) ) { | ||
87 | path = current; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | if ( path && isalpha(path[0]) && path[1] == ':' ) { | ||
92 | mnt_fsname[0] = path[0]; | ||
93 | mnt_fsname[1] = path[1]; | ||
94 | mnt_fsname[2] = '\0'; | ||
95 | mnt_dir[0] = path[0]; | ||
96 | mnt_dir[1] = path[1]; | ||
97 | mnt_dir[2] = '\\'; | ||
98 | mnt_dir[3] = '\0'; | ||
99 | |||
100 | mountEntry = &my_mount_entry; | ||
101 | } | ||
102 | free(current); | ||
103 | #endif | ||
67 | 104 | ||
68 | return mountEntry; | 105 | return mountEntry; |
69 | } | 106 | } |
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c index db823d05b..d4bea8ab5 100644 --- a/libbb/find_pid_by_name.c +++ b/libbb/find_pid_by_name.c | |||
@@ -56,6 +56,7 @@ static int comm_match(procps_status_t *p, const char *procName) | |||
56 | * This can be crazily_long_script_name.sh! | 56 | * This can be crazily_long_script_name.sh! |
57 | * The telltale sign is basename(argv[1]) == procName */ | 57 | * The telltale sign is basename(argv[1]) == procName */ |
58 | 58 | ||
59 | #if !ENABLE_PLATFORM_MINGW32 | ||
59 | if (!p->argv0) | 60 | if (!p->argv0) |
60 | return 0; | 61 | return 0; |
61 | 62 | ||
@@ -66,6 +67,7 @@ static int comm_match(procps_status_t *p, const char *procName) | |||
66 | 67 | ||
67 | if (strcmp(bb_basename(argv1), procName) != 0) | 68 | if (strcmp(bb_basename(argv1), procName) != 0) |
68 | return 0; | 69 | return 0; |
70 | #endif | ||
69 | 71 | ||
70 | return 1; | 72 | return 1; |
71 | } | 73 | } |
@@ -88,10 +90,12 @@ pid_t* FAST_FUNC find_pid_by_name(const char *procName) | |||
88 | pidList = xzalloc(sizeof(*pidList)); | 90 | pidList = xzalloc(sizeof(*pidList)); |
89 | while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGVN|PSSCAN_EXE))) { | 91 | while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGVN|PSSCAN_EXE))) { |
90 | if (comm_match(p, procName) | 92 | if (comm_match(p, procName) |
93 | #if !ENABLE_PLATFORM_MINGW32 | ||
91 | /* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/ | 94 | /* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/ |
92 | || (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0) | 95 | || (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0) |
93 | /* or we require /proc/PID/exe link to match */ | 96 | /* or we require /proc/PID/exe link to match */ |
94 | || (p->exe && strcmp(bb_basename(p->exe), procName) == 0) | 97 | || (p->exe && strcmp(bb_basename(p->exe), procName) == 0) |
98 | #endif | ||
95 | ) { | 99 | ) { |
96 | pidList = xrealloc_vector(pidList, 2, i); | 100 | pidList = xrealloc_vector(pidList, 2, i); |
97 | pidList[i++] = p->pid; | 101 | pidList[i++] = p->pid; |
diff --git a/libbb/get_last_path_component.c b/libbb/get_last_path_component.c index 04fdf2a3e..15eb85ca8 100644 --- a/libbb/get_last_path_component.c +++ b/libbb/get_last_path_component.c | |||
@@ -13,6 +13,11 @@ const char* FAST_FUNC bb_basename(const char *name) | |||
13 | const char *cp = strrchr(name, '/'); | 13 | const char *cp = strrchr(name, '/'); |
14 | if (cp) | 14 | if (cp) |
15 | return cp + 1; | 15 | return cp + 1; |
16 | #if ENABLE_PLATFORM_MINGW32 | ||
17 | cp = strrchr(name, '\\'); | ||
18 | if (cp) | ||
19 | return cp + 1; | ||
20 | #endif | ||
16 | return name; | 21 | return name; |
17 | } | 22 | } |
18 | 23 | ||
@@ -26,8 +31,18 @@ char* FAST_FUNC bb_get_last_path_component_nostrip(const char *path) | |||
26 | { | 31 | { |
27 | char *slash = strrchr(path, '/'); | 32 | char *slash = strrchr(path, '/'); |
28 | 33 | ||
34 | #if ENABLE_PLATFORM_MINGW32 | ||
35 | const char *start = has_dos_drive_prefix(path) ? path+2 : path; | ||
36 | |||
37 | if (!slash) | ||
38 | slash = strrchr(path, '\\'); | ||
39 | |||
40 | if (!slash || (slash == start && !slash[1])) | ||
41 | return (char*)path; | ||
42 | #else | ||
29 | if (!slash || (slash == path && !slash[1])) | 43 | if (!slash || (slash == path && !slash[1])) |
30 | return (char*)path; | 44 | return (char*)path; |
45 | #endif | ||
31 | 46 | ||
32 | return slash + 1; | 47 | return slash + 1; |
33 | } | 48 | } |
@@ -42,9 +57,20 @@ char* FAST_FUNC bb_get_last_path_component_strip(char *path) | |||
42 | { | 57 | { |
43 | char *slash = last_char_is(path, '/'); | 58 | char *slash = last_char_is(path, '/'); |
44 | 59 | ||
60 | #if ENABLE_PLATFORM_MINGW32 | ||
61 | const char *start = has_dos_drive_prefix(path) ? path+2 : path; | ||
62 | |||
63 | if (!slash) | ||
64 | slash = last_char_is(path, '\\'); | ||
65 | |||
66 | if (slash) | ||
67 | while ((*slash == '/' || *slash == '\\') && slash != start) | ||
68 | *slash-- = '\0'; | ||
69 | #else | ||
45 | if (slash) | 70 | if (slash) |
46 | while (*slash == '/' && slash != path) | 71 | while (*slash == '/' && slash != path) |
47 | *slash-- = '\0'; | 72 | *slash-- = '\0'; |
73 | #endif | ||
48 | 74 | ||
49 | return bb_get_last_path_component_nostrip(path); | 75 | return bb_get_last_path_component_nostrip(path); |
50 | } | 76 | } |
diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c index a98dd35eb..2038fac7d 100644 --- a/libbb/get_line_from_file.c +++ b/libbb/get_line_from_file.c | |||
@@ -57,6 +57,10 @@ char* FAST_FUNC xmalloc_fgetline(FILE *file) | |||
57 | 57 | ||
58 | if (i && c[--i] == '\n') | 58 | if (i && c[--i] == '\n') |
59 | c[i] = '\0'; | 59 | c[i] = '\0'; |
60 | #if ENABLE_PLATFORM_MINGW32 | ||
61 | if (i && c[--i] == '\r') | ||
62 | c[i] = '\0'; | ||
63 | #endif | ||
60 | 64 | ||
61 | return c; | 65 | return c; |
62 | } | 66 | } |
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 15b6efc09..ed9352191 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -576,7 +576,7 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
576 | * run_nofork_applet() does this, but we might end up here | 576 | * run_nofork_applet() does this, but we might end up here |
577 | * also via gunzip_main() -> gzip_main(). Play safe. | 577 | * also via gunzip_main() -> gzip_main(). Play safe. |
578 | */ | 578 | */ |
579 | #ifdef __GLIBC__ | 579 | #if defined(__GLIBC__) || ENABLE_PLATFORM_MINGW32 |
580 | optind = 0; | 580 | optind = 0; |
581 | #else /* BSD style */ | 581 | #else /* BSD style */ |
582 | optind = 1; | 582 | optind = 1; |
diff --git a/libbb/inode_hash.c b/libbb/inode_hash.c index f11c2afb2..64f43b885 100644 --- a/libbb/inode_hash.c +++ b/libbb/inode_hash.c | |||
@@ -59,6 +59,7 @@ char* FAST_FUNC is_in_ino_dev_hashtable(const struct stat *statbuf) | |||
59 | /* Add statbuf to statbuf hash table */ | 59 | /* Add statbuf to statbuf hash table */ |
60 | void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) | 60 | void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) |
61 | { | 61 | { |
62 | #if !ENABLE_PLATFORM_MINGW32 | ||
62 | int i; | 63 | int i; |
63 | ino_dev_hashtable_bucket_t *bucket; | 64 | ino_dev_hashtable_bucket_t *bucket; |
64 | 65 | ||
@@ -76,6 +77,7 @@ void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char * | |||
76 | i = hash_inode(statbuf->st_ino); | 77 | i = hash_inode(statbuf->st_ino); |
77 | bucket->next = ino_dev_hashtable[i]; | 78 | bucket->next = ino_dev_hashtable[i]; |
78 | ino_dev_hashtable[i] = bucket; | 79 | ino_dev_hashtable[i] = bucket; |
80 | #endif | ||
79 | } | 81 | } |
80 | 82 | ||
81 | #if ENABLE_DU || ENABLE_FEATURE_CLEAN_UP | 83 | #if ENABLE_DU || ENABLE_FEATURE_CLEAN_UP |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 2cc61db40..06f708b62 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -353,7 +353,7 @@ int adjust_width_and_validate_wc(unsigned *width_adj, int wc); | |||
353 | /* Put 'command_ps[cursor]', cursor++. | 353 | /* Put 'command_ps[cursor]', cursor++. |
354 | * Advance cursor on screen. If we reached right margin, scroll text up | 354 | * Advance cursor on screen. If we reached right margin, scroll text up |
355 | * and remove terminal margin effect by printing 'next_char' */ | 355 | * and remove terminal margin effect by printing 'next_char' */ |
356 | #define HACK_FOR_WRONG_WIDTH 1 | 356 | #define HACK_FOR_WRONG_WIDTH 1 && !ENABLE_PLATFORM_MINGW32 |
357 | static void put_cur_glyph_and_inc_cursor(void) | 357 | static void put_cur_glyph_and_inc_cursor(void) |
358 | { | 358 | { |
359 | CHAR_T c = command_ps[cursor]; | 359 | CHAR_T c = command_ps[cursor]; |
@@ -416,6 +416,42 @@ static void put_cur_glyph_and_inc_cursor(void) | |||
416 | } | 416 | } |
417 | } | 417 | } |
418 | 418 | ||
419 | #if ENABLE_PLATFORM_MINGW32 | ||
420 | static void inc_cursor(void) | ||
421 | { | ||
422 | CHAR_T c = command_ps[cursor]; | ||
423 | unsigned width = 0; | ||
424 | int ofs_to_right; | ||
425 | |||
426 | /* advance cursor */ | ||
427 | cursor++; | ||
428 | if (unicode_status == UNICODE_ON) { | ||
429 | IF_UNICODE_WIDE_WCHARS(width = cmdedit_x;) | ||
430 | c = adjust_width_and_validate_wc(&cmdedit_x, c); | ||
431 | IF_UNICODE_WIDE_WCHARS(width = cmdedit_x - width;) | ||
432 | } else { | ||
433 | cmdedit_x++; | ||
434 | } | ||
435 | |||
436 | ofs_to_right = cmdedit_x - cmdedit_termw; | ||
437 | if (!ENABLE_UNICODE_WIDE_WCHARS || ofs_to_right <= 0) { | ||
438 | /* cursor remains on this line */ | ||
439 | printf(ESC"[1C"); | ||
440 | } | ||
441 | |||
442 | if (ofs_to_right >= 0) { | ||
443 | /* we go to the next line */ | ||
444 | printf(ESC"[1B"); | ||
445 | bb_putchar('\r'); | ||
446 | cmdedit_y++; | ||
447 | if (!ENABLE_UNICODE_WIDE_WCHARS || ofs_to_right == 0) { | ||
448 | width = 0; | ||
449 | } | ||
450 | cmdedit_x = width; | ||
451 | } | ||
452 | } | ||
453 | #endif | ||
454 | |||
419 | /* Move to end of line (by printing all chars till the end) */ | 455 | /* Move to end of line (by printing all chars till the end) */ |
420 | static void put_till_end_and_adv_cursor(void) | 456 | static void put_till_end_and_adv_cursor(void) |
421 | { | 457 | { |
@@ -472,6 +508,7 @@ static void input_backward(unsigned num) | |||
472 | 508 | ||
473 | if (cmdedit_x >= num) { | 509 | if (cmdedit_x >= num) { |
474 | cmdedit_x -= num; | 510 | cmdedit_x -= num; |
511 | #if !ENABLE_PLATFORM_MINGW32 | ||
475 | if (num <= 4) { | 512 | if (num <= 4) { |
476 | /* This is longer by 5 bytes on x86. | 513 | /* This is longer by 5 bytes on x86. |
477 | * Also gets miscompiled for ARM users | 514 | * Also gets miscompiled for ARM users |
@@ -484,6 +521,7 @@ static void input_backward(unsigned num) | |||
484 | } while (--num); | 521 | } while (--num); |
485 | return; | 522 | return; |
486 | } | 523 | } |
524 | #endif | ||
487 | printf(ESC"[%uD", num); | 525 | printf(ESC"[%uD", num); |
488 | return; | 526 | return; |
489 | } | 527 | } |
@@ -615,7 +653,11 @@ static void input_backspace(void) | |||
615 | static void input_forward(void) | 653 | static void input_forward(void) |
616 | { | 654 | { |
617 | if (cursor < command_len) | 655 | if (cursor < command_len) |
656 | #if !ENABLE_PLATFORM_MINGW32 | ||
618 | put_cur_glyph_and_inc_cursor(); | 657 | put_cur_glyph_and_inc_cursor(); |
658 | #else | ||
659 | inc_cursor(); | ||
660 | #endif | ||
619 | } | 661 | } |
620 | 662 | ||
621 | #if ENABLE_FEATURE_TAB_COMPLETION | 663 | #if ENABLE_FEATURE_TAB_COMPLETION |
@@ -643,6 +685,14 @@ static void add_match(char *matched) | |||
643 | num_matches++; | 685 | num_matches++; |
644 | } | 686 | } |
645 | 687 | ||
688 | #if ENABLE_FEATURE_SH_STANDALONE && NUM_APPLETS != 1 | ||
689 | static void add_partial_match(const char *part, const char *full, int plen) | ||
690 | { | ||
691 | if (strncmp(part, full, plen) == 0) | ||
692 | add_match(xstrdup(full)); | ||
693 | } | ||
694 | #endif | ||
695 | |||
646 | # if ENABLE_FEATURE_USERNAME_COMPLETION | 696 | # if ENABLE_FEATURE_USERNAME_COMPLETION |
647 | /* Replace "~user/..." with "/homedir/...". | 697 | /* Replace "~user/..." with "/homedir/...". |
648 | * The parameter is malloced, free it or return it | 698 | * The parameter is malloced, free it or return it |
@@ -723,7 +773,11 @@ static int path_parse(char ***p) | |||
723 | tmp = (char*)pth; | 773 | tmp = (char*)pth; |
724 | npth = 1; /* path component count */ | 774 | npth = 1; /* path component count */ |
725 | while (1) { | 775 | while (1) { |
776 | #if ENABLE_PLATFORM_MINGW32 | ||
777 | tmp = (char *)next_path_sep(tmp); | ||
778 | #else | ||
726 | tmp = strchr(tmp, ':'); | 779 | tmp = strchr(tmp, ':'); |
780 | #endif | ||
727 | if (!tmp) | 781 | if (!tmp) |
728 | break; | 782 | break; |
729 | tmp++; | 783 | tmp++; |
@@ -736,7 +790,11 @@ static int path_parse(char ***p) | |||
736 | res[0] = tmp = xstrdup(pth); | 790 | res[0] = tmp = xstrdup(pth); |
737 | npth = 1; | 791 | npth = 1; |
738 | while (1) { | 792 | while (1) { |
793 | #if ENABLE_PLATFORM_MINGW32 | ||
794 | tmp = (char *)next_path_sep(tmp); | ||
795 | #else | ||
739 | tmp = strchr(tmp, ':'); | 796 | tmp = strchr(tmp, ':'); |
797 | #endif | ||
740 | if (!tmp) | 798 | if (!tmp) |
741 | break; | 799 | break; |
742 | *tmp++ = '\0'; /* ':' -> '\0' */ | 800 | *tmp++ = '\0'; /* ':' -> '\0' */ |
@@ -786,11 +844,11 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
786 | const char *p = applet_names; | 844 | const char *p = applet_names; |
787 | 845 | ||
788 | while (*p) { | 846 | while (*p) { |
789 | if (strncmp(pfind, p, pf_len) == 0) | 847 | add_partial_match(pfind, p, pf_len); |
790 | add_match(xstrdup(p)); | ||
791 | while (*p++ != '\0') | 848 | while (*p++ != '\0') |
792 | continue; | 849 | continue; |
793 | } | 850 | } |
851 | add_partial_match(pfind, "busybox", pf_len); | ||
794 | } | 852 | } |
795 | #endif | 853 | #endif |
796 | 854 | ||
@@ -822,6 +880,9 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
822 | if (stat(found, &st) && lstat(found, &st)) | 880 | if (stat(found, &st) && lstat(found, &st)) |
823 | goto cont; /* hmm, remove in progress? */ | 881 | goto cont; /* hmm, remove in progress? */ |
824 | 882 | ||
883 | if (type == FIND_EXE_ONLY && !file_is_executable(found)) | ||
884 | goto cont; | ||
885 | |||
825 | /* Save only name */ | 886 | /* Save only name */ |
826 | len = strlen(name_found); | 887 | len = strlen(name_found); |
827 | found = xrealloc(found, len + 2); /* +2: for slash and NUL */ | 888 | found = xrealloc(found, len + 2); /* +2: for slash and NUL */ |
@@ -1903,7 +1964,16 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
1903 | char *after_home_user; | 1964 | char *after_home_user; |
1904 | 1965 | ||
1905 | /* /home/user[/something] -> ~[/something] */ | 1966 | /* /home/user[/something] -> ~[/something] */ |
1967 | #if !ENABLE_PLATFORM_MINGW32 | ||
1906 | after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf); | 1968 | after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf); |
1969 | #else | ||
1970 | after_home_user = NULL; | ||
1971 | l = strlen(home_pwd_buf); | ||
1972 | if (l != 0 | ||
1973 | && strncasecmp(home_pwd_buf, cwd_buf, l) == 0) { | ||
1974 | after_home_user = cwd_buf + l; | ||
1975 | } | ||
1976 | #endif | ||
1907 | if (after_home_user | 1977 | if (after_home_user |
1908 | && (*after_home_user == '/' || *after_home_user == '\0') | 1978 | && (*after_home_user == '/' || *after_home_user == '\0') |
1909 | ) { | 1979 | ) { |
@@ -2273,9 +2343,16 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2273 | 2343 | ||
2274 | INIT_S(); | 2344 | INIT_S(); |
2275 | 2345 | ||
2346 | #if ENABLE_PLATFORM_MINGW32 | ||
2347 | memset(initial_settings.c_cc, 0, sizeof(initial_settings.c_cc)); | ||
2348 | initial_settings.c_cc[VINTR] = CTRL('C'); | ||
2349 | initial_settings.c_cc[VEOF] = CTRL('D'); | ||
2350 | if (!isatty(0) || !isatty(1)) { | ||
2351 | #else | ||
2276 | if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 | 2352 | if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 |
2277 | || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON | 2353 | || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON |
2278 | ) { | 2354 | ) { |
2355 | #endif | ||
2279 | /* Happens when e.g. stty -echo was run before. | 2356 | /* Happens when e.g. stty -echo was run before. |
2280 | * But if ICANON is not set, we don't come here. | 2357 | * But if ICANON is not set, we don't come here. |
2281 | * (example: interactive python ^Z-backgrounded, | 2358 | * (example: interactive python ^Z-backgrounded, |
@@ -2376,6 +2453,11 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2376 | 2453 | ||
2377 | fflush_all(); | 2454 | fflush_all(); |
2378 | ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); | 2455 | ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); |
2456 | #if ENABLE_PLATFORM_MINGW32 | ||
2457 | /* scroll to cursor position on any keypress */ | ||
2458 | if (isatty(fileno(stdin)) && isatty(fileno(stdout))) | ||
2459 | move_cursor_row(0); | ||
2460 | #endif | ||
2379 | 2461 | ||
2380 | #if ENABLE_FEATURE_REVERSE_SEARCH | 2462 | #if ENABLE_FEATURE_REVERSE_SEARCH |
2381 | again: | 2463 | again: |
@@ -2629,7 +2711,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2629 | * standard readline bindings (IOW: bash) do. | 2711 | * standard readline bindings (IOW: bash) do. |
2630 | * Often, Alt-<key> generates ESC-<key>. | 2712 | * Often, Alt-<key> generates ESC-<key>. |
2631 | */ | 2713 | */ |
2632 | ic = lineedit_read_key(read_key_buffer, 50); | 2714 | ic = lineedit_read_key(read_key_buffer, 20); |
2633 | switch (ic) { | 2715 | switch (ic) { |
2634 | //case KEYCODE_LEFT: - bash doesn't do this | 2716 | //case KEYCODE_LEFT: - bash doesn't do this |
2635 | case 'b': | 2717 | case 'b': |
diff --git a/libbb/make_directory.c b/libbb/make_directory.c index 89352ca1f..3980376ec 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c | |||
@@ -45,6 +45,31 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags) | |||
45 | c = '\0'; | 45 | c = '\0'; |
46 | 46 | ||
47 | if (flags & FILEUTILS_RECUR) { /* Get the parent */ | 47 | if (flags & FILEUTILS_RECUR) { /* Get the parent */ |
48 | #if ENABLE_PLATFORM_MINGW32 | ||
49 | if (s == path && *s && s[1] == ':') { | ||
50 | /* skip drive letter */ | ||
51 | s += 2; | ||
52 | } | ||
53 | else if (s == path && s[0] == '/' && s[1] == '/' ) { | ||
54 | /* skip UNC server and share */ | ||
55 | int count = 0; | ||
56 | s += 2; | ||
57 | while (*s) { | ||
58 | if (*s == '/') { | ||
59 | do { | ||
60 | ++s; | ||
61 | } while (*s == '/'); | ||
62 | if (++count == 2) { | ||
63 | --s; | ||
64 | break; | ||
65 | } | ||
66 | } | ||
67 | else { | ||
68 | ++s; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | #endif | ||
48 | /* Bypass leading non-'/'s and then subsequent '/'s */ | 73 | /* Bypass leading non-'/'s and then subsequent '/'s */ |
49 | while (*s) { | 74 | while (*s) { |
50 | if (*s == '/') { | 75 | if (*s == '/') { |
diff --git a/libbb/messages.c b/libbb/messages.c index cb0836de8..d74c237e7 100644 --- a/libbb/messages.c +++ b/libbb/messages.c | |||
@@ -35,7 +35,9 @@ const char bb_msg_standard_output[] ALIGN1 = "standard output"; | |||
35 | 35 | ||
36 | const char bb_hexdigits_upcase[] ALIGN1 = "0123456789ABCDEF"; | 36 | const char bb_hexdigits_upcase[] ALIGN1 = "0123456789ABCDEF"; |
37 | 37 | ||
38 | #if !ENABLE_PLATFORM_MINGW32 | ||
38 | const char bb_busybox_exec_path[] ALIGN1 = CONFIG_BUSYBOX_EXEC_PATH; | 39 | const char bb_busybox_exec_path[] ALIGN1 = CONFIG_BUSYBOX_EXEC_PATH; |
40 | #endif | ||
39 | const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL; | 41 | const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL; |
40 | /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, | 42 | /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, |
41 | * but I want to save a few bytes here. Check libbb.h before changing! */ | 43 | * but I want to save a few bytes here. Check libbb.h before changing! */ |
diff --git a/libbb/printable_string.c b/libbb/printable_string.c index 077d58d32..e638a178e 100644 --- a/libbb/printable_string.c +++ b/libbb/printable_string.c | |||
@@ -42,7 +42,7 @@ const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str) | |||
42 | unsigned char c = *d; | 42 | unsigned char c = *d; |
43 | if (c == '\0') | 43 | if (c == '\0') |
44 | break; | 44 | break; |
45 | if (c < ' ' || c >= 0x7f) | 45 | if (c < ' ' || (c >= 0x7f && !ENABLE_PLATFORM_MINGW32)) |
46 | *d = '?'; | 46 | *d = '?'; |
47 | d++; | 47 | d++; |
48 | } | 48 | } |
diff --git a/libbb/procps.c b/libbb/procps.c index 4edc54d48..452b50b82 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -75,6 +75,7 @@ const char* FAST_FUNC get_cached_groupname(gid_t gid) | |||
75 | return get_cached(&groupname, gid, gid2group_utoa); | 75 | return get_cached(&groupname, gid, gid2group_utoa); |
76 | } | 76 | } |
77 | 77 | ||
78 | #if !ENABLE_PLATFORM_MINGW32 | ||
78 | 79 | ||
79 | #define PROCPS_BUFSIZE 1024 | 80 | #define PROCPS_BUFSIZE 1024 |
80 | 81 | ||
@@ -618,6 +619,8 @@ void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) | |||
618 | } | 619 | } |
619 | } | 620 | } |
620 | 621 | ||
622 | #endif /* ENABLE_PLATFORM_MINGW32 */ | ||
623 | |||
621 | /* from kernel: | 624 | /* from kernel: |
622 | // pid comm S ppid pgid sid tty_nr tty_pgrp flg | 625 | // pid comm S ppid pgid sid tty_nr tty_pgrp flg |
623 | sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \ | 626 | sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \ |
diff --git a/libbb/read_printf.c b/libbb/read_printf.c index b6a17cc36..e47ac7afe 100644 --- a/libbb/read_printf.c +++ b/libbb/read_printf.c | |||
@@ -93,6 +93,11 @@ char* FAST_FUNC xmalloc_reads(int fd, size_t *maxsz_p) | |||
93 | break; | 93 | break; |
94 | p++; | 94 | p++; |
95 | } | 95 | } |
96 | #if ENABLE_PLATFORM_MINGW32 | ||
97 | if ( p != buf && *(p-1) == '\r' ) { | ||
98 | --p; | ||
99 | } | ||
100 | #endif | ||
96 | *p = '\0'; | 101 | *p = '\0'; |
97 | if (maxsz_p) | 102 | if (maxsz_p) |
98 | *maxsz_p = p - buf; | 103 | *maxsz_p = p - buf; |
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 4258656fe..944ac5538 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c | |||
@@ -30,6 +30,14 @@ | |||
30 | 30 | ||
31 | #include "libbb.h" | 31 | #include "libbb.h" |
32 | 32 | ||
33 | #if ENABLE_PLATFORM_MINGW32 | ||
34 | static void xsetenv_if_unset(const char *key, const char *value) | ||
35 | { | ||
36 | if (!getenv(key)) | ||
37 | xsetenv(key, value); | ||
38 | } | ||
39 | #endif | ||
40 | |||
33 | void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) | 41 | void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) |
34 | { | 42 | { |
35 | if (!shell || !shell[0]) | 43 | if (!shell || !shell[0]) |
@@ -61,6 +69,9 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass | |||
61 | //xsetenv("HOME", pw->pw_dir); | 69 | //xsetenv("HOME", pw->pw_dir); |
62 | //xsetenv("SHELL", shell); | 70 | //xsetenv("SHELL", shell); |
63 | } else if (flags & SETUP_ENV_CHANGEENV) { | 71 | } else if (flags & SETUP_ENV_CHANGEENV) { |
72 | #if ENABLE_PLATFORM_MINGW32 | ||
73 | #define xsetenv(k, v) xsetenv_if_unset(k, v) | ||
74 | #endif | ||
64 | /* Set HOME, SHELL, and if not becoming a super-user, | 75 | /* Set HOME, SHELL, and if not becoming a super-user, |
65 | * USER and LOGNAME. */ | 76 | * USER and LOGNAME. */ |
66 | if (pw->pw_uid) { | 77 | if (pw->pw_uid) { |
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index c192829b5..766a89e5f 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -17,6 +17,7 @@ | |||
17 | 17 | ||
18 | #include "busybox.h" /* uses applet tables */ | 18 | #include "busybox.h" /* uses applet tables */ |
19 | 19 | ||
20 | #if !ENABLE_PLATFORM_MINGW32 | ||
20 | /* This does a fork/exec in one call, using vfork(). Returns PID of new child, | 21 | /* This does a fork/exec in one call, using vfork(). Returns PID of new child, |
21 | * -1 for failure. Runs argv[0], searching path if that has no / in it. */ | 22 | * -1 for failure. Runs argv[0], searching path if that has no / in it. */ |
22 | pid_t FAST_FUNC spawn(char **argv) | 23 | pid_t FAST_FUNC spawn(char **argv) |
@@ -58,6 +59,7 @@ pid_t FAST_FUNC spawn(char **argv) | |||
58 | } | 59 | } |
59 | return pid; | 60 | return pid; |
60 | } | 61 | } |
62 | #endif | ||
61 | 63 | ||
62 | /* Die with an error message if we can't spawn a child process. */ | 64 | /* Die with an error message if we can't spawn a child process. */ |
63 | pid_t FAST_FUNC xspawn(char **argv) | 65 | pid_t FAST_FUNC xspawn(char **argv) |
@@ -194,7 +196,7 @@ int FAST_FUNC spawn_and_wait(char **argv) | |||
194 | { | 196 | { |
195 | return run_nofork_applet(a, argv); | 197 | return run_nofork_applet(a, argv); |
196 | } | 198 | } |
197 | # if BB_MMU | 199 | # if BB_MMU && !ENABLE_PLATFORM_MINGW32 |
198 | /* MMU only */ | 200 | /* MMU only */ |
199 | /* a->noexec is true */ | 201 | /* a->noexec is true */ |
200 | rc = fork(); | 202 | rc = fork(); |
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 3a0dc2653..ee54898e3 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -98,15 +98,15 @@ len_and_sockaddr* FAST_FUNC get_peer_lsa(int fd) | |||
98 | return get_lsa(fd, getpeername); | 98 | return get_lsa(fd, getpeername); |
99 | } | 99 | } |
100 | 100 | ||
101 | void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) | 101 | void FAST_FUNC xconnect(int s, const struct sockaddr *saddr, socklen_t addrlen) |
102 | { | 102 | { |
103 | if (connect(s, s_addr, addrlen) < 0) { | 103 | if (connect(s, saddr, addrlen) < 0) { |
104 | if (ENABLE_FEATURE_CLEAN_UP) | 104 | if (ENABLE_FEATURE_CLEAN_UP) |
105 | close(s); | 105 | close(s); |
106 | if (s_addr->sa_family == AF_INET) | 106 | if (saddr->sa_family == AF_INET) |
107 | bb_perror_msg_and_die("%s (%s)", | 107 | bb_perror_msg_and_die("%s (%s)", |
108 | "can't connect to remote host", | 108 | "can't connect to remote host", |
109 | inet_ntoa(((struct sockaddr_in *)s_addr)->sin_addr)); | 109 | inet_ntoa(((struct sockaddr_in *)saddr)->sin_addr)); |
110 | bb_perror_msg_and_die("can't connect to remote host"); | 110 | bb_perror_msg_and_die("can't connect to remote host"); |
111 | } | 111 | } |
112 | } | 112 | } |
@@ -353,6 +353,10 @@ int FAST_FUNC xsocket_type(len_and_sockaddr **lsap, int family, int sock_type) | |||
353 | #if ENABLE_FEATURE_IPV6 | 353 | #if ENABLE_FEATURE_IPV6 |
354 | fd = socket(AF_INET6, sock_type, 0); | 354 | fd = socket(AF_INET6, sock_type, 0); |
355 | if (fd >= 0) { | 355 | if (fd >= 0) { |
356 | #if ENABLE_PLATFORM_MINGW32 | ||
357 | DWORD buffer = 0; | ||
358 | setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &buffer, sizeof(DWORD)); | ||
359 | #endif | ||
356 | family = AF_INET6; | 360 | family = AF_INET6; |
357 | goto done; | 361 | goto done; |
358 | } | 362 | } |
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index 7d4cb60a5..2c5a9ef39 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c | |||
@@ -65,7 +65,7 @@ char* FAST_FUNC xmalloc_follow_symlinks(const char *path) | |||
65 | linkpath = xmalloc_readlink(buf); | 65 | linkpath = xmalloc_readlink(buf); |
66 | if (!linkpath) { | 66 | if (!linkpath) { |
67 | /* not a symlink, or doesn't exist */ | 67 | /* not a symlink, or doesn't exist */ |
68 | if (errno == EINVAL || errno == ENOENT) | 68 | if (errno == EINVAL || errno == ENOENT || (ENABLE_PLATFORM_MINGW32 && errno == ENOSYS)) |
69 | return buf; | 69 | return buf; |
70 | goto free_buf_ret_null; | 70 | goto free_buf_ret_null; |
71 | } | 71 | } |