diff options
author | Ron Yorston <rmy@pobox.com> | 2018-02-13 09:44:44 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-02-13 09:44:44 +0000 |
commit | dc19a361bd6c6df30338371532691bbc7f7126bb (patch) | |
tree | 1fb2cd646d54b5f8e425c4f11f3e09fc21d1966b /libbb | |
parent | 096aee2bb468d1ab044de36e176ed1f6c7e3674d (diff) | |
parent | 3459024bf404af814cacfe90a0deb719e282ae62 (diff) | |
download | busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.gz busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.bz2 busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Kbuild.src | 4 | ||||
-rw-r--r-- | libbb/bb_getsockname.c | 19 | ||||
-rw-r--r-- | libbb/crc32.c | 10 | ||||
-rw-r--r-- | libbb/executable.c | 31 | ||||
-rw-r--r-- | libbb/lineedit.c | 3 | ||||
-rw-r--r-- | libbb/make_directory.c | 16 | ||||
-rw-r--r-- | libbb/messages.c | 8 | ||||
-rw-r--r-- | libbb/progress.c | 112 |
8 files changed, 122 insertions, 81 deletions
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index 6749cceda..c0cc2baf5 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src | |||
@@ -128,6 +128,7 @@ lib-$(CONFIG_UNICODE_SUPPORT) += unicode.o | |||
128 | lib-$(CONFIG_FEATURE_CHECK_NAMES) += die_if_bad_username.o | 128 | lib-$(CONFIG_FEATURE_CHECK_NAMES) += die_if_bad_username.o |
129 | 129 | ||
130 | lib-$(CONFIG_NC_110_COMPAT) += udp_io.o | 130 | lib-$(CONFIG_NC_110_COMPAT) += udp_io.o |
131 | lib-$(CONFIG_NETCAT) += udp_io.o | ||
131 | lib-$(CONFIG_DNSD) += udp_io.o | 132 | lib-$(CONFIG_DNSD) += udp_io.o |
132 | lib-$(CONFIG_NTPD) += udp_io.o | 133 | lib-$(CONFIG_NTPD) += udp_io.o |
133 | lib-$(CONFIG_TFTP) += udp_io.o | 134 | lib-$(CONFIG_TFTP) += udp_io.o |
@@ -146,7 +147,8 @@ lib-$(CONFIG_DELGROUP) += update_passwd.o | |||
146 | lib-$(CONFIG_DELUSER) += update_passwd.o | 147 | lib-$(CONFIG_DELUSER) += update_passwd.o |
147 | 148 | ||
148 | lib-$(CONFIG_FTPD) += pw_encrypt.o correct_password.o | 149 | lib-$(CONFIG_FTPD) += pw_encrypt.o correct_password.o |
149 | lib-$(CONFIG_PASSWD) += pw_encrypt.o update_passwd.o obscure.o | 150 | lib-$(CONFIG_PASSWD) += pw_encrypt.o update_passwd.o |
151 | lib-$(CONFIG_FEATURE_PASSWD_WEAK_CHECK) += obscure.o | ||
150 | lib-$(CONFIG_CHPASSWD) += pw_encrypt.o update_passwd.o | 152 | lib-$(CONFIG_CHPASSWD) += pw_encrypt.o update_passwd.o |
151 | lib-$(CONFIG_CRYPTPW) += pw_encrypt.o | 153 | lib-$(CONFIG_CRYPTPW) += pw_encrypt.o |
152 | lib-$(CONFIG_MKPASSWD) += pw_encrypt.o | 154 | lib-$(CONFIG_MKPASSWD) += pw_encrypt.o |
diff --git a/libbb/bb_getsockname.c b/libbb/bb_getsockname.c new file mode 100644 index 000000000..1af9b39b9 --- /dev/null +++ b/libbb/bb_getsockname.c | |||
@@ -0,0 +1,19 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
6 | */ | ||
7 | //kbuild:lib-y += bb_getsockname.o | ||
8 | |||
9 | #include "libbb.h" | ||
10 | |||
11 | int FAST_FUNC bb_getsockname(int sockfd, void *addr, socklen_t addrlen) | ||
12 | { | ||
13 | /* The usefullness of this function is that for getsockname(), | ||
14 | * addrlen must go on stack (to _have_ an address to be passed), | ||
15 | * but many callers do not need its modified value. | ||
16 | * By using this shim, they can avoid unnecessary stack spillage. | ||
17 | */ | ||
18 | return getsockname(sockfd, (struct sockaddr *)addr, &addrlen); | ||
19 | } | ||
diff --git a/libbb/crc32.c b/libbb/crc32.c index b00b580d0..728bcb736 100644 --- a/libbb/crc32.c +++ b/libbb/crc32.c | |||
@@ -41,6 +41,16 @@ uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian) | |||
41 | 41 | ||
42 | return crc_table - 256; | 42 | return crc_table - 256; |
43 | } | 43 | } |
44 | /* Common uses: */ | ||
45 | uint32_t* FAST_FUNC crc32_new_table_le(void) | ||
46 | { | ||
47 | return crc32_filltable(NULL, 0); | ||
48 | } | ||
49 | uint32_t* FAST_FUNC global_crc32_new_table_le(void) | ||
50 | { | ||
51 | global_crc32_table = crc32_new_table_le(); | ||
52 | return global_crc32_table; | ||
53 | } | ||
44 | 54 | ||
45 | uint32_t FAST_FUNC crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) | 55 | uint32_t FAST_FUNC crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) |
46 | { | 56 | { |
diff --git a/libbb/executable.c b/libbb/executable.c index b28f020e0..8e2f99732 100644 --- a/libbb/executable.c +++ b/libbb/executable.c | |||
@@ -25,7 +25,8 @@ int FAST_FUNC file_is_executable(const char *name) | |||
25 | * you may call find_executable again with this PATHp to continue | 25 | * you may call find_executable again with this PATHp to continue |
26 | * (if it's not NULL). | 26 | * (if it's not NULL). |
27 | * return NULL otherwise; (PATHp is undefined) | 27 | * return NULL otherwise; (PATHp is undefined) |
28 | * in all cases (*PATHp) contents will be trashed (s/:/NUL/). | 28 | * in all cases (*PATHp) contents are temporarily modified |
29 | * but are restored on return (s/:/NUL/ and back). | ||
29 | */ | 30 | */ |
30 | #if !ENABLE_PLATFORM_MINGW32 | 31 | #if !ENABLE_PLATFORM_MINGW32 |
31 | #define next_path_sep(s) strchr(s, ':') | 32 | #define next_path_sep(s) strchr(s, ':') |
@@ -48,14 +49,30 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) | |||
48 | 49 | ||
49 | p = *PATHp; | 50 | p = *PATHp; |
50 | while (p) { | 51 | while (p) { |
52 | int ex; | ||
53 | #if ENABLE_PLATFORM_MINGW32 | ||
54 | char sep; | ||
55 | |||
51 | n = (char*)next_path_sep(p); | 56 | n = (char*)next_path_sep(p); |
52 | if (n) | 57 | if (n) { |
53 | *n++ = '\0'; | 58 | sep = *n; |
59 | *n = '\0'; | ||
60 | } | ||
61 | #else | ||
62 | n = strchr(p, ':'); | ||
63 | if (n) *n = '\0'; | ||
64 | #endif | ||
54 | p = concat_path_file( | 65 | p = concat_path_file( |
55 | p[0] ? p : ".", /* handle "::" case */ | 66 | p[0] ? p : ".", /* handle "::" case */ |
56 | filename | 67 | filename |
57 | ); | 68 | ); |
58 | if (file_is_executable(p)) { | 69 | ex = file_is_executable(p); |
70 | #if ENABLE_PLATFORM_MINGW32 | ||
71 | if (n) *n++ = sep; | ||
72 | #else | ||
73 | if (n) *n++ = ':'; | ||
74 | #endif | ||
75 | if (ex) { | ||
59 | *PATHp = n; | 76 | *PATHp = n; |
60 | return p; | 77 | return p; |
61 | } | 78 | } |
@@ -78,10 +95,8 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) | |||
78 | */ | 95 | */ |
79 | int FAST_FUNC executable_exists(const char *filename) | 96 | int FAST_FUNC executable_exists(const char *filename) |
80 | { | 97 | { |
81 | char *path = xstrdup(getenv("PATH")); | 98 | char *path = getenv("PATH"); |
82 | char *tmp = path; | 99 | char *ret = find_executable(filename, &path); |
83 | char *ret = find_executable(filename, &tmp); | ||
84 | free(path); | ||
85 | free(ret); | 100 | free(ret); |
86 | return ret != NULL; | 101 | return ret != NULL; |
87 | } | 102 | } |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 3df67abb1..f22f5768f 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -90,7 +90,8 @@ static bool BB_ispunct(CHAR_T c) { return ((unsigned)c < 256 && ispunct(c)); } | |||
90 | # define CHAR_T char | 90 | # define CHAR_T char |
91 | # define BB_isspace(c) isspace(c) | 91 | # define BB_isspace(c) isspace(c) |
92 | # if ENABLE_FEATURE_EDITING_VI | 92 | # if ENABLE_FEATURE_EDITING_VI |
93 | static bool BB_isalnum_or_underscore(CHAR_T c) { | 93 | static bool BB_isalnum_or_underscore(CHAR_T c) |
94 | { | ||
94 | return ((unsigned)c < 256 && isalnum(c)) || c == '_'; | 95 | return ((unsigned)c < 256 && isalnum(c)) || c == '_'; |
95 | } | 96 | } |
96 | # endif | 97 | # endif |
diff --git a/libbb/make_directory.c b/libbb/make_directory.c index 6422c863f..1f3aecf40 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c | |||
@@ -125,6 +125,7 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags) | |||
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | //bb_error_msg("mkdir '%s'", path); | ||
128 | if (mkdir(path, 0777) < 0) { | 129 | if (mkdir(path, 0777) < 0) { |
129 | /* If we failed for any other reason than the directory | 130 | /* If we failed for any other reason than the directory |
130 | * already exists, output a diagnostic and return -1 */ | 131 | * already exists, output a diagnostic and return -1 */ |
@@ -151,13 +152,16 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags) | |||
151 | /* Done. If necessary, update perms on the newly | 152 | /* Done. If necessary, update perms on the newly |
152 | * created directory. Failure to update here _is_ | 153 | * created directory. Failure to update here _is_ |
153 | * an error. */ | 154 | * an error. */ |
154 | if ((mode != -1) && (chmod(path, mode) < 0)) { | 155 | if (mode != -1) { |
155 | fail_msg = "set permissions of"; | 156 | //bb_error_msg("chmod 0%03lo mkdir '%s'", mode, path); |
156 | if (flags & FILEUTILS_IGNORE_CHMOD_ERR) { | 157 | if (chmod(path, mode) < 0) { |
157 | flags = 0; | 158 | fail_msg = "set permissions of"; |
158 | goto print_err; | 159 | if (flags & FILEUTILS_IGNORE_CHMOD_ERR) { |
160 | flags = 0; | ||
161 | goto print_err; | ||
162 | } | ||
163 | break; | ||
159 | } | 164 | } |
160 | break; | ||
161 | } | 165 | } |
162 | goto ret0; | 166 | goto ret0; |
163 | } | 167 | } |
diff --git a/libbb/messages.c b/libbb/messages.c index 31721a3b3..f5bbd3e32 100644 --- a/libbb/messages.c +++ b/libbb/messages.c | |||
@@ -6,11 +6,6 @@ | |||
6 | */ | 6 | */ |
7 | #include "libbb.h" | 7 | #include "libbb.h" |
8 | 8 | ||
9 | /* allow default system PATH to be extended via CFLAGS */ | ||
10 | #ifndef BB_ADDITIONAL_PATH | ||
11 | #define BB_ADDITIONAL_PATH "" | ||
12 | #endif | ||
13 | |||
14 | /* allow version to be extended, via CFLAGS */ | 9 | /* allow version to be extended, via CFLAGS */ |
15 | #ifndef BB_EXTRA_VERSION | 10 | #ifndef BB_EXTRA_VERSION |
16 | #define BB_EXTRA_VERSION " ("AUTOCONF_TIMESTAMP")" | 11 | #define BB_EXTRA_VERSION " ("AUTOCONF_TIMESTAMP")" |
@@ -38,8 +33,7 @@ const char bb_busybox_exec_path[] ALIGN1 = CONFIG_BUSYBOX_EXEC_PATH; | |||
38 | const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL; | 33 | const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL; |
39 | /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, | 34 | /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, |
40 | * but I want to save a few bytes here. Check libbb.h before changing! */ | 35 | * but I want to save a few bytes here. Check libbb.h before changing! */ |
41 | const char bb_PATH_root_path[] ALIGN1 = | 36 | const char bb_PATH_root_path[] ALIGN1 = BB_PATH_ROOT_PATH; |
42 | "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH; | ||
43 | 37 | ||
44 | 38 | ||
45 | //const int const_int_1 = 1; | 39 | //const int const_int_1 = 1; |
diff --git a/libbb/progress.c b/libbb/progress.c index 64e6529ac..f1d980d68 100644 --- a/libbb/progress.c +++ b/libbb/progress.c | |||
@@ -71,10 +71,9 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, | |||
71 | uoff_t transferred, | 71 | uoff_t transferred, |
72 | uoff_t totalsize) | 72 | uoff_t totalsize) |
73 | { | 73 | { |
74 | uoff_t beg_and_transferred; | 74 | char numbuf5[6]; /* 5 + 1 for NUL */ |
75 | unsigned since_last_update, elapsed; | 75 | unsigned since_last_update, elapsed; |
76 | int notty; | 76 | int notty; |
77 | int kiloscale; | ||
78 | 77 | ||
79 | //transferred = 1234; /* use for stall detection testing */ | 78 | //transferred = 1234; /* use for stall detection testing */ |
80 | //totalsize = 0; /* use for unknown size download testing */ | 79 | //totalsize = 0; /* use for unknown size download testing */ |
@@ -95,74 +94,69 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, | |||
95 | return; | 94 | return; |
96 | } | 95 | } |
97 | 96 | ||
98 | kiloscale = 0; | 97 | /* Before we lose real, unscaled sizes, produce human-readable size string */ |
98 | smart_ulltoa5(beg_size + transferred, numbuf5, " kMGTPEZY")[0] = '\0'; | ||
99 | |||
99 | /* | 100 | /* |
100 | * Scale sizes down if they are close to overflowing. | 101 | * Scale sizes down if they are close to overflowing. |
101 | * This allows calculations like (100 * transferred / totalsize) | 102 | * This allows calculations like (100 * transferred / totalsize) |
102 | * without risking overflow: we guarantee 10 highest bits to be 0. | 103 | * without risking overflow: we guarantee 10 highest bits to be 0. |
103 | * Introduced error is less than 1 / 2^12 ~= 0.025% | 104 | * Introduced error is less than 1 / 2^12 ~= 0.025% |
104 | */ | 105 | */ |
105 | if (ULONG_MAX > 0xffffffff || sizeof(off_t) == 4 || sizeof(off_t) != 8) { | 106 | while (totalsize >= (1 << 20)) { |
106 | /* | 107 | totalsize >>= 8; |
107 | * 64-bit CPU || small off_t: in either case, | 108 | beg_size >>= 8; |
108 | * >> is cheap, single-word operation. | 109 | transferred >>= 8; |
109 | * ... || strange off_t: also use this code | ||
110 | * (it is safe, just suboptimal wrt code size), | ||
111 | * because 32/64 optimized one works only for 64-bit off_t. | ||
112 | */ | ||
113 | if (totalsize >= (1 << 22)) { | ||
114 | totalsize >>= 10; | ||
115 | beg_size >>= 10; | ||
116 | transferred >>= 10; | ||
117 | kiloscale = 1; | ||
118 | } | ||
119 | } else { | ||
120 | /* 32-bit CPU and 64-bit off_t. | ||
121 | * Use a 40-bit shift, it is easier to do on 32-bit CPU. | ||
122 | */ | ||
123 | /* ONE suppresses "warning: shift count >= width of type" */ | ||
124 | #define ONE (sizeof(off_t) > 4) | ||
125 | if (totalsize >= (uoff_t)(1ULL << 54*ONE)) { | ||
126 | totalsize = (uint32_t)(totalsize >> 32*ONE) >> 8; | ||
127 | beg_size = (uint32_t)(beg_size >> 32*ONE) >> 8; | ||
128 | transferred = (uint32_t)(transferred >> 32*ONE) >> 8; | ||
129 | kiloscale = 4; | ||
130 | } | ||
131 | } | 110 | } |
111 | /* If they were huge, now they are scaled down to [1048575,4096] range. | ||
112 | * (N * totalsize) won't overflow 32 bits for N up to 4096. | ||
113 | */ | ||
114 | #if ULONG_MAX == 0xffffffff | ||
115 | /* 32-bit CPU, uoff_t arithmetic is complex on it, cast variables to narrower types */ | ||
116 | # define totalsize ((unsigned)totalsize) | ||
117 | # define beg_size ((unsigned)beg_size) | ||
118 | # define transferred ((unsigned)transferred) | ||
119 | #endif | ||
132 | 120 | ||
133 | notty = !isatty(STDERR_FILENO); | 121 | notty = !isatty(STDERR_FILENO); |
134 | 122 | ||
135 | if (ENABLE_UNICODE_SUPPORT) | 123 | if (ENABLE_UNICODE_SUPPORT) |
136 | fprintf(stderr, "\r%s" + notty, p->curfile); | 124 | fprintf(stderr, "\r%s " + notty, p->curfile); |
137 | else | 125 | else |
138 | fprintf(stderr, "\r%-20.20s" + notty, p->curfile); | 126 | fprintf(stderr, "\r%-20.20s " + notty, p->curfile); |
139 | |||
140 | beg_and_transferred = beg_size + transferred; | ||
141 | 127 | ||
142 | if (totalsize != 0) { | 128 | if (totalsize != 0) { |
143 | int barlength; | 129 | int barlength; |
144 | unsigned ratio = 100 * beg_and_transferred / totalsize; | 130 | unsigned beg_and_transferred; /* does not need uoff_t, see scaling code */ |
145 | fprintf(stderr, "%4u%%", ratio); | 131 | unsigned ratio; |
146 | 132 | ||
147 | barlength = get_terminal_width(2) - 49; | 133 | beg_and_transferred = beg_size + transferred; |
148 | if (barlength > 0) { | 134 | ratio = 100 * beg_and_transferred / totalsize; |
149 | /* god bless gcc for variable arrays :) */ | 135 | /* can't overflow ^^^^^^^^^^^^^^^ */ |
150 | char buf[barlength + 1]; | 136 | fprintf(stderr, "%3u%% ", ratio); |
151 | unsigned stars = (unsigned)barlength * beg_and_transferred / totalsize; | 137 | |
152 | memset(buf, ' ', barlength); | 138 | barlength = get_terminal_width(2) - 48; |
153 | buf[barlength] = '\0'; | 139 | /* |
154 | memset(buf, '*', stars); | 140 | * Must reject barlength <= 0 (terminal too narrow). While at it, |
155 | fprintf(stderr, " |%s|", buf); | 141 | * also reject: 1-char bar (useless), 2-char bar (ridiculous). |
142 | */ | ||
143 | if (barlength > 2) { | ||
144 | if (barlength > 999) | ||
145 | barlength = 999; | ||
146 | { | ||
147 | /* god bless gcc for variable arrays :) */ | ||
148 | char buf[barlength + 1]; | ||
149 | unsigned stars = (unsigned)barlength * beg_and_transferred / totalsize; | ||
150 | /* can't overflow ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ | ||
151 | memset(buf, ' ', barlength); | ||
152 | buf[barlength] = '\0'; | ||
153 | memset(buf, '*', stars); | ||
154 | fprintf(stderr, "|%s| ", buf); | ||
155 | } | ||
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
159 | while (beg_and_transferred >= 100000) { | 159 | fputs(numbuf5, stderr); /* "NNNNk" */ |
160 | beg_and_transferred >>= 10; | ||
161 | kiloscale++; | ||
162 | } | ||
163 | /* see http://en.wikipedia.org/wiki/Tera */ | ||
164 | fprintf(stderr, "%6u%c", (unsigned)beg_and_transferred, " kMGTPEZY"[kiloscale]); | ||
165 | #define beg_and_transferred dont_use_beg_and_transferred_below() | ||
166 | 160 | ||
167 | since_last_update = elapsed - p->last_change_sec; | 161 | since_last_update = elapsed - p->last_change_sec; |
168 | if ((unsigned)transferred != p->last_size) { | 162 | if ((unsigned)transferred != p->last_size) { |
@@ -184,16 +178,18 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, | |||
184 | fprintf(stderr, " --:--:-- ETA"); | 178 | fprintf(stderr, " --:--:-- ETA"); |
185 | } else { | 179 | } else { |
186 | unsigned eta, secs, hours; | 180 | unsigned eta, secs, hours; |
181 | unsigned bytes; | ||
187 | 182 | ||
188 | totalsize -= beg_size; /* now it's "total to upload" */ | 183 | bytes = totalsize - beg_size; |
189 | 184 | ||
190 | /* Estimated remaining time = | 185 | /* Estimated remaining time = |
191 | * estimated_sec_to_dl_totalsize_bytes - elapsed_sec = | 186 | * estimated_sec_to_dl_bytes - elapsed_sec = |
192 | * totalsize / average_bytes_sec_so_far - elapsed = | 187 | * bytes / average_bytes_sec_so_far - elapsed = |
193 | * totalsize / (transferred/elapsed) - elapsed = | 188 | * bytes / (transferred/elapsed) - elapsed = |
194 | * totalsize * elapsed / transferred - elapsed | 189 | * bytes * elapsed / transferred - elapsed |
195 | */ | 190 | */ |
196 | eta = totalsize * elapsed / transferred - elapsed; | 191 | eta = (unsigned long)bytes * elapsed / transferred - elapsed; |
192 | /* if 32bit, can overflow ^^^^^^^^^^, but this would only show bad ETA */ | ||
197 | if (eta >= 1000*60*60) | 193 | if (eta >= 1000*60*60) |
198 | eta = 1000*60*60 - 1; | 194 | eta = 1000*60*60 - 1; |
199 | secs = eta % 3600; | 195 | secs = eta % 3600; |