diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 12:56:34 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 12:56:34 +1000 |
commit | c31744ca1a86b2276c37c6d9a884660185debed6 (patch) | |
tree | bb051c35c3430a3793ceef173a01cb522fb4ae05 /libbb | |
parent | 1a286d510c2125bdab601ce47afd4d27b6ce6f41 (diff) | |
parent | e329089c62ed813e97344f8c61d7dc34221fd5ee (diff) | |
download | busybox-w32-c31744ca1a86b2276c37c6d9a884660185debed6.tar.gz busybox-w32-c31744ca1a86b2276c37c6d9a884660185debed6.tar.bz2 busybox-w32-c31744ca1a86b2276c37c6d9a884660185debed6.zip |
Merge branch 'origin/master' (early part)
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Config.src | 2 | ||||
-rw-r--r-- | libbb/Kbuild.src | 2 | ||||
-rw-r--r-- | libbb/appletlib.c | 7 | ||||
-rw-r--r-- | libbb/xfuncs.c | 54 |
4 files changed, 43 insertions, 22 deletions
diff --git a/libbb/Config.src b/libbb/Config.src index a0aeb3683..80b1e0d21 100644 --- a/libbb/Config.src +++ b/libbb/Config.src | |||
@@ -5,6 +5,8 @@ | |||
5 | 5 | ||
6 | menu "Busybox Library Tuning" | 6 | menu "Busybox Library Tuning" |
7 | 7 | ||
8 | INSERT | ||
9 | |||
8 | config PASSWORD_MINLEN | 10 | config PASSWORD_MINLEN |
9 | int "Minimum password length" | 11 | int "Minimum password length" |
10 | default 6 | 12 | default 6 |
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index 9374feb17..2a50a1ae3 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src | |||
@@ -6,6 +6,8 @@ | |||
6 | 6 | ||
7 | lib-y:= | 7 | lib-y:= |
8 | 8 | ||
9 | INSERT | ||
10 | |||
9 | lib-y += appletlib.o | 11 | lib-y += appletlib.o |
10 | lib-y += ask_confirmation.o | 12 | lib-y += ask_confirmation.o |
11 | lib-y += bb_askpass.o | 13 | lib-y += bb_askpass.o |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index cb18a688e..922f7d26b 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -98,13 +98,6 @@ static const char *unpack_usage_messages(void) | |||
98 | #endif /* FEATURE_COMPRESS_USAGE */ | 98 | #endif /* FEATURE_COMPRESS_USAGE */ |
99 | 99 | ||
100 | 100 | ||
101 | static void full_write2_str(const char *str) | ||
102 | { | ||
103 | // This uses stdio: | ||
104 | //xwrite_str(STDERR_FILENO, str); | ||
105 | write(STDERR_FILENO, str, strlen(str)); | ||
106 | } | ||
107 | |||
108 | void FAST_FUNC bb_show_usage(void) | 101 | void FAST_FUNC bb_show_usage(void) |
109 | { | 102 | { |
110 | if (ENABLE_SHOW_USAGE) { | 103 | if (ENABLE_SHOW_USAGE) { |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 6200fc600..65437211d 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -49,23 +49,35 @@ char* FAST_FUNC strncpy_IFNAMSIZ(char *dst, const char *src) | |||
49 | } | 49 | } |
50 | 50 | ||
51 | 51 | ||
52 | // Convert unsigned integer to ascii, writing into supplied buffer. | 52 | /* Convert unsigned integer to ascii, writing into supplied buffer. |
53 | // A truncated result contains the first few digits of the result ala strncpy. | 53 | * A truncated result contains the first few digits of the result ala strncpy. |
54 | // Returns a pointer past last generated digit, does _not_ store NUL. | 54 | * Returns a pointer past last generated digit, does _not_ store NUL. |
55 | void BUG_sizeof_unsigned_not_4(void); | 55 | */ |
56 | void BUG_sizeof(void); | ||
56 | char* FAST_FUNC utoa_to_buf(unsigned n, char *buf, unsigned buflen) | 57 | char* FAST_FUNC utoa_to_buf(unsigned n, char *buf, unsigned buflen) |
57 | { | 58 | { |
58 | unsigned i, out, res; | 59 | unsigned i, out, res; |
59 | if (sizeof(unsigned) != 4) | 60 | |
60 | BUG_sizeof_unsigned_not_4(); | ||
61 | if (buflen) { | 61 | if (buflen) { |
62 | out = 0; | 62 | out = 0; |
63 | for (i = 1000000000; i; i /= 10) { | 63 | if (sizeof(n) == 4) |
64 | // 2^32-1 = 4294967295 | ||
65 | i = 1000000000; | ||
66 | #if UINT_MAX > 4294967295 /* prevents warning about "const too large" */ | ||
67 | else | ||
68 | if (sizeof(n) == 8) | ||
69 | // 2^64-1 = 18446744073709551615 | ||
70 | i = 10000000000000000000; | ||
71 | #endif | ||
72 | else | ||
73 | BUG_sizeof(); | ||
74 | for (; i; i /= 10) { | ||
64 | res = n / i; | 75 | res = n / i; |
76 | n = n % i; | ||
65 | if (res || out || i == 1) { | 77 | if (res || out || i == 1) { |
66 | if (!--buflen) break; | 78 | if (--buflen == 0) |
79 | break; | ||
67 | out++; | 80 | out++; |
68 | n -= res*i; | ||
69 | *buf++ = '0' + res; | 81 | *buf++ = '0' + res; |
70 | } | 82 | } |
71 | } | 83 | } |
@@ -76,7 +88,9 @@ char* FAST_FUNC utoa_to_buf(unsigned n, char *buf, unsigned buflen) | |||
76 | /* Convert signed integer to ascii, like utoa_to_buf() */ | 88 | /* Convert signed integer to ascii, like utoa_to_buf() */ |
77 | char* FAST_FUNC itoa_to_buf(int n, char *buf, unsigned buflen) | 89 | char* FAST_FUNC itoa_to_buf(int n, char *buf, unsigned buflen) |
78 | { | 90 | { |
79 | if (buflen && n < 0) { | 91 | if (!buflen) |
92 | return buf; | ||
93 | if (n < 0) { | ||
80 | n = -n; | 94 | n = -n; |
81 | *buf++ = '-'; | 95 | *buf++ = '-'; |
82 | buflen--; | 96 | buflen--; |
@@ -87,16 +101,16 @@ char* FAST_FUNC itoa_to_buf(int n, char *buf, unsigned buflen) | |||
87 | // The following two functions use a static buffer, so calling either one a | 101 | // The following two functions use a static buffer, so calling either one a |
88 | // second time will overwrite previous results. | 102 | // second time will overwrite previous results. |
89 | // | 103 | // |
90 | // The largest 32 bit integer is -2 billion plus null terminator, or 12 bytes. | 104 | // The largest 32 bit integer is -2 billion plus NUL, or 1+10+1=12 bytes. |
91 | // It so happens that sizeof(int) * 3 is enough for 32+ bits. | 105 | // It so happens that sizeof(int) * 3 is enough for 32+ bit ints. |
92 | // (sizeof(int) * 3 + 2 is correct for any width, even 8-bit) | 106 | // (sizeof(int) * 3 + 2 is correct for any width, even 8-bit) |
93 | 107 | ||
94 | static char local_buf[sizeof(int) * 3]; | 108 | static char local_buf[sizeof(int) * 3]; |
95 | 109 | ||
96 | // Convert unsigned integer to ascii using a static buffer (returned). | 110 | /* Convert unsigned integer to ascii using a static buffer (returned). */ |
97 | char* FAST_FUNC utoa(unsigned n) | 111 | char* FAST_FUNC utoa(unsigned n) |
98 | { | 112 | { |
99 | *(utoa_to_buf(n, local_buf, sizeof(local_buf))) = '\0'; | 113 | *(utoa_to_buf(n, local_buf, sizeof(local_buf) - 1)) = '\0'; |
100 | 114 | ||
101 | return local_buf; | 115 | return local_buf; |
102 | } | 116 | } |
@@ -104,7 +118,7 @@ char* FAST_FUNC utoa(unsigned n) | |||
104 | /* Convert signed integer to ascii using a static buffer (returned). */ | 118 | /* Convert signed integer to ascii using a static buffer (returned). */ |
105 | char* FAST_FUNC itoa(int n) | 119 | char* FAST_FUNC itoa(int n) |
106 | { | 120 | { |
107 | *(itoa_to_buf(n, local_buf, sizeof(local_buf))) = '\0'; | 121 | *(itoa_to_buf(n, local_buf, sizeof(local_buf) - 1)) = '\0'; |
108 | 122 | ||
109 | return local_buf; | 123 | return local_buf; |
110 | } | 124 | } |
@@ -204,6 +218,16 @@ int FAST_FUNC bb_putchar_stderr(char ch) | |||
204 | return write(STDERR_FILENO, &ch, 1); | 218 | return write(STDERR_FILENO, &ch, 1); |
205 | } | 219 | } |
206 | 220 | ||
221 | ssize_t FAST_FUNC full_write1_str(const char *str) | ||
222 | { | ||
223 | return full_write(STDOUT_FILENO, str, strlen(str)); | ||
224 | } | ||
225 | |||
226 | ssize_t FAST_FUNC full_write2_str(const char *str) | ||
227 | { | ||
228 | return full_write(STDERR_FILENO, str, strlen(str)); | ||
229 | } | ||
230 | |||
207 | static int wh_helper(int value, int def_val, const char *env_name, int *err) | 231 | static int wh_helper(int value, int def_val, const char *env_name, int *err) |
208 | { | 232 | { |
209 | if (value == 0) { | 233 | if (value == 0) { |