diff options
author | Ron Yorston <rmy@pobox.com> | 2018-07-25 10:41:42 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-07-25 10:41:42 +0100 |
commit | 59873514f17cefd6ba3997dad5779f75433fd4e6 (patch) | |
tree | 1c9d0a3450ed95f0b820285b9f9fc217c902e652 /coreutils | |
parent | 779fd5745ac11bf752f5f4b977a274a39c192f90 (diff) | |
parent | 81de30de05beebabfa72f2a01ec4f33e9a1923e3 (diff) | |
download | busybox-w32-59873514f17cefd6ba3997dad5779f75433fd4e6.tar.gz busybox-w32-59873514f17cefd6ba3997dad5779f75433fd4e6.tar.bz2 busybox-w32-59873514f17cefd6ba3997dad5779f75433fd4e6.zip |
Merge branch 'busybox'
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/Config.src | 2 | ||||
-rw-r--r-- | coreutils/cp.c | 24 | ||||
-rw-r--r-- | coreutils/install.c | 6 | ||||
-rw-r--r-- | coreutils/nproc.c | 44 | ||||
-rw-r--r-- | coreutils/readlink.c | 2 | ||||
-rw-r--r-- | coreutils/realpath.c | 2 | ||||
-rw-r--r-- | coreutils/sort.c | 47 |
7 files changed, 93 insertions, 34 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src index 7a8a3a634..1bded03a6 100644 --- a/coreutils/Config.src +++ b/coreutils/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 | ||
6 | menu "Coreutils" | 6 | menu "Coreutils" |
diff --git a/coreutils/cp.c b/coreutils/cp.c index 455bffbba..ae60623d3 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c | |||
@@ -24,6 +24,11 @@ | |||
24 | //config: help | 24 | //config: help |
25 | //config: Enable long options. | 25 | //config: Enable long options. |
26 | //config: Also add support for --parents option. | 26 | //config: Also add support for --parents option. |
27 | //config: | ||
28 | //config:config FEATURE_CP_REFLINK | ||
29 | //config: bool "Enable --reflink[=auto]" | ||
30 | //config: default y | ||
31 | //config: depends on FEATURE_CP_LONG_OPTIONS | ||
27 | 32 | ||
28 | //applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) | 33 | //applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) |
29 | /* NOEXEC despite cases when it can be a "runner" (cp -r LARGE_DIR NEW_DIR) */ | 34 | /* NOEXEC despite cases when it can be a "runner" (cp -r LARGE_DIR NEW_DIR) */ |
@@ -72,10 +77,14 @@ int cp_main(int argc, char **argv) | |||
72 | #if ENABLE_FEATURE_CP_LONG_OPTIONS | 77 | #if ENABLE_FEATURE_CP_LONG_OPTIONS |
73 | /*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */ | 78 | /*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */ |
74 | OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1), | 79 | OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1), |
80 | OPT_reflink = 1 << (FILEUTILS_CP_OPTNUM+2), | ||
75 | #endif | 81 | #endif |
76 | }; | 82 | }; |
77 | 83 | ||
78 | #if ENABLE_FEATURE_CP_LONG_OPTIONS | 84 | #if ENABLE_FEATURE_CP_LONG_OPTIONS |
85 | # if ENABLE_FEATURE_CP_REFLINK | ||
86 | char *reflink = NULL; | ||
87 | # endif | ||
79 | flags = getopt32long(argv, "^" | 88 | flags = getopt32long(argv, "^" |
80 | FILEUTILS_CP_OPTSTR | 89 | FILEUTILS_CP_OPTSTR |
81 | "\0" | 90 | "\0" |
@@ -99,7 +108,22 @@ int cp_main(int argc, char **argv) | |||
99 | "update\0" No_argument "u" | 108 | "update\0" No_argument "u" |
100 | "remove-destination\0" No_argument "\xff" | 109 | "remove-destination\0" No_argument "\xff" |
101 | "parents\0" No_argument "\xfe" | 110 | "parents\0" No_argument "\xfe" |
111 | # if ENABLE_FEATURE_CP_REFLINK | ||
112 | "reflink\0" Optional_argument "\xfd" | ||
113 | , &reflink | ||
114 | # endif | ||
102 | ); | 115 | ); |
116 | # if ENABLE_FEATURE_CP_REFLINK | ||
117 | BUILD_BUG_ON(OPT_reflink != FILEUTILS_REFLINK); | ||
118 | if (flags & FILEUTILS_REFLINK) { | ||
119 | if (!reflink) | ||
120 | flags |= FILEUTILS_REFLINK_ALWAYS; | ||
121 | else if (strcmp(reflink, "always") == 0) | ||
122 | flags |= FILEUTILS_REFLINK_ALWAYS; | ||
123 | else if (strcmp(reflink, "auto") != 0) | ||
124 | bb_show_usage(); | ||
125 | } | ||
126 | # endif | ||
103 | #else | 127 | #else |
104 | flags = getopt32(argv, "^" | 128 | flags = getopt32(argv, "^" |
105 | FILEUTILS_CP_OPTSTR | 129 | FILEUTILS_CP_OPTSTR |
diff --git a/coreutils/install.c b/coreutils/install.c index 2e4dc257f..8270490bd 100644 --- a/coreutils/install.c +++ b/coreutils/install.c | |||
@@ -214,7 +214,11 @@ int install_main(int argc, char **argv) | |||
214 | dest = last; | 214 | dest = last; |
215 | if (opts & OPT_MKDIR_LEADING) { | 215 | if (opts & OPT_MKDIR_LEADING) { |
216 | char *ddir = xstrdup(dest); | 216 | char *ddir = xstrdup(dest); |
217 | bb_make_directory(dirname(ddir), 0755, mkdir_flags); | 217 | /* |
218 | * -D -t DIR1/DIR2/F3 FILE: create DIR1/DIR2/F3, copy FILE there | ||
219 | * -D FILE DIR1/DIR2/F3: create DIR1/DIR2, copy FILE there as F3 | ||
220 | */ | ||
221 | bb_make_directory((opts & OPT_TARGET) ? ddir : dirname(ddir), 0755, mkdir_flags); | ||
218 | /* errors are not checked. copy_file | 222 | /* errors are not checked. copy_file |
219 | * will fail if dir is not created. | 223 | * will fail if dir is not created. |
220 | */ | 224 | */ |
diff --git a/coreutils/nproc.c b/coreutils/nproc.c index 336b176ca..0ea8d1001 100644 --- a/coreutils/nproc.c +++ b/coreutils/nproc.c | |||
@@ -14,10 +14,14 @@ | |||
14 | //kbuild:lib-$(CONFIG_NPROC) += nproc.o | 14 | //kbuild:lib-$(CONFIG_NPROC) += nproc.o |
15 | 15 | ||
16 | //usage:#define nproc_trivial_usage | 16 | //usage:#define nproc_trivial_usage |
17 | //usage: "" | 17 | //usage: ""IF_LONG_OPTS("--all --ignore=N") |
18 | //TODO: "[--all] [--ignore=N]" | ||
19 | //usage:#define nproc_full_usage "\n\n" | 18 | //usage:#define nproc_full_usage "\n\n" |
20 | //usage: "Print number of CPUs" | 19 | //usage: "Print number of available CPUs" |
20 | //usage: IF_LONG_OPTS( | ||
21 | //usage: "\n" | ||
22 | //usage: "\n --all Number of installed CPUs" | ||
23 | //usage: "\n --ignore=N Exclude N CPUs" | ||
24 | //usage: ) | ||
21 | 25 | ||
22 | #include <sched.h> | 26 | #include <sched.h> |
23 | #include "libbb.h" | 27 | #include "libbb.h" |
@@ -26,13 +30,30 @@ int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
26 | int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 30 | int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
27 | { | 31 | { |
28 | unsigned long mask[1024]; | 32 | unsigned long mask[1024]; |
29 | unsigned i, count = 0; | 33 | int count = 0; |
30 | 34 | #if ENABLE_LONG_OPTS | |
31 | //getopt32(argv, ""); | 35 | int ignore = 0; |
32 | 36 | int opts = getopt32long(argv, "\xfe:+", | |
33 | //if --all, count /sys/devices/system/cpu/cpuN dirs, else: | 37 | "ignore\0" Required_argument "\xfe" |
38 | "all\0" No_argument "\xff" | ||
39 | , &ignore | ||
40 | ); | ||
34 | 41 | ||
42 | if (opts & (1 << 1)) { | ||
43 | DIR *cpusd = opendir("/sys/devices/system/cpu"); | ||
44 | if (cpusd) { | ||
45 | struct dirent *de; | ||
46 | while (NULL != (de = readdir(cpusd))) { | ||
47 | char *cpuid = strstr(de->d_name, "cpu"); | ||
48 | if (cpuid && isdigit(cpuid[strlen(cpuid) - 1])) | ||
49 | count++; | ||
50 | } | ||
51 | closedir(cpusd); | ||
52 | } | ||
53 | } else | ||
54 | #endif | ||
35 | if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) { | 55 | if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) { |
56 | int i; | ||
36 | for (i = 0; i < ARRAY_SIZE(mask); i++) { | 57 | for (i = 0; i < ARRAY_SIZE(mask); i++) { |
37 | unsigned long m = mask[i]; | 58 | unsigned long m = mask[i]; |
38 | while (m) { | 59 | while (m) { |
@@ -42,8 +63,11 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
42 | } | 63 | } |
43 | } | 64 | } |
44 | } | 65 | } |
45 | if (count == 0) | 66 | |
46 | count++; | 67 | IF_LONG_OPTS(count -= ignore;) |
68 | if (count <= 0) | ||
69 | count = 1; | ||
70 | |||
47 | printf("%u\n", count); | 71 | printf("%u\n", count); |
48 | 72 | ||
49 | return 0; | 73 | return 0; |
diff --git a/coreutils/readlink.c b/coreutils/readlink.c index b8e327d11..49361cea0 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c | |||
@@ -86,7 +86,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) | |||
86 | 86 | ||
87 | /* NOFORK: only one alloc is allowed; must free */ | 87 | /* NOFORK: only one alloc is allowed; must free */ |
88 | if (opt & 1) { /* -f */ | 88 | if (opt & 1) { /* -f */ |
89 | buf = xmalloc_realpath(fname); | 89 | buf = xmalloc_realpath_coreutils(fname); |
90 | } else { | 90 | } else { |
91 | buf = xmalloc_readlink_or_warn(fname); | 91 | buf = xmalloc_readlink_or_warn(fname); |
92 | } | 92 | } |
diff --git a/coreutils/realpath.c b/coreutils/realpath.c index aa878fcd2..43923681c 100644 --- a/coreutils/realpath.c +++ b/coreutils/realpath.c | |||
@@ -38,7 +38,7 @@ int realpath_main(int argc UNUSED_PARAM, char **argv) | |||
38 | 38 | ||
39 | do { | 39 | do { |
40 | /* NOFORK: only one alloc is allowed; must free */ | 40 | /* NOFORK: only one alloc is allowed; must free */ |
41 | char *resolved_path = xmalloc_realpath(*argv); | 41 | char *resolved_path = xmalloc_realpath_coreutils(*argv); |
42 | if (resolved_path != NULL) { | 42 | if (resolved_path != NULL) { |
43 | puts(resolved_path); | 43 | puts(resolved_path); |
44 | free(resolved_path); | 44 | free(resolved_path); |
diff --git a/coreutils/sort.c b/coreutils/sort.c index 4d741e76d..05e5c9071 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -60,6 +60,7 @@ | |||
60 | //usage: IF_FEATURE_SORT_BIG( | 60 | //usage: IF_FEATURE_SORT_BIG( |
61 | //usage: "\n -g General numerical sort" | 61 | //usage: "\n -g General numerical sort" |
62 | //usage: "\n -M Sort month" | 62 | //usage: "\n -M Sort month" |
63 | //usage: "\n -V Sort version" | ||
63 | //usage: "\n -t CHAR Field separator" | 64 | //usage: "\n -t CHAR Field separator" |
64 | //usage: "\n -k N[,M] Sort by Nth field" | 65 | //usage: "\n -k N[,M] Sort by Nth field" |
65 | //usage: ) | 66 | //usage: ) |
@@ -91,32 +92,33 @@ | |||
91 | 92 | ||
92 | /* These are sort types */ | 93 | /* These are sort types */ |
93 | enum { | 94 | enum { |
94 | FLAG_n = 1, /* Numeric sort */ | 95 | FLAG_n = 1 << 0, /* Numeric sort */ |
95 | FLAG_g = 2, /* Sort using strtod() */ | 96 | FLAG_g = 1 << 1, /* Sort using strtod() */ |
96 | FLAG_M = 4, /* Sort date */ | 97 | FLAG_M = 1 << 2, /* Sort date */ |
98 | FLAG_V = 1 << 3, /* Sort version */ | ||
97 | /* ucsz apply to root level only, not keys. b at root level implies bb */ | 99 | /* ucsz apply to root level only, not keys. b at root level implies bb */ |
98 | FLAG_u = 8, /* Unique */ | 100 | FLAG_u = 1 << 4, /* Unique */ |
99 | FLAG_c = 0x10, /* Check: no output, exit(!ordered) */ | 101 | FLAG_c = 1 << 5, /* Check: no output, exit(!ordered) */ |
100 | FLAG_s = 0x20, /* Stable sort, no ascii fallback at end */ | 102 | FLAG_s = 1 << 6, /* Stable sort, no ascii fallback at end */ |
101 | FLAG_z = 0x40, /* Input and output is NUL terminated, not \n */ | 103 | FLAG_z = 1 << 7, /* Input and output is NUL terminated, not \n */ |
102 | /* These can be applied to search keys, the previous four can't */ | 104 | /* These can be applied to search keys, the previous four can't */ |
103 | FLAG_b = 0x80, /* Ignore leading blanks */ | 105 | FLAG_b = 1 << 8, /* Ignore leading blanks */ |
104 | FLAG_r = 0x100, /* Reverse */ | 106 | FLAG_r = 1 << 9, /* Reverse */ |
105 | FLAG_d = 0x200, /* Ignore !(isalnum()|isspace()) */ | 107 | FLAG_d = 1 << 10, /* Ignore !(isalnum()|isspace()) */ |
106 | FLAG_f = 0x400, /* Force uppercase */ | 108 | FLAG_f = 1 << 11, /* Force uppercase */ |
107 | FLAG_i = 0x800, /* Ignore !isprint() */ | 109 | FLAG_i = 1 << 12, /* Ignore !isprint() */ |
108 | FLAG_m = 0x1000, /* ignored: merge already sorted files; do not sort */ | 110 | FLAG_m = 1 << 13, /* ignored: merge already sorted files; do not sort */ |
109 | FLAG_S = 0x2000, /* ignored: -S, --buffer-size=SIZE */ | 111 | FLAG_S = 1 << 14, /* ignored: -S, --buffer-size=SIZE */ |
110 | FLAG_T = 0x4000, /* ignored: -T, --temporary-directory=DIR */ | 112 | FLAG_T = 1 << 15, /* ignored: -T, --temporary-directory=DIR */ |
111 | FLAG_o = 0x8000, | 113 | FLAG_o = 1 << 16, |
112 | FLAG_k = 0x10000, | 114 | FLAG_k = 1 << 17, |
113 | FLAG_t = 0x20000, | 115 | FLAG_t = 1 << 18, |
114 | FLAG_bb = 0x80000000, /* Ignore trailing blanks */ | 116 | FLAG_bb = 0x80000000, /* Ignore trailing blanks */ |
115 | FLAG_no_tie_break = 0x40000000, | 117 | FLAG_no_tie_break = 0x40000000, |
116 | }; | 118 | }; |
117 | 119 | ||
118 | static const char sort_opt_str[] ALIGN1 = "^" | 120 | static const char sort_opt_str[] ALIGN1 = "^" |
119 | "ngMucszbrdfimS:T:o:k:*t:" | 121 | "ngMVucszbrdfimS:T:o:k:*t:" |
120 | "\0" "o--o:t--t"/*-t, -o: at most one of each*/; | 122 | "\0" "o--o:t--t"/*-t, -o: at most one of each*/; |
121 | /* | 123 | /* |
122 | * OPT_STR must not be string literal, needs to have stable address: | 124 | * OPT_STR must not be string literal, needs to have stable address: |
@@ -273,10 +275,15 @@ static int compare_keys(const void *xarg, const void *yarg) | |||
273 | y = *(char **)yarg; | 275 | y = *(char **)yarg; |
274 | #endif | 276 | #endif |
275 | /* Perform actual comparison */ | 277 | /* Perform actual comparison */ |
276 | switch (flags & (FLAG_n | FLAG_M | FLAG_g)) { | 278 | switch (flags & (FLAG_n | FLAG_g | FLAG_M | FLAG_V)) { |
277 | default: | 279 | default: |
278 | bb_error_msg_and_die("unknown sort type"); | 280 | bb_error_msg_and_die("unknown sort type"); |
279 | break; | 281 | break; |
282 | #if defined(HAVE_STRVERSCMP) && HAVE_STRVERSCMP == 1 | ||
283 | case FLAG_V: | ||
284 | retval = strverscmp(x, y); | ||
285 | break; | ||
286 | #endif | ||
280 | /* Ascii sort */ | 287 | /* Ascii sort */ |
281 | case 0: | 288 | case 0: |
282 | #if ENABLE_LOCALE_SUPPORT | 289 | #if ENABLE_LOCALE_SUPPORT |