aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-01-08 12:30:49 +0000
committerRon Yorston <rmy@pobox.com>2020-01-08 12:30:49 +0000
commita9271a8e97e6e7be5285330d5f19352decabf807 (patch)
treebf3c4464c369a15a46454792dac167505f74769f /libbb
parentb0b7ab792bc1f45963f4b84b94faaf05054e1613 (diff)
parent9ec836c033fc6e55e80f3309b3e05acdf09bb297 (diff)
downloadbusybox-w32-a9271a8e97e6e7be5285330d5f19352decabf807.tar.gz
busybox-w32-a9271a8e97e6e7be5285330d5f19352decabf807.tar.bz2
busybox-w32-a9271a8e97e6e7be5285330d5f19352decabf807.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c2
-rw-r--r--libbb/copyfd.c13
-rw-r--r--libbb/lineedit.c2
-rw-r--r--libbb/missing_syscalls.c8
-rw-r--r--libbb/read.c12
-rw-r--r--libbb/read_key.c3
-rw-r--r--libbb/replace.c4
-rw-r--r--libbb/time.c4
8 files changed, 27 insertions, 21 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index f7971daf4..17ce463ea 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -319,7 +319,7 @@ void lbb_prepare(const char *applet
319 IF_FEATURE_INDIVIDUAL(, char **argv)) 319 IF_FEATURE_INDIVIDUAL(, char **argv))
320{ 320{
321#ifdef __GLIBC__ 321#ifdef __GLIBC__
322 (*(int **)&bb_errno) = __errno_location(); 322 (*(int **)not_const_pp(&bb_errno)) = __errno_location();
323 barrier(); 323 barrier();
324#endif 324#endif
325 applet_name = applet; 325 applet_name = applet;
diff --git a/libbb/copyfd.c b/libbb/copyfd.c
index ae5c26999..d41fd10f0 100644
--- a/libbb/copyfd.c
+++ b/libbb/copyfd.c
@@ -18,7 +18,7 @@
18 * was seen to cause largish delays when user tries to ^C a file copy. 18 * was seen to cause largish delays when user tries to ^C a file copy.
19 * Let's use a saner size. 19 * Let's use a saner size.
20 * Note: needs to be >= max(CONFIG_FEATURE_COPYBUF_KB), 20 * Note: needs to be >= max(CONFIG_FEATURE_COPYBUF_KB),
21 * or else "copy to eof" code will use neddlesly short reads. 21 * or else "copy to eof" code will use needlesly short reads.
22 */ 22 */
23#define SENDFILE_BIGBUF (16*1024*1024) 23#define SENDFILE_BIGBUF (16*1024*1024)
24 24
@@ -60,10 +60,13 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
60 ssize_t rd; 60 ssize_t rd;
61 61
62 if (sendfile_sz) { 62 if (sendfile_sz) {
63 rd = sendfile(dst_fd, src_fd, NULL, 63 /* dst_fd == -1 is a fake, else... */
64 size > sendfile_sz ? sendfile_sz : size); 64 if (dst_fd >= 0) {
65 if (rd >= 0) 65 rd = sendfile(dst_fd, src_fd, NULL,
66 goto read_ok; 66 size > sendfile_sz ? sendfile_sz : size);
67 if (rd >= 0)
68 goto read_ok;
69 }
67 sendfile_sz = 0; /* do not try sendfile anymore */ 70 sendfile_sz = 0; /* do not try sendfile anymore */
68 } 71 }
69#if CONFIG_FEATURE_COPYBUF_KB > 4 72#if CONFIG_FEATURE_COPYBUF_KB > 4
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 9781b4a08..9bb3ea98b 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -203,7 +203,7 @@ extern struct lineedit_statics *const lineedit_ptr_to_statics;
203#define delbuf (S.delbuf ) 203#define delbuf (S.delbuf )
204 204
205#define INIT_S() do { \ 205#define INIT_S() do { \
206 (*(struct lineedit_statics**)&lineedit_ptr_to_statics) = xzalloc(sizeof(S)); \ 206 (*(struct lineedit_statics**)not_const_pp(&lineedit_ptr_to_statics)) = xzalloc(sizeof(S)); \
207 barrier(); \ 207 barrier(); \
208 cmdedit_termw = 80; \ 208 cmdedit_termw = 80; \
209 IF_USERNAME_OR_HOMEDIR(home_pwd_buf = (char*)null_str;) \ 209 IF_USERNAME_OR_HOMEDIR(home_pwd_buf = (char*)null_str;) \
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
index 87cf59b3d..dc40d9155 100644
--- a/libbb/missing_syscalls.c
+++ b/libbb/missing_syscalls.c
@@ -15,14 +15,6 @@ pid_t getsid(pid_t pid)
15 return syscall(__NR_getsid, pid); 15 return syscall(__NR_getsid, pid);
16} 16}
17 17
18int stime(const time_t *t)
19{
20 struct timeval tv;
21 tv.tv_sec = *t;
22 tv.tv_usec = 0;
23 return settimeofday(&tv, NULL);
24}
25
26int sethostname(const char *name, size_t len) 18int sethostname(const char *name, size_t len)
27{ 19{
28 return syscall(__NR_sethostname, name, len); 20 return syscall(__NR_sethostname, name, len);
diff --git a/libbb/read.c b/libbb/read.c
index 5906bc225..a342506a8 100644
--- a/libbb/read.c
+++ b/libbb/read.c
@@ -12,9 +12,17 @@ ssize_t FAST_FUNC safe_read(int fd, void *buf, size_t count)
12{ 12{
13 ssize_t n; 13 ssize_t n;
14 14
15 do { 15 for (;;) {
16 n = read(fd, buf, count); 16 n = read(fd, buf, count);
17 } while (n < 0 && errno == EINTR); 17 if (n >= 0 || errno != EINTR)
18 break;
19 /* Some callers set errno=0, are upset when they see EINTR.
20 * Returning EINTR is wrong since we retry read(),
21 * the "error" was transient.
22 */
23 errno = 0;
24 /* repeat the read() */
25 }
18 26
19 return n; 27 return n;
20} 28}
diff --git a/libbb/read_key.c b/libbb/read_key.c
index 951786869..03b7da656 100644
--- a/libbb/read_key.c
+++ b/libbb/read_key.c
@@ -259,7 +259,8 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout)
259 259
260 buffer[-1] = 0; 260 buffer[-1] = 0;
261 /* Pack into "1 <row15bits> <col16bits>" 32-bit sequence */ 261 /* Pack into "1 <row15bits> <col16bits>" 32-bit sequence */
262 col |= (((-1 << 15) | row) << 16); 262 row |= ((unsigned)(-1) << 15);
263 col |= (row << 16);
263 /* Return it in high-order word */ 264 /* Return it in high-order word */
264 return ((int64_t) col << 32) | (uint32_t)KEYCODE_CURSOR_POS; 265 return ((int64_t) col << 32) | (uint32_t)KEYCODE_CURSOR_POS;
265 } 266 }
diff --git a/libbb/replace.c b/libbb/replace.c
index a661d96e6..6183d3e6f 100644
--- a/libbb/replace.c
+++ b/libbb/replace.c
@@ -15,6 +15,10 @@ unsigned FAST_FUNC count_strstr(const char *str, const char *sub)
15 size_t sub_len = strlen(sub); 15 size_t sub_len = strlen(sub);
16 unsigned count = 0; 16 unsigned count = 0;
17 17
18 /* If sub is empty, avoid an infinite loop */
19 if (sub_len == 0)
20 return strlen(str) + 1;
21
18 while ((str = strstr(str, sub)) != NULL) { 22 while ((str = strstr(str, sub)) != NULL) {
19 count++; 23 count++;
20 str += sub_len; 24 str += sub_len;
diff --git a/libbb/time.c b/libbb/time.c
index cab0ad602..e66a9cba8 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -253,11 +253,9 @@ char* FAST_FUNC strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp)
253#define CLOCK_MONOTONIC 1 253#define CLOCK_MONOTONIC 1
254#endif 254#endif
255 255
256/* libc has incredibly messy way of doing this,
257 * typically requiring -lrt. We just skip all this mess */
258static void get_mono(struct timespec *ts) 256static void get_mono(struct timespec *ts)
259{ 257{
260 if (syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts)) 258 if (clock_gettime(CLOCK_MONOTONIC, ts))
261 bb_simple_error_msg_and_die("clock_gettime(MONOTONIC) failed"); 259 bb_simple_error_msg_and_die("clock_gettime(MONOTONIC) failed");
262} 260}
263unsigned long long FAST_FUNC monotonic_ns(void) 261unsigned long long FAST_FUNC monotonic_ns(void)