aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-07-25 10:41:42 +0100
committerRon Yorston <rmy@pobox.com>2018-07-25 10:41:42 +0100
commit59873514f17cefd6ba3997dad5779f75433fd4e6 (patch)
tree1c9d0a3450ed95f0b820285b9f9fc217c902e652 /libbb
parent779fd5745ac11bf752f5f4b977a274a39c192f90 (diff)
parent81de30de05beebabfa72f2a01ec4f33e9a1923e3 (diff)
downloadbusybox-w32-59873514f17cefd6ba3997dad5779f75433fd4e6.tar.gz
busybox-w32-59873514f17cefd6ba3997dad5779f75433fd4e6.tar.bz2
busybox-w32-59873514f17cefd6ba3997dad5779f75433fd4e6.zip
Merge branch 'busybox'
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Config.src2
-rw-r--r--libbb/appletlib.c9
-rw-r--r--libbb/copy_file.c19
-rw-r--r--libbb/dump.c14
-rw-r--r--libbb/loop.c4
-rw-r--r--libbb/nuke_str.c2
-rw-r--r--libbb/pw_encrypt.c1
-rw-r--r--libbb/xfuncs_printf.c1
-rw-r--r--libbb/xreadlink.c30
9 files changed, 72 insertions, 10 deletions
diff --git a/libbb/Config.src b/libbb/Config.src
index 16e16480b..312aa1831 100644
--- a/libbb/Config.src
+++ b/libbb/Config.src
@@ -1,6 +1,6 @@
1# 1#
2# For a description of the syntax of this configuration file, 2# For a description of the syntax of this configuration file,
3# see scripts/kbuild/config-language.txt. 3# see docs/Kconfig-language.txt.
4# 4#
5 5
6comment "Library Tuning" 6comment "Library Tuning"
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index f250264d9..7df75c665 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -177,8 +177,11 @@ void FAST_FUNC bb_show_usage(void)
177 else { 177 else {
178 full_write2_str("\nUsage: "); 178 full_write2_str("\nUsage: ");
179 full_write2_str(applet_name); 179 full_write2_str(applet_name);
180 full_write2_str(" "); 180 if (p[0]) {
181 full_write2_str(p); 181 if (p[0] != '\n')
182 full_write2_str(" ");
183 full_write2_str(p);
184 }
182 full_write2_str("\n"); 185 full_write2_str("\n");
183 } 186 }
184 if (ENABLE_FEATURE_CLEAN_UP) 187 if (ENABLE_FEATURE_CLEAN_UP)
@@ -747,7 +750,7 @@ static void install_links(const char *busybox, int use_symbolic_links,
747 * busybox.h::bb_install_loc_t, or else... */ 750 * busybox.h::bb_install_loc_t, or else... */
748 int (*lf)(const char *, const char *); 751 int (*lf)(const char *, const char *);
749 char *fpc; 752 char *fpc;
750 const char *appname = applet_names; 753 const char *appname = applet_names;
751 unsigned i; 754 unsigned i;
752 int rc; 755 int rc;
753 756
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index c60765d95..7cd9cd978 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -343,8 +343,27 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
343 } 343 }
344 } 344 }
345#endif 345#endif
346#if ENABLE_FEATURE_CP_REFLINK
347# undef BTRFS_IOCTL_MAGIC
348# define BTRFS_IOCTL_MAGIC 0x94
349# undef BTRFS_IOC_CLONE
350# define BTRFS_IOC_CLONE _IOW (BTRFS_IOCTL_MAGIC, 9, int)
351 if (flags & FILEUTILS_REFLINK) {
352 retval = ioctl(dst_fd, BTRFS_IOC_CLONE, src_fd);
353 if (retval == 0)
354 goto do_close;
355 /* reflink did not work */
356 if (flags & FILEUTILS_REFLINK_ALWAYS) {
357 bb_perror_msg("failed to clone '%s' from '%s'", dest, source);
358 goto do_close;
359 }
360 /* fall through to standard copy */
361 retval = 0;
362 }
363#endif
346 if (bb_copyfd_eof(src_fd, dst_fd) == -1) 364 if (bb_copyfd_eof(src_fd, dst_fd) == -1)
347 retval = -1; 365 retval = -1;
366 IF_FEATURE_CP_REFLINK(do_close:)
348 /* Careful with writing... */ 367 /* Careful with writing... */
349 if (close(dst_fd) < 0) { 368 if (close(dst_fd) < 0) {
350 bb_perror_msg("error writing to '%s'", dest); 369 bb_perror_msg("error writing to '%s'", dest);
diff --git a/libbb/dump.c b/libbb/dump.c
index 5941ef902..b4b49d709 100644
--- a/libbb/dump.c
+++ b/libbb/dump.c
@@ -387,7 +387,10 @@ static unsigned char *get(priv_dumper_t *dumper)
387 if (need == blocksize) { 387 if (need == blocksize) {
388 return NULL; 388 return NULL;
389 } 389 }
390 if (dumper->pub.dump_vflag != ALL && !memcmp(dumper->get__curp, dumper->get__savp, nread)) { 390 if (dumper->pub.dump_vflag != ALL /* not "show all"? */
391 && dumper->pub.dump_vflag != FIRST /* not first line? */
392 && memcmp(dumper->get__curp, dumper->get__savp, nread) == 0 /* same data? */
393 ) {
391 if (dumper->pub.dump_vflag != DUP) { 394 if (dumper->pub.dump_vflag != DUP) {
392 puts("*"); 395 puts("*");
393 } 396 }
@@ -399,7 +402,7 @@ static unsigned char *get(priv_dumper_t *dumper)
399 } 402 }
400 n = fread(dumper->get__curp + nread, sizeof(unsigned char), 403 n = fread(dumper->get__curp + nread, sizeof(unsigned char),
401 dumper->pub.dump_length == -1 ? need : MIN(dumper->pub.dump_length, need), stdin); 404 dumper->pub.dump_length == -1 ? need : MIN(dumper->pub.dump_length, need), stdin);
402 if (!n) { 405 if (n == 0) {
403 if (ferror(stdin)) { 406 if (ferror(stdin)) {
404 bb_simple_perror_msg(dumper->argv[-1]); 407 bb_simple_perror_msg(dumper->argv[-1]);
405 } 408 }
@@ -411,9 +414,10 @@ static unsigned char *get(priv_dumper_t *dumper)
411 dumper->pub.dump_length -= n; 414 dumper->pub.dump_length -= n;
412 } 415 }
413 need -= n; 416 need -= n;
414 if (!need) { 417 if (need == 0) {
415 if (dumper->pub.dump_vflag == ALL || dumper->pub.dump_vflag == FIRST 418 if (dumper->pub.dump_vflag == ALL /* "show all"? */
416 || memcmp(dumper->get__curp, dumper->get__savp, blocksize) 419 || dumper->pub.dump_vflag == FIRST /* first line? */
420 || memcmp(dumper->get__curp, dumper->get__savp, blocksize) != 0 /* not same data? */
417 ) { 421 ) {
418 if (dumper->pub.dump_vflag == DUP || dumper->pub.dump_vflag == FIRST) { 422 if (dumper->pub.dump_vflag == DUP || dumper->pub.dump_vflag == FIRST) {
419 dumper->pub.dump_vflag = WAIT; 423 dumper->pub.dump_vflag = WAIT;
diff --git a/libbb/loop.c b/libbb/loop.c
index f0d4296ae..c78535a20 100644
--- a/libbb/loop.c
+++ b/libbb/loop.c
@@ -106,6 +106,10 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
106 return -errno; 106 return -errno;
107 } 107 }
108 108
109//TODO: use LOOP_CTL_GET_FREE instead of trying every loopN in sequence? a-la:
110// fd = open("/dev/loop-control", O_RDWR);
111// loopN = ioctl(fd, LOOP_CTL_GET_FREE);
112//
109 /* Find a loop device. */ 113 /* Find a loop device. */
110 try = *device ? *device : dev; 114 try = *device ? *device : dev;
111 /* 1048575 (0xfffff) is a max possible minor number in Linux circa 2010 */ 115 /* 1048575 (0xfffff) is a max possible minor number in Linux circa 2010 */
diff --git a/libbb/nuke_str.c b/libbb/nuke_str.c
index 240e68004..b5385e956 100644
--- a/libbb/nuke_str.c
+++ b/libbb/nuke_str.c
@@ -12,7 +12,7 @@
12 12
13void FAST_FUNC nuke_str(char *str) 13void FAST_FUNC nuke_str(char *str)
14{ 14{
15 if (str) { 15 if (str) {
16 while (*str) 16 while (*str)
17 *str++ = 0; 17 *str++ = 0;
18 /* or: memset(str, 0, strlen(str)); - not as small as above */ 18 /* or: memset(str, 0, strlen(str)); - not as small as above */
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c
index 1edf4b6f0..86455cd0d 100644
--- a/libbb/pw_encrypt.c
+++ b/libbb/pw_encrypt.c
@@ -6,6 +6,7 @@
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */ 8 */
9#include <crypt.h>
9#include "libbb.h" 10#include "libbb.h"
10 11
11/* static const uint8_t ascii64[] ALIGN1 = 12/* static const uint8_t ascii64[] ALIGN1 =
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index 21263ccfe..a0db2b86e 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -222,6 +222,7 @@ void FAST_FUNC xdup2(int from, int to)
222{ 222{
223 if (dup2(from, to) != to) 223 if (dup2(from, to) != to)
224 bb_perror_msg_and_die("can't duplicate file descriptor"); 224 bb_perror_msg_and_die("can't duplicate file descriptor");
225 // " %d to %d", from, to);
225} 226}
226 227
227// "Renumber" opened fd 228// "Renumber" opened fd
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
index b3118b433..9ae70de99 100644
--- a/libbb/xreadlink.c
+++ b/libbb/xreadlink.c
@@ -122,3 +122,33 @@ char* FAST_FUNC xmalloc_realpath(const char *path)
122 return xstrdup(realpath(path, buf)); 122 return xstrdup(realpath(path, buf));
123#endif 123#endif
124} 124}
125
126char* FAST_FUNC xmalloc_realpath_coreutils(const char *path)
127{
128 char *buf;
129
130 errno = 0;
131 buf = xmalloc_realpath(path);
132 /*
133 * There is one case when "readlink -f" and
134 * "realpath" from coreutils succeed,
135 * even though file does not exist, such as:
136 * /tmp/file_does_not_exist
137 * (the directory must exist).
138 */
139 if (!buf && errno == ENOENT) {
140 char *last_slash = strrchr(path, '/');
141 if (last_slash) {
142 *last_slash++ = '\0';
143 buf = xmalloc_realpath(path);
144 if (buf) {
145 unsigned len = strlen(buf);
146 buf = xrealloc(buf, len + strlen(last_slash) + 2);
147 buf[len++] = '/';
148 strcpy(buf + len, last_slash);
149 }
150 }
151 }
152
153 return buf;
154}