Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (9 years ago)
- Location:
- branches/3.3
- Files:
-
- 4 added
- 1 deleted
- 49 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/coreutils/Config.src
r3232 r3621 12 12 default y 13 13 help 14 cal is used to display a monthly calend er.14 cal is used to display a monthly calendar. 15 15 16 16 config CATV … … 87 87 cut is used to print selected parts of lines from 88 88 each file to stdout. 89 90 config DD91 bool "dd"92 default y93 help94 dd copies a file (from standard input to standard output,95 by default) using specific input and output blocksizes,96 while optionally performing conversions on it.97 98 config FEATURE_DD_SIGNAL_HANDLING99 bool "Enable DD signal handling for status reporting"100 default y101 depends on DD102 help103 Sending a SIGUSR1 signal to a running `dd' process makes it104 print to standard error the number of records read and written105 so far, then to resume copying.106 107 $ dd if=/dev/zero of=/dev/null&108 $ pid=$! kill -USR1 $pid; sleep 1; kill $pid109 10899206+0 records in110 10899206+0 records out111 112 config FEATURE_DD_THIRD_STATUS_LINE113 bool "Enable the third status line upon signal"114 default y115 depends on DD && FEATURE_DD_SIGNAL_HANDLING116 help117 Displays a coreutils-like third status line with transferred bytes,118 elapsed time and speed.119 120 config FEATURE_DD_IBS_OBS121 bool "Enable ibs, obs and conv options"122 default y123 depends on DD124 help125 Enables support for writing a certain number of bytes in and out,126 at a time, and performing conversions on the data stream.127 89 128 90 config DF … … 582 544 'g' for 1GiB for the -b option. 583 545 584 config STAT585 bool "stat"586 default y587 select PLATFORM_LINUX # statfs()588 help589 display file or filesystem status.590 591 config FEATURE_STAT_FORMAT592 bool "Enable custom formats (-c)"593 default y594 depends on STAT595 help596 Without this, stat will not support the '-c format' option where597 users can pass a custom format string for output. This adds about598 7k to a nonstatic build on amd64.599 600 546 config STTY 601 547 bool "stty" … … 610 556 checksum and count the blocks in a file 611 557 612 config SYNC613 bool "sync"614 default y615 help616 sync is used to flush filesystem buffers.617 618 558 config TAC 619 559 bool "tac" … … 634 574 depends on TAIL 635 575 help 636 The options (-q, -s, and -v) are provided by GNU tail, but576 The options (-q, -s, -v and -F) are provided by GNU tail, but 637 577 are not specific in the SUSv3 standard. 638 578 … … 640 580 -s SEC Wait SEC seconds between reads with -f 641 581 -v Always output headers giving file names 582 -F Same as -f, but keep retrying 642 583 643 584 config TEE … … 674 615 uname is used to print system information. 675 616 617 config UNAME_OSNAME 618 string "Operating system name" 619 default "GNU/Linux" 620 depends on UNAME 621 help 622 Sets the operating system name reported by uname -o. The 623 default is "GNU/Linux". 624 676 625 config UNEXPAND 677 626 bool "unexpand" … … 738 687 yes is used to repeatedly output a specific string, or 739 688 the default string `y'. 689 690 comment "Common options" 691 692 config FEATURE_VERBOSE 693 bool "Support verbose options (usually -v) for various applets" 694 default y 695 help 696 Enable cp -v, rm -v and similar messages. 697 Also enables long option (--verbose) if it exists. 698 Without this option, -v is accepted but ignored. 740 699 741 700 comment "Common options for cp and mv" -
branches/3.3/mindi-busybox/coreutils/Kbuild.src
r3232 r3621 36 36 lib-$(CONFIG_FOLD) += fold.o 37 37 lib-$(CONFIG_FSYNC) += fsync.o 38 lib-$(CONFIG_HEAD) += head.o39 38 lib-$(CONFIG_INSTALL) += install.o 40 39 #lib-$(CONFIG_LENGTH) += length.o … … 70 69 lib-$(CONFIG_STTY) += stty.o 71 70 lib-$(CONFIG_SUM) += sum.o 72 lib-$(CONFIG_SYNC) += sync.o73 71 lib-$(CONFIG_TAC) += tac.o 74 lib-$(CONFIG_TAIL) += tail.o75 72 lib-$(CONFIG_TEE) += tee.o 76 73 lib-$(CONFIG_TRUE) += true.o -
branches/3.3/mindi-busybox/coreutils/basename.c
r3232 r3621 32 32 //usage: "FILE [SUFFIX]" 33 33 //usage:#define basename_full_usage "\n\n" 34 //usage: "Strip directory path and .SUFFIX from FILE \n"34 //usage: "Strip directory path and .SUFFIX from FILE" 35 35 //usage: 36 36 //usage:#define basename_example_usage -
branches/3.3/mindi-busybox/coreutils/cal.c
r3232 r3621 166 166 167 167 day_array(month, year, dp); 168 len = sprintf(lineout, "%s % d", month_names[month - 1], year);168 len = sprintf(lineout, "%s %u", month_names[month - 1], year); 169 169 printf("%*s%s\n%s\n", 170 170 ((7*julian + WEEK_LEN) - len) / 2, "", -
branches/3.3/mindi-busybox/coreutils/catv.c
r3232 r3621 20 20 21 21 #include "libbb.h" 22 #include "common_bufsiz.h" 23 24 #define CATV_OPT_e (1<<0) 25 #define CATV_OPT_t (1<<1) 26 #define CATV_OPT_v (1<<2) 27 struct BUG_const_mismatch { 28 char BUG_const_mismatch[ 29 CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS 30 ? 1 : -1 31 ]; 32 }; 22 33 23 34 int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 26 37 int retval = EXIT_SUCCESS; 27 38 int fd; 28 unsigned flags; 29 30 flags = getopt32(argv, "etv"); 31 #define CATV_OPT_e (1<<0) 32 #define CATV_OPT_t (1<<1) 33 #define CATV_OPT_v (1<<2) 34 flags ^= CATV_OPT_v; 39 unsigned opts; 40 opts = getopt32(argv, "etv"); 35 41 argv += optind; 42 #if 0 /* These consts match, we can just pass "opts" to visible() */ 43 if (opts & CATV_OPT_e) 44 flags |= VISIBLE_ENDLINE; 45 if (opts & CATV_OPT_t) 46 flags |= VISIBLE_SHOW_TABS; 47 #endif 36 48 37 49 /* Read from stdin if there's nothing else to do. */ 38 50 if (!argv[0]) 39 51 *--argv = (char*)"-"; 52 53 #define read_buf bb_common_bufsiz1 54 setup_common_bufsiz(); 40 55 do { 41 56 fd = open_or_warn_stdin(*argv); … … 47 62 int i, res; 48 63 49 #define read_buf bb_common_bufsiz150 64 res = read(fd, read_buf, COMMON_BUFSIZE); 51 65 if (res < 0) 52 66 retval = EXIT_FAILURE; 53 if (res < 1)67 if (res <= 0) 54 68 break; 55 69 for (i = 0; i < res; i++) { 56 70 unsigned char c = read_buf[i]; 57 58 if (c > 126 && (flags & CATV_OPT_v)) { 59 if (c == 127) { 60 printf("^?"); 61 continue; 62 } 63 printf("M-"); 64 c -= 128; 71 if (opts & CATV_OPT_v) { 72 putchar(c); 73 } else { 74 char buf[sizeof("M-^c")]; 75 visible(c, buf, opts); 76 fputs(buf, stdout); 65 77 } 66 if (c < 32) {67 if (c == 10) {68 if (flags & CATV_OPT_e)69 bb_putchar('$');70 } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {71 printf("^%c", c+'@');72 continue;73 }74 }75 bb_putchar(c);76 78 } 77 79 } -
branches/3.3/mindi-busybox/coreutils/chmod.c
r3232 r3621 70 70 return TRUE; 71 71 } 72 newmode = statbuf->st_mode;73 72 74 if (!bb_parse_mode((char *)param, &newmode)) 73 newmode = bb_parse_mode((char *)param, statbuf->st_mode); 74 if (newmode == (mode_t)-1) 75 75 bb_error_msg_and_die("invalid mode '%s'", (char *)param); 76 76 -
branches/3.3/mindi-busybox/coreutils/chown.c
r3232 r3621 12 12 13 13 //usage:#define chown_trivial_usage 14 //usage: "[-Rh LHP"IF_DESKTOP("cvf")"]... OWNER[<.|:>[GROUP]] FILE..."14 //usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... USER[:[GRP]] FILE..." 15 15 //usage:#define chown_full_usage "\n\n" 16 //usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n"16 //usage: "Change the owner and/or group of each FILE to USER and/or GRP\n" 17 17 //usage: "\n -R Recurse" 18 18 //usage: "\n -h Affect symlinks instead of symlink targets" 19 //usage: IF_DESKTOP( 19 20 //usage: "\n -L Traverse all symlinks to directories" 20 21 //usage: "\n -H Traverse symlinks on command line only" 21 22 //usage: "\n -P Don't traverse symlinks (default)" 22 //usage: IF_DESKTOP(23 23 //usage: "\n -c List changed files" 24 24 //usage: "\n -v List all files" … … 113 113 struct param_t param; 114 114 115 /* Just -1 might not work: uid_t may be unsigned long */116 param.ugid.uid = -1L;117 param.ugid.gid = -1L;118 119 115 #if ENABLE_FEATURE_CHOWN_LONG_OPTIONS 120 116 applet_long_options = chown_longopts; -
branches/3.3/mindi-busybox/coreutils/cksum.c
r3232 r3621 14 14 15 15 #include "libbb.h" 16 #include "common_bufsiz.h" 16 17 17 18 /* This is a NOEXEC applet. Be very careful! */ … … 33 34 #endif 34 35 36 setup_common_bufsiz(); 35 37 do { 36 38 int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input); … … 44 46 45 47 #define read_buf bb_common_bufsiz1 46 while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) {48 while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) { 47 49 length += bytes_read; 48 50 crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table); -
branches/3.3/mindi-busybox/coreutils/cp.c
r3232 r3621 32 32 //usage: "\n -i Prompt before overwrite" 33 33 //usage: "\n -l,-s Create (sym)links" 34 //usage: "\n -u Copy only newer files" 34 35 35 36 #include "libbb.h" … … 50 51 int status; 51 52 enum { 52 OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1), 53 OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)), 54 OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1), 55 OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2), 56 #if ENABLE_FEATURE_CP_LONG_OPTIONS 57 OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3), 53 FILEUTILS_CP_OPTNUM = sizeof(FILEUTILS_CP_OPTSTR)-1, 54 #if ENABLE_FEATURE_CP_LONG_OPTIONS 55 /*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */ 56 OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1), 58 57 #endif 59 58 }; … … 77 76 "symbolic-link\0" No_argument "s" 78 77 "verbose\0" No_argument "v" 79 "parents\0" No_argument "\xff" 78 "update\0" No_argument "u" 79 "remove-destination\0" No_argument "\xff" 80 "parents\0" No_argument "\xfe" 80 81 ; 81 82 #endif 82 // -v (--verbose) is ignored 83 flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv"); 83 flags = getopt32(argv, FILEUTILS_CP_OPTSTR); 84 84 /* Options of cp from GNU coreutils 6.10: 85 85 * -a, --archive … … 96 96 * -p same as --preserve=mode,ownership,timestamps 97 97 * -c same as --preserve=context 98 * -u, --update 99 * copy only when the SOURCE file is newer than the destination 100 * file or when the destination file is missing 101 * --remove-destination 102 * remove each existing destination file before attempting to open 98 103 * --parents 99 104 * use full source file name under DIRECTORY … … 108 113 * if possible additional attributes: security context,links,all 109 114 * --no-preserve=ATTR_LIST 110 * --remove-destination111 * remove each existing destination file before attempting to open112 115 * --sparse=WHEN 113 116 * control creation of sparse files … … 120 123 * -T, --no-target-directory 121 124 * treat DEST as a normal file 122 * -u, --update123 * copy only when the SOURCE file is newer than the destination124 * file or when the destination file is missing125 125 * -x, --one-file-system 126 126 * stay on this file system … … 158 158 159 159 #if ENABLE_FEATURE_CP_LONG_OPTIONS 160 //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x", 161 // flags, FILEUTILS_RMDEST, OPT_parents); 160 162 if (flags & OPT_parents) { 161 163 if (!(d_flags & 2)) { 162 164 bb_error_msg_and_die("with --parents, the destination must be a directory"); 163 165 } 166 } 167 if (flags & FILEUTILS_RMDEST) { 168 flags |= FILEUTILS_FORCE; 164 169 } 165 170 #endif -
branches/3.3/mindi-busybox/coreutils/date.c
r3232 r3621 139 139 140 140 #include "libbb.h" 141 #include "common_bufsiz.h" 141 142 #if ENABLE_FEATURE_DATE_NANO 142 143 # include <sys/syscall.h> … … 369 370 370 371 #define date_buf bb_common_bufsiz1 372 setup_common_bufsiz(); 371 373 if (*fmt_dt2str == '\0') { 372 374 /* With no format string, just print a blank line */ … … 374 376 } else { 375 377 /* Handle special conversions */ 376 if ( strncmp(fmt_dt2str, "%f", 2) == 0) {378 if (is_prefixed_with(fmt_dt2str, "%f")) { 377 379 fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S"; 378 380 } 379 381 /* Generate output string */ 380 strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time);382 strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time); 381 383 } 382 384 puts(date_buf); -
branches/3.3/mindi-busybox/coreutils/dd.c
r3232 r3621 9 9 */ 10 10 11 //config:config DD 12 //config: bool "dd" 13 //config: default y 14 //config: help 15 //config: dd copies a file (from standard input to standard output, 16 //config: by default) using specific input and output blocksizes, 17 //config: while optionally performing conversions on it. 18 //config: 19 //config:config FEATURE_DD_SIGNAL_HANDLING 20 //config: bool "Enable signal handling for status reporting" 21 //config: default y 22 //config: depends on DD 23 //config: help 24 //config: Sending a SIGUSR1 signal to a running `dd' process makes it 25 //config: print to standard error the number of records read and written 26 //config: so far, then to resume copying. 27 //config: 28 //config: $ dd if=/dev/zero of=/dev/null & 29 //config: $ pid=$!; kill -USR1 $pid; sleep 1; kill $pid 30 //config: 10899206+0 records in 31 //config: 10899206+0 records out 32 //config: 33 //config:config FEATURE_DD_THIRD_STATUS_LINE 34 //config: bool "Enable the third status line upon signal" 35 //config: default y 36 //config: depends on DD && FEATURE_DD_SIGNAL_HANDLING 37 //config: help 38 //config: Displays a coreutils-like third status line with transferred bytes, 39 //config: elapsed time and speed. 40 //config: 41 //config:config FEATURE_DD_IBS_OBS 42 //config: bool "Enable ibs, obs and conv options" 43 //config: default y 44 //config: depends on DD 45 //config: help 46 //config: Enables support for writing a certain number of bytes in and out, 47 //config: at a time, and performing conversions on the data stream. 48 //config: 49 //config:config FEATURE_DD_STATUS 50 //config: bool "Enable status display options" 51 //config: default y 52 //config: depends on DD 53 //config: help 54 //config: Enables support for status=noxfer/none option. 55 11 56 //usage:#define dd_trivial_usage 12 57 //usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n" 13 //usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] ")58 //usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes]") 14 59 //usage:#define dd_full_usage "\n\n" 15 60 //usage: "Copy a file with converting and formatting\n" … … 31 76 //usage: "\n conv=sync Pad blocks with zeros" 32 77 //usage: "\n conv=fsync Physically write data out before finishing" 78 //usage: "\n conv=swab Swap every pair of bytes" 79 //usage: "\n iflag=skip_bytes skip=N is in bytes" 80 //usage: ) 81 //usage: IF_FEATURE_DD_STATUS( 82 //usage: "\n status=noxfer Suppress rate output" 83 //usage: "\n status=none Suppress all output" 33 84 //usage: ) 34 85 //usage: "\n" 35 //usage: "\nNumbers may be suffixed by c (x1), w (x2), b (x512), kD (x1000), k (x1024)," 36 //usage: "\nMD (x1000000), M (x1048576), GD (x1000000000) or G (x1073741824)" 86 //usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G" 37 87 //usage: 38 88 //usage:#define dd_example_usage … … 42 92 43 93 #include "libbb.h" 94 #include "common_bufsiz.h" 44 95 45 96 /* This is a NOEXEC applet. Be very careful! */ … … 49 100 ifd = STDIN_FILENO, 50 101 ofd = STDOUT_FILENO, 51 };52 53 static const struct suffix_mult dd_suffixes[] = {54 { "c", 1 },55 { "w", 2 },56 { "b", 512 },57 { "kD", 1000 },58 { "k", 1024 },59 { "K", 1024 }, /* compat with coreutils dd */60 { "MD", 1000000 },61 { "M", 1048576 },62 { "GD", 1000000000 },63 { "G", 1073741824 },64 { "", 0 }65 102 }; 66 103 … … 71 108 unsigned long long begin_time_us; 72 109 #endif 110 int flags; 73 111 } FIX_ALIASING; 74 #define G (*(struct globals*) &bb_common_bufsiz1)112 #define G (*(struct globals*)bb_common_bufsiz1) 75 113 #define INIT_G() do { \ 114 setup_common_bufsiz(); \ 76 115 /* we have to zero it out because of NOEXEC */ \ 77 116 memset(&G, 0, sizeof(G)); \ 78 117 } while (0) 79 118 119 enum { 120 /* Must be in the same order as OP_conv_XXX! */ 121 /* (see "flags |= (1 << what)" below) */ 122 FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS, 123 FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS, 124 FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS, 125 FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS, 126 FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS, 127 /* end of conv flags */ 128 /* start of input flags */ 129 FLAG_IFLAG_SHIFT = 5, 130 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, 131 /* end of input flags */ 132 FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, 133 FLAG_COUNT = 1 << 7, 134 FLAG_STATUS = 1 << 8, 135 FLAG_STATUS_NONE = 1 << 9, 136 FLAG_STATUS_NOXFER = 1 << 10, 137 }; 80 138 81 139 static void dd_output_status(int UNUSED_PARAM cur_signal) … … 94 152 95 153 #if ENABLE_FEATURE_DD_THIRD_STATUS_LINE 154 # if ENABLE_FEATURE_DD_STATUS 155 if (G.flags & FLAG_STATUS_NOXFER) /* status=noxfer active? */ 156 return; 157 //TODO: should status=none make dd stop reacting to USR1 entirely? 158 //So far we react to it (we print the stats), 159 //status=none only suppresses final, non-USR1 generated status message. 160 # endif 96 161 fprintf(stderr, "%llu bytes (%sB) copied, ", 97 162 G.total_bytes, … … 146 211 #endif 147 212 213 #if ENABLE_FEATURE_DD_IBS_OBS 214 static int parse_comma_flags(char *val, const char *words, const char *error_in) 215 { 216 int flags = 0; 217 while (1) { 218 int n; 219 char *arg; 220 /* find ',', replace them with NUL so we can use val for 221 * index_in_strings() without copying. 222 * We rely on val being non-null, else strchr would fault. 223 */ 224 arg = strchr(val, ','); 225 if (arg) 226 *arg = '\0'; 227 n = index_in_strings(words, val); 228 if (n < 0) 229 bb_error_msg_and_die(bb_msg_invalid_arg_to, val, error_in); 230 flags |= (1 << n); 231 if (!arg) /* no ',' left, so this was the last specifier */ 232 break; 233 *arg = ','; /* to preserve ps listing */ 234 val = arg + 1; /* skip this keyword and ',' */ 235 } 236 return flags; 237 } 238 #endif 239 148 240 int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 149 241 int dd_main(int argc UNUSED_PARAM, char **argv) 150 242 { 151 enum {152 /* Must be in the same order as OP_conv_XXX! */153 /* (see "flags |= (1 << what)" below) */154 FLAG_NOTRUNC = 1 << 0,155 FLAG_SYNC = 1 << 1,156 FLAG_NOERROR = 1 << 2,157 FLAG_FSYNC = 1 << 3,158 /* end of conv flags */159 FLAG_TWOBUFS = 1 << 4,160 FLAG_COUNT = 1 << 5,161 };162 243 static const char keywords[] ALIGN1 = 163 "bs\0""count\0""seek\0""skip\0""if\0""of\0" 164 #if ENABLE_FEATURE_DD_IBS_OBS 165 "ibs\0""obs\0""conv\0" 244 "bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0") 245 #if ENABLE_FEATURE_DD_IBS_OBS 246 "ibs\0""obs\0""conv\0""iflag\0" 166 247 #endif 167 248 ; 168 249 #if ENABLE_FEATURE_DD_IBS_OBS 169 250 static const char conv_words[] ALIGN1 = 170 "notrunc\0""sync\0""noerror\0""fsync\0"; 251 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0"; 252 static const char iflag_words[] ALIGN1 = 253 "skip_bytes\0"; 254 #endif 255 #if ENABLE_FEATURE_DD_STATUS 256 static const char status_words[] ALIGN1 = 257 "none\0""noxfer\0"; 171 258 #endif 172 259 enum { … … 177 264 OP_if, 178 265 OP_of, 266 IF_FEATURE_DD_STATUS(OP_status,) 179 267 #if ENABLE_FEATURE_DD_IBS_OBS 180 268 OP_ibs, 181 269 OP_obs, 182 270 OP_conv, 271 OP_iflag, 183 272 /* Must be in the same order as FLAG_XXX! */ 184 273 OP_conv_notrunc = 0, … … 186 275 OP_conv_noerror, 187 276 OP_conv_fsync, 277 OP_conv_swab, 188 278 /* Unimplemented conv=XXX: */ 189 279 //nocreat do not create the output file 190 280 //excl fail if the output file already exists 191 281 //fdatasync physically write output file data before finishing 192 //swab swap every pair of input bytes193 282 //lcase change upper case to lower case 194 283 //ucase change lower case to upper case … … 198 287 //ebcdic from ASCII to EBCDIC 199 288 //ibm from ASCII to alternate EBCDIC 289 /* Partially implemented: */ 290 //swab swap every pair of input bytes: will abort on non-even reads 291 OP_iflag_skip_bytes, 200 292 #endif 201 293 }; 202 int exitcode = EXIT_FAILURE; 203 size_t ibs = 512, obs = 512; 204 ssize_t n, w; 205 char *ibuf, *obuf; 206 /* And these are all zeroed at once! */ 294 smallint exitcode = EXIT_FAILURE; 295 int i; 296 size_t ibs = 512; 297 char *ibuf; 298 #if ENABLE_FEATURE_DD_IBS_OBS 299 size_t obs = 512; 300 char *obuf; 301 #else 302 # define obs ibs 303 # define obuf ibuf 304 #endif 305 /* These are all zeroed at once! */ 207 306 struct { 208 int flags;209 307 size_t oc; 308 ssize_t prev_read_size; /* for detecting swab failure */ 210 309 off_t count; 211 310 off_t seek, skip; 212 311 const char *infile, *outfile; 213 312 } Z; 214 #define flags (Z.flags )215 313 #define oc (Z.oc ) 314 #define prev_read_size (Z.prev_read_size) 216 315 #define count (Z.count ) 217 316 #define seek (Z.seek ) … … 224 323 //fflush_all(); - is this needed because of NOEXEC? 225 324 226 for ( n = 1; argv[n]; n++) {325 for (i = 1; argv[i]; i++) { 227 326 int what; 228 327 char *val; 229 char *arg = argv[ n];328 char *arg = argv[i]; 230 329 231 330 #if ENABLE_DESKTOP … … 247 346 if (what == OP_ibs) { 248 347 /* Must fit into positive ssize_t */ 249 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);348 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 250 349 /*continue;*/ 251 350 } 252 351 if (what == OP_obs) { 253 obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);352 obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 254 353 /*continue;*/ 255 354 } 256 355 if (what == OP_conv) { 257 while (1) { 258 /* find ',', replace them with NUL so we can use val for 259 * index_in_strings() without copying. 260 * We rely on val being non-null, else strchr would fault. 261 */ 262 arg = strchr(val, ','); 263 if (arg) 264 *arg = '\0'; 265 what = index_in_strings(conv_words, val); 266 if (what < 0) 267 bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv"); 268 flags |= (1 << what); 269 if (!arg) /* no ',' left, so this was the last specifier */ 270 break; 271 /* *arg = ','; - to preserve ps listing? */ 272 val = arg + 1; /* skip this keyword and ',' */ 273 } 274 continue; /* we trashed 'what', can't fall through */ 356 G.flags |= parse_comma_flags(val, conv_words, "conv"); 357 /*continue;*/ 358 } 359 if (what == OP_iflag) { 360 G.flags |= parse_comma_flags(val, iflag_words, "iflag") << FLAG_IFLAG_SHIFT; 361 /*continue;*/ 275 362 } 276 363 #endif 277 364 if (what == OP_bs) { 278 ibs = obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes); 365 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 366 obs = ibs; 279 367 /*continue;*/ 280 368 } 281 369 /* These can be large: */ 282 370 if (what == OP_count) { 283 flags |= FLAG_COUNT;284 count = XATOU_SFX(val, dd_suffixes);371 G.flags |= FLAG_COUNT; 372 count = XATOU_SFX(val, cwbkMG_suffixes); 285 373 /*continue;*/ 286 374 } 287 375 if (what == OP_seek) { 288 seek = XATOU_SFX(val, dd_suffixes);376 seek = XATOU_SFX(val, cwbkMG_suffixes); 289 377 /*continue;*/ 290 378 } 291 379 if (what == OP_skip) { 292 skip = XATOU_SFX(val, dd_suffixes);380 skip = XATOU_SFX(val, cwbkMG_suffixes); 293 381 /*continue;*/ 294 382 } … … 301 389 /*continue;*/ 302 390 } 303 } /* end of "for (argv[n])" */ 391 #if ENABLE_FEATURE_DD_STATUS 392 if (what == OP_status) { 393 int n; 394 n = index_in_strings(status_words, val); 395 if (n < 0) 396 bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status"); 397 G.flags |= FLAG_STATUS << n; 398 /*continue;*/ 399 } 400 #endif 401 } /* end of "for (argv[i])" */ 304 402 305 403 //XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever 306 ibuf = obuf = xmalloc(ibs); 404 ibuf = xmalloc(ibs); 405 obuf = ibuf; 406 #if ENABLE_FEATURE_DD_IBS_OBS 307 407 if (ibs != obs) { 308 flags |= FLAG_TWOBUFS;408 G.flags |= FLAG_TWOBUFS; 309 409 obuf = xmalloc(obs); 310 410 } 411 #endif 311 412 312 413 #if ENABLE_FEATURE_DD_SIGNAL_HANDLING … … 317 418 #endif 318 419 319 if (infile != NULL)420 if (infile) { 320 421 xmove_fd(xopen(infile, O_RDONLY), ifd); 321 else {422 } else { 322 423 infile = bb_msg_standard_input; 323 424 } 324 if (outfile != NULL) {425 if (outfile) { 325 426 int oflag = O_WRONLY | O_CREAT; 326 427 327 if (!seek && !( flags & FLAG_NOTRUNC))428 if (!seek && !(G.flags & FLAG_NOTRUNC)) 328 429 oflag |= O_TRUNC; 329 430 330 431 xmove_fd(xopen(outfile, oflag), ofd); 331 432 332 if (seek && !( flags & FLAG_NOTRUNC)) {433 if (seek && !(G.flags & FLAG_NOTRUNC)) { 333 434 if (ftruncate(ofd, seek * obs) < 0) { 334 435 struct stat st; … … 346 447 } 347 448 if (skip) { 348 if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) { 349 while (skip-- > 0) { 350 n = safe_read(ifd, ibuf, ibs); 449 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs; 450 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) { 451 do { 452 ssize_t n = safe_read(ifd, ibuf, blocksz); 351 453 if (n < 0) 352 454 goto die_infile; 353 455 if (n == 0) 354 456 break; 355 } 457 } while (--skip != 0); 356 458 } 357 459 } … … 361 463 } 362 464 363 while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { 465 while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { 466 ssize_t n; 467 364 468 n = safe_read(ifd, ibuf, ibs); 365 469 if (n == 0) … … 367 471 if (n < 0) { 368 472 /* "Bad block" */ 369 if (!( flags & FLAG_NOERROR))473 if (!(G.flags & FLAG_NOERROR)) 370 474 goto die_infile; 371 475 bb_simple_perror_msg(infile); … … 376 480 n = 0; 377 481 } 482 if (G.flags & FLAG_SWAB) { 483 uint16_t *p16; 484 ssize_t n2; 485 486 /* Our code allows only last read to be odd-sized */ 487 if (prev_read_size & 1) 488 bb_error_msg_and_die("can't swab %lu byte buffer", 489 (unsigned long)prev_read_size); 490 prev_read_size = n; 491 492 /* If n is odd, last byte is not swapped: 493 * echo -n "qwe" | dd conv=swab 494 * prints "wqe". 495 */ 496 p16 = (void*) ibuf; 497 n2 = (n >> 1); 498 while (--n2 >= 0) { 499 *p16 = bswap_16(*p16); 500 p16++; 501 } 502 } 378 503 if ((size_t)n == ibs) 379 504 G.in_full++; 380 505 else { 381 506 G.in_part++; 382 if ( flags & FLAG_SYNC) {507 if (G.flags & FLAG_SYNC) { 383 508 memset(ibuf + n, 0, ibs - n); 384 509 n = ibs; 385 510 } 386 511 } 387 if ( flags & FLAG_TWOBUFS) {512 if (G.flags & FLAG_TWOBUFS) { 388 513 char *tmp = ibuf; 389 514 while (n) { … … 402 527 } 403 528 } 404 } else if (write_and_stats(ibuf, n, obs, outfile)) 405 goto out_status; 406 407 if (flags & FLAG_FSYNC) { 529 } else { 530 if (write_and_stats(ibuf, n, obs, outfile)) 531 goto out_status; 532 } 533 534 if (G.flags & FLAG_FSYNC) { 408 535 if (fsync(ofd) < 0) 409 536 goto die_outfile; … … 412 539 413 540 if (ENABLE_FEATURE_DD_IBS_OBS && oc) { 414 w = full_write_or_warn(obuf, oc, outfile); 415 if (w < 0) goto out_status; 416 if (w > 0) G.out_part++; 541 if (write_and_stats(obuf, oc, obs, outfile)) 542 goto out_status; 417 543 } 418 544 if (close(ifd) < 0) { … … 428 554 exitcode = EXIT_SUCCESS; 429 555 out_status: 430 dd_output_status(0); 556 if (!ENABLE_FEATURE_DD_STATUS || !(G.flags & FLAG_STATUS_NONE)) 557 dd_output_status(0); 431 558 432 559 if (ENABLE_FEATURE_CLEAN_UP) { 433 560 free(obuf); 434 if ( flags & FLAG_TWOBUFS)561 if (G.flags & FLAG_TWOBUFS) 435 562 free(ibuf); 436 563 } -
branches/3.3/mindi-busybox/coreutils/df.c
r3232 r3621 26 26 //usage: "[-Pk" 27 27 //usage: IF_FEATURE_HUMAN_READABLE("mh") 28 //usage: "T" 28 29 //usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE") 29 30 //usage: "] [FILESYSTEM]..." … … 36 37 //usage: "\n -h Human readable (e.g. 1K 243M 2G)" 37 38 //usage: ) 39 //usage: "\n -T Print filesystem type" 38 40 //usage: IF_FEATURE_DF_FANCY( 39 41 //usage: "\n -a Show all filesystems" … … 84 86 OPT_KILO = (1 << 0), 85 87 OPT_POSIX = (1 << 1), 86 OPT_ALL = (1 << 2) * ENABLE_FEATURE_DF_FANCY, 87 OPT_INODE = (1 << 3) * ENABLE_FEATURE_DF_FANCY, 88 OPT_BSIZE = (1 << 4) * ENABLE_FEATURE_DF_FANCY, 89 OPT_HUMAN = (1 << (2 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, 90 OPT_MEGA = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, 88 OPT_FSTYPE = (1 << 2), 89 OPT_ALL = (1 << 3) * ENABLE_FEATURE_DF_FANCY, 90 OPT_INODE = (1 << 4) * ENABLE_FEATURE_DF_FANCY, 91 OPT_BSIZE = (1 << 5) * ENABLE_FEATURE_DF_FANCY, 92 OPT_HUMAN = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, 93 OPT_MEGA = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, 91 94 }; 92 95 const char *disp_units_hdr = NULL; … … 100 103 opt_complementary = "k-m:m-k"; 101 104 #endif 102 opt = getopt32(argv, "kP "105 opt = getopt32(argv, "kPT" 103 106 IF_FEATURE_DF_FANCY("aiB:") 104 107 IF_FEATURE_HUMAN_READABLE("hm") … … 135 138 #endif 136 139 } 137 printf("Filesystem %-15sUsed Available %s Mounted on\n", 138 disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%"); 140 141 printf("Filesystem %s%-15sUsed Available %s Mounted on\n", 142 (opt & OPT_FSTYPE) ? "Type " : "", 143 disp_units_hdr, 144 (opt & OPT_POSIX) ? "Capacity" : "Use%"); 139 145 140 146 mount_table = NULL; … … 149 155 const char *device; 150 156 const char *mount_point; 157 const char *fs_type; 151 158 152 159 if (mount_table) { … … 171 178 device = mount_entry->mnt_fsname; 172 179 mount_point = mount_entry->mnt_dir; 180 fs_type = mount_entry->mnt_type; 173 181 174 182 if (statfs(mount_point, &s) != 0) { … … 219 227 } 220 228 free(uni_dev); 229 if (opt & OPT_FSTYPE) { 230 char *uni_type = unicode_conv_to_printable(&uni_stat, fs_type); 231 if (uni_stat.unicode_width > 10 && !(opt & OPT_POSIX)) 232 printf(" %s\n%31s", uni_type, ""); 233 else 234 printf(" %s%*s", uni_type, 10 - (int)uni_stat.unicode_width, ""); 235 free(uni_type); 236 } 221 237 } 222 238 #else 223 239 if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX)) 224 240 printf("\n%-20s", ""); 241 if (opt & OPT_FSTYPE) { 242 if (printf(" %-10s", fs_type) > 11 && !(opt & OPT_POSIX)) 243 printf("\n%-30s", ""); 244 } 225 245 #endif 226 246 -
branches/3.3/mindi-busybox/coreutils/dos2unix.c
r3232 r3621 42 42 { 43 43 FILE *in, *out; 44 int i;44 int ch; 45 45 char *temp_fn = temp_fn; /* for compiler */ 46 46 char *resolved_fn = resolved_fn; … … 50 50 if (fn != NULL) { 51 51 struct stat st; 52 int fd; 52 53 53 54 resolved_fn = xmalloc_follow_symlinks(fn); … … 55 56 bb_simple_perror_msg_and_die(fn); 56 57 in = xfopen_for_read(resolved_fn); 57 fstat(fileno(in), &st);58 xfstat(fileno(in), &st, resolved_fn); 58 59 59 60 temp_fn = xasprintf("%sXXXXXX", resolved_fn); 60 i= xmkstemp(temp_fn);61 if (fchmod( i, st.st_mode) == -1)61 fd = xmkstemp(temp_fn); 62 if (fchmod(fd, st.st_mode) == -1) 62 63 bb_simple_perror_msg_and_die(temp_fn); 64 fchown(fd, st.st_uid, st.st_gid); 63 65 64 out = xfdopen_for_write( i);66 out = xfdopen_for_write(fd); 65 67 } 66 68 67 while (( i= fgetc(in)) != EOF) {68 if ( i== '\r')69 while ((ch = fgetc(in)) != EOF) { 70 if (ch == '\r') 69 71 continue; 70 if ( i== '\n')72 if (ch == '\n') 71 73 if (conv_type == CT_UNIX2DOS) 72 74 fputc('\r', out); 73 fputc( i, out);75 fputc(ch, out); 74 76 } 75 77 -
branches/3.3/mindi-busybox/coreutils/du.c
r3232 r3621 59 59 60 60 #include "libbb.h" 61 #include "common_bufsiz.h" 61 62 62 63 enum { … … 76 77 struct globals { 77 78 #if ENABLE_FEATURE_HUMAN_READABLE 78 unsigned long disp_ hr;79 unsigned long disp_unit; 79 80 #else 80 81 unsigned disp_k; … … 86 87 dev_t dir_dev; 87 88 } FIX_ALIASING; 88 #define G (*(struct globals*)&bb_common_bufsiz1) 89 #define INIT_G() do { } while (0) 90 91 92 /* FIXME? coreutils' du rounds sizes up: 93 * for example, 1025k file is shown as "2" by du -m. 94 * We round to nearest. 95 */ 89 #define G (*(struct globals*)bb_common_bufsiz1) 90 #define INIT_G() do { setup_common_bufsiz(); } while (0) 91 92 96 93 static void print(unsigned long long size, const char *filename) 97 94 { 98 95 /* TODO - May not want to defer error checking here. */ 99 96 #if ENABLE_FEATURE_HUMAN_READABLE 97 # if ENABLE_DESKTOP 98 /* ~30 bytes of code for extra comtat: 99 * coreutils' du rounds sizes up: 100 * for example, 1025k file is shown as "2" by du -m. 101 * We round to nearest if human-readable [too hard to fix], 102 * else (fixed scale such as -m), we round up. To that end, 103 * add yet another half of the unit before displaying: 104 */ 105 if (G.disp_unit) 106 size += (G.disp_unit-1) / (unsigned)(512 * 2); 107 # endif 100 108 printf("%s\t%s\n", 101 /* size x 512 / G.disp_hr, show one fractional, 102 * use suffixes if G.disp_hr == 0 */ 103 make_human_readable_str(size, 512, G.disp_hr), 109 /* size x 512 / G.disp_unit. 110 * If G.disp_unit == 0, show one fractional 111 * and use suffixes 112 */ 113 make_human_readable_str(size, 512, G.disp_unit), 104 114 filename); 105 115 #else … … 200 210 201 211 #if ENABLE_FEATURE_HUMAN_READABLE 202 IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_ hr= 1024;)203 IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_ hr= 512;)212 IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 1024;) 213 IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 512;) 204 214 if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */ 205 G.disp_ hr= 512;215 G.disp_unit = 512; 206 216 #else 207 217 IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;) … … 221 231 argv += optind; 222 232 if (opt & OPT_h_for_humans) { 223 G.disp_ hr= 0;233 G.disp_unit = 0; 224 234 } 225 235 if (opt & OPT_m_mbytes) { 226 G.disp_ hr= 1024*1024;236 G.disp_unit = 1024*1024; 227 237 } 228 238 if (opt & OPT_k_kbytes) { 229 G.disp_ hr= 1024;239 G.disp_unit = 1024; 230 240 } 231 241 #else -
branches/3.3/mindi-busybox/coreutils/echo.c
r3232 r3621 73 73 #if !ENABLE_FEATURE_FANCY_ECHO 74 74 enum { 75 eflag = '\\',75 eflag = 0, /* 0 -- disable escape sequences */ 76 76 nflag = 1, /* 1 -- print '\n' */ 77 77 }; -
branches/3.3/mindi-busybox/coreutils/expand.c
r3232 r3621 79 79 *ptr = '\0'; 80 80 # if ENABLE_UNICODE_SUPPORT 81 { 82 uni_stat_t uni_stat; 83 printable_string(&uni_stat, ptr_strbeg); 84 len = uni_stat.unicode_width; 85 } 81 len = unicode_strwidth(ptr_strbeg); 86 82 # else 87 83 len = ptr - ptr_strbeg; … … 139 135 # if ENABLE_UNICODE_SUPPORT 140 136 { 141 char c; 142 uni_stat_t uni_stat; 143 c = ptr[n]; 137 char c = ptr[n]; 144 138 ptr[n] = '\0'; 145 printable_string(&uni_stat, ptr); 146 len = uni_stat.unicode_width; 139 len = unicode_strwidth(ptr); 147 140 ptr[n] = c; 148 141 } -
branches/3.3/mindi-busybox/coreutils/expr.c
r3232 r3621 62 62 63 63 #include "libbb.h" 64 #include "common_bufsiz.h" 64 65 #include "xregex.h" 65 66 … … 100 101 char **args; 101 102 } FIX_ALIASING; 102 #define G (*(struct globals*) &bb_common_bufsiz1)103 #define INIT_G() do { } while (0)103 #define G (*(struct globals*)bb_common_bufsiz1) 104 #define INIT_G() do { setup_common_bufsiz(); } while (0) 104 105 105 106 /* forward declarations */ -
branches/3.3/mindi-busybox/coreutils/false.c
r3232 r3621 11 11 /* http://www.opengroup.org/onlinepubs/000095399/utilities/false.html */ 12 12 13 //usage:#define false_trivial_usage 14 //usage: "" 15 //usage:#define false_full_usage "\n\n" 16 //usage: "Return an exit code of FALSE (1)" 17 //usage: 13 /* "false --help" is special-cased to ignore --help */ 14 //usage:#define false_trivial_usage NOUSAGE_STR 15 //usage:#define false_full_usage "" 18 16 //usage:#define false_example_usage 19 17 //usage: "$ false\n" -
branches/3.3/mindi-busybox/coreutils/head.c
r3232 r3621 12 12 /* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */ 13 13 14 //kbuild:lib-$(CONFIG_HEAD) += head.o 15 14 16 //usage:#define head_trivial_usage 15 17 //usage: "[OPTIONS] [FILE]..." … … 19 21 //usage: "\n -n N[kbm] Print first N lines" 20 22 //usage: IF_FEATURE_FANCY_HEAD( 21 //usage: "\n -c N[kbm] Print first N bytes" 23 //usage: "\n -n -N[kbm] Print all except N last lines" 24 //usage: "\n -c [-]N[kbm] Print first N bytes" 22 25 //usage: "\n -q Never print headers" 23 26 //usage: "\n -v Always print headers" … … 35 38 /* This is a NOEXEC applet. Be very careful! */ 36 39 40 #if !ENABLE_FEATURE_FANCY_HEAD 41 # define print_first_N(fp,count,bytes) print_first_N(fp,count) 42 #endif 43 static void 44 print_first_N(FILE *fp, unsigned long count, bool count_bytes) 45 { 46 #if !ENABLE_FEATURE_FANCY_HEAD 47 const int count_bytes = 0; 48 #endif 49 while (count) { 50 int c = getc(fp); 51 if (c == EOF) 52 break; 53 if (count_bytes || (c == '\n')) 54 --count; 55 putchar(c); 56 } 57 } 58 59 #if ENABLE_FEATURE_FANCY_HEAD 60 static void 61 print_except_N_last_bytes(FILE *fp, unsigned count) 62 { 63 unsigned char *circle = xmalloc(++count); 64 unsigned head = 0; 65 for(;;) { 66 int c; 67 c = getc(fp); 68 if (c == EOF) 69 goto ret; 70 circle[head++] = c; 71 if (head == count) 72 break; 73 } 74 for (;;) { 75 int c; 76 if (head == count) 77 head = 0; 78 putchar(circle[head]); 79 c = getc(fp); 80 if (c == EOF) 81 goto ret; 82 circle[head] = c; 83 head++; 84 } 85 ret: 86 free(circle); 87 } 88 89 static void 90 print_except_N_last_lines(FILE *fp, unsigned count) 91 { 92 char **circle = xzalloc((++count) * sizeof(circle[0])); 93 unsigned head = 0; 94 for(;;) { 95 char *c; 96 c = xmalloc_fgets(fp); 97 if (!c) 98 goto ret; 99 circle[head++] = c; 100 if (head == count) 101 break; 102 } 103 for (;;) { 104 char *c; 105 if (head == count) 106 head = 0; 107 fputs(circle[head], stdout); 108 c = xmalloc_fgets(fp); 109 if (!c) 110 goto ret; 111 free(circle[head]); 112 circle[head++] = c; 113 } 114 ret: 115 head = 0; 116 for(;;) { 117 free(circle[head++]); 118 if (head == count) 119 break; 120 } 121 free(circle); 122 } 123 #else 124 /* Must never be called */ 125 void print_except_N_last_bytes(FILE *fp, unsigned count); 126 void print_except_N_last_lines(FILE *fp, unsigned count); 127 #endif 128 129 #if !ENABLE_FEATURE_FANCY_HEAD 130 # define eat_num(negative_N,p) eat_num(p) 131 #endif 132 static unsigned long 133 eat_num(bool *negative_N, const char *p) 134 { 135 #if ENABLE_FEATURE_FANCY_HEAD 136 if (*p == '-') { 137 *negative_N = 1; 138 p++; 139 } 140 #endif 141 return xatoul_sfx(p, bkm_suffixes); 142 } 143 37 144 static const char head_opts[] ALIGN1 = 38 145 "n:" … … 42 149 ; 43 150 44 static const struct suffix_mult head_suffixes[] = {45 { "b", 512 },46 { "k", 1024 },47 { "m", 1024*1024 },48 { "", 0 }49 };50 51 151 #define header_fmt_str "\n==> %s <==\n" 52 152 … … 55 155 { 56 156 unsigned long count = 10; 57 unsigned long i; 58 #if ENABLE_FEATURE_FANCY_HEAD 59 int count_bytes = 0; 157 #if ENABLE_FEATURE_FANCY_HEAD 60 158 int header_threshhold = 1; 159 bool count_bytes = 0; 160 bool negative_N = 0; 161 #else 162 # define header_threshhold 1 163 # define count_bytes 0 164 # define negative_N 0 61 165 #endif 62 166 FILE *fp; … … 64 168 char *p; 65 169 int opt; 66 int c;67 170 int retval = EXIT_SUCCESS; 68 171 … … 74 177 --argc; 75 178 ++argv; 76 p = (*argv)+ 1;179 p = argv[0] + 1; 77 180 goto GET_COUNT; 78 181 } … … 98 201 GET_COUNT: 99 202 #endif 100 count = xatoul_sfx(p, head_suffixes);203 count = eat_num(&negative_N, p); 101 204 break; 102 205 default: … … 111 214 112 215 fmt = header_fmt_str + 1; 113 #if ENABLE_FEATURE_FANCY_HEAD114 216 if (argc <= header_threshhold) { 217 #if ENABLE_FEATURE_FANCY_HEAD 115 218 header_threshhold = 0; 116 }117 219 #else 118 if (argc <= 1) {119 220 fmt += 11; /* "" */ 120 } 121 /* Now define some things here to avoid #ifdefs in the code below.122 * These should optimize out of the if conditions below. */123 #define header_threshhold 1 124 #define count_bytes 0 125 #endif 221 #endif 222 } 223 if (negative_N) { 224 if (count >= INT_MAX / sizeof(char*)) 225 bb_error_msg("count is too big: %lu", count); 226 } 126 227 127 228 do { … … 134 235 printf(fmt, *argv); 135 236 } 136 i = count; 137 while (i && ((c = getc(fp)) != EOF)) { 138 if (count_bytes || (c == '\n')) { 139 --i; 237 if (negative_N) { 238 if (count_bytes) { 239 print_except_N_last_bytes(fp, count); 240 } else { 241 print_except_N_last_lines(fp, count); 140 242 } 141 putchar(c); 142 } 243 } else { 244 print_first_N(fp, count, count_bytes); 245 } 246 die_if_ferror_stdout(); 143 247 if (fclose_if_not_stdin(fp)) { 144 248 bb_simple_perror_msg(*argv); 145 249 retval = EXIT_FAILURE; 146 250 } 147 die_if_ferror_stdout();148 251 } else { 149 252 retval = EXIT_FAILURE; -
branches/3.3/mindi-busybox/coreutils/hostid.c
r3232 r3621 37 37 } 38 38 39 printf("%08lx\n", gethostid()); 39 /* POSIX says gethostid returns a "32-bit identifier" */ 40 printf("%08x\n", (unsigned)(uint32_t)gethostid()); 40 41 41 42 return fflush_all(); -
branches/3.3/mindi-busybox/coreutils/id.c
r3232 r3621 65 65 66 66 #if !ENABLE_USE_BB_PWD_GRP 67 #if defined(__UCLIBC_MAJOR__) && (__UCLIBC_MAJOR__ == 0) 68 #if (__UCLIBC_MINOR__ < 9) || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ < 30) 67 #if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 30) 69 68 #error "Sorry, you need at least uClibc version 0.9.30 for id applet to build" 70 #endif71 69 #endif 72 70 #endif -
branches/3.3/mindi-busybox/coreutils/install.c
r3232 r3621 9 9 /* -v, -b, -c are ignored */ 10 10 //usage:#define install_trivial_usage 11 //usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [ SOURCE]... DEST"11 //usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST" 12 12 //usage:#define install_full_usage "\n\n" 13 13 //usage: "Copy files and set attributes\n" … … 20 20 //usage: "\n -g GRP Set group ownership" 21 21 //usage: "\n -m MODE Set permissions" 22 //usage: "\n -t DIR Install to DIR" 22 23 //usage: IF_SELINUX( 23 24 //usage: "\n -Z Set security context" … … 29 30 #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS 30 31 static const char install_longopts[] ALIGN1 = 32 IF_FEATURE_VERBOSE( 33 "verbose\0" No_argument "v" 34 ) 31 35 "directory\0" No_argument "d" 32 36 "preserve-timestamps\0" No_argument "p" … … 35 39 "mode\0" Required_argument "m" 36 40 "owner\0" Required_argument "o" 41 "target-directory\0" Required_argument "t" 37 42 /* autofs build insists of using -b --suffix=.orig */ 38 43 /* TODO? (short option for --suffix is -S) */ … … 90 95 const char *uid_str; 91 96 const char *mode_str; 97 int mkdir_flags = FILEUTILS_RECUR; 92 98 int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; 93 99 int opts; 94 int min_args = 1;95 100 int ret = EXIT_SUCCESS; 96 int isdir = 0;101 int isdir; 97 102 #if ENABLE_SELINUX 98 103 security_context_t scontext; … … 110 115 OPT_MODE = 1 << 8, 111 116 OPT_OWNER = 1 << 9, 112 #if ENABLE_SELINUX 113 OPT_SET_SECURITY_CONTEXT = 1 << 10, 114 OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11, 117 OPT_TARGET = 1 << 10, 118 #if ENABLE_SELINUX 119 OPT_SET_SECURITY_CONTEXT = 1 << 11, 120 OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12, 115 121 #endif 116 122 }; … … 119 125 applet_long_options = install_longopts; 120 126 #endif 121 opt_complementary = " s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));127 opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")); 122 128 /* -c exists for backwards compatibility, it's needed */ 123 /* -v is ignored ("print name of each created directory") */124 129 /* -b is ignored ("make a backup of each existing destination file") */ 125 opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"), 126 &gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext)); 130 opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), 131 &gid_str, &mode_str, &uid_str, &last 132 IF_SELINUX(, &scontext)); 127 133 argc -= optind; 128 134 argv += optind; … … 142 148 #endif 143 149 150 if ((opts & OPT_v) && FILEUTILS_VERBOSE) { 151 mkdir_flags |= FILEUTILS_VERBOSE; 152 copy_flags |= FILEUTILS_VERBOSE; 153 } 154 144 155 /* preserve access and modification time, this is GNU behaviour, 145 156 * BSD only preserves modification time */ … … 149 160 mode = 0755; /* GNU coreutils 6.10 compat */ 150 161 if (opts & OPT_MODE) 151 bb_parse_mode(mode_str, &mode);162 mode = bb_parse_mode(mode_str, mode); 152 163 uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid(); 153 164 gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid(); 154 165 155 last = argv[argc - 1]; 156 if (!(opts & OPT_DIRECTORY)) { 157 argv[argc - 1] = NULL; 158 min_args++; 159 166 /* If -t DIR is in use, then isdir=true, last="DIR" */ 167 isdir = (opts & OPT_TARGET); 168 if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) { 169 /* Neither -t DIR nor -d is in use */ 170 argc--; 171 last = argv[argc]; 172 argv[argc] = NULL; 160 173 /* coreutils install resolves link in this case, don't use lstat */ 161 174 isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode); 162 175 } 163 176 164 if (argc < min_args)177 if (argc < 1) 165 178 bb_show_usage(); 166 179 167 180 while ((arg = *argv++) != NULL) { 168 char *dest = last; 181 char *dest; 182 169 183 if (opts & OPT_DIRECTORY) { 170 184 dest = arg; … … 172 186 * on intermediate created directories 173 187 * (only on last one) */ 174 if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {188 if (bb_make_directory(dest, 0755, mkdir_flags)) { 175 189 ret = EXIT_FAILURE; 176 190 goto next; 177 191 } 178 192 } else { 193 dest = last; 179 194 if (opts & OPT_MKDIR_LEADING) { 180 195 char *ddir = xstrdup(dest); 181 bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);196 bb_make_directory(dirname(ddir), 0755, mkdir_flags); 182 197 /* errors are not checked. copy_file 183 198 * will fail if dir is not created. */ -
branches/3.3/mindi-busybox/coreutils/libcoreutils/getopt_mk_fifo_nod.c
r2725 r3621 34 34 opt = getopt32(argv, "m:" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext)); 35 35 if (opt & 1) { 36 if (bb_parse_mode(smode, &mode)) 36 mode = bb_parse_mode(smode, mode); 37 if (mode != (mode_t)-1) /* if mode is valid */ 38 /* make future mknod/mkfifo set mode bits exactly */ 37 39 umask(0); 38 40 } -
branches/3.3/mindi-busybox/coreutils/ln.c
r3232 r3621 135 135 136 136 free(src_name); 137 138 137 } while ((++argv)[1]); 139 138 -
branches/3.3/mindi-busybox/coreutils/ls.c
r3232 r3621 94 94 95 95 #include "libbb.h" 96 #include "common_bufsiz.h" 96 97 #include "unicode.h" 97 98 … … 366 367 #endif 367 368 } FIX_ALIASING; 368 #define G (*(struct globals*) &bb_common_bufsiz1)369 #define G (*(struct globals*)bb_common_bufsiz1) 369 370 #define INIT_G() do { \ 371 setup_common_bufsiz(); \ 370 372 /* we have to zero it out because of NOEXEC */ \ 371 373 memset(&G, 0, sizeof(G)); \ … … 567 569 if (G.all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) { 568 570 char *filetime; 569 time_t ttime =dn->dn_mtime;571 const time_t *ttime = &dn->dn_mtime; 570 572 if (G.all_fmt & TIME_ACCESS) 571 ttime = dn->dn_atime;573 ttime = &dn->dn_atime; 572 574 if (G.all_fmt & TIME_CHANGE) 573 ttime = dn->dn_ctime;574 filetime = ctime( &ttime);575 ttime = &dn->dn_ctime; 576 filetime = ctime(ttime); 575 577 /* filetime's format: "Wed Jun 30 21:49:08 1993\n" */ 576 578 if (G.all_fmt & LIST_FULLTIME) { /* -e */ … … 581 583 } else { /* LIST_DATE_TIME */ 582 584 /* G.current_time_t ~== time(NULL) */ 583 time_t age = G.current_time_t - ttime; 584 printf("%.6s ", filetime + 4); /* "Jun 30" */ 585 time_t age = G.current_time_t - *ttime; 585 586 if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) { 586 /* hh:mm if less than 6 months old */ 587 printf("%.5s ", filetime + 11); 588 } else { /* year. buggy if year > 9999 ;) */ 589 printf(" %.4s ", filetime + 20); 587 /* less than 6 months old */ 588 /* "mmm dd hh:mm " */ 589 printf("%.12s ", filetime + 4); 590 } else { 591 /* "mmm dd yyyy " */ 592 /* "mmm dd yyyyy " after year 9999 :) */ 593 strchr(filetime + 20, '\n')[0] = ' '; 594 printf("%.7s%6s", filetime + 4, filetime + 20); 590 595 } 591 596 column += 13; … … 666 671 column_width = len; 667 672 } 668 column_width += 1+673 column_width += 2 + 669 674 IF_SELINUX( ((G.all_fmt & LIST_CONTEXT) ? 33 : 0) + ) 670 675 ((G.all_fmt & LIST_INO) ? 8 : 0) + … … 694 699 if (column > 0) { 695 700 nexttab -= column; 696 printf("%*s 697 column += nexttab + 1;701 printf("%*s", nexttab, ""); 702 column += nexttab; 698 703 } 699 704 nexttab = column + column_width; … … 1033 1038 subdnp = scan_one_dir((*dn)->fullname, &nfiles); 1034 1039 #if ENABLE_DESKTOP 1035 if ((G.all_fmt & STYLE_MASK) == STYLE_LONG )1040 if ((G.all_fmt & STYLE_MASK) == STYLE_LONG || (G.all_fmt & LIST_BLOCKS)) 1036 1041 printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp)); 1037 1042 #endif … … 1103 1108 #if ENABLE_FEATURE_AUTOWIDTH 1104 1109 /* obtain the terminal width */ 1105 get_terminal_width_height(STDIN_FILENO, &G_terminal_width, NULL);1110 G_terminal_width = get_terminal_width(STDIN_FILENO); 1106 1111 /* go one less... */ 1107 1112 G_terminal_width--; -
branches/3.3/mindi-busybox/coreutils/md5_sha1_sum.c
r3232 r3621 152 152 } 153 153 hash_value = NULL; 154 if (count == 0) { 154 if (count < 0) 155 bb_perror_msg("can't read '%s'", filename); 156 else /* count == 0 */ { 155 157 final(&context, in_buf); 156 158 hash_value = hash_bin_to_hex(in_buf, hash_len); -
branches/3.3/mindi-busybox/coreutils/mkdir.c
r3232 r3621 49 49 "context\0" Required_argument "Z" 50 50 #endif 51 #if ENABLE_FEATURE_VERBOSE 51 52 "verbose\0" No_argument "v" 53 #endif 52 54 ; 53 55 #endif … … 68 70 applet_long_options = mkdir_longopts; 69 71 #endif 70 opt = getopt32(argv, "m:p " IF_SELINUX("Z:") "v", &smode IF_SELINUX(,&scontext));72 opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext)); 71 73 if (opt & 1) { 72 mode_t mmode = 0777;73 if ( !bb_parse_mode(smode, &mmode)) {74 mode_t mmode = bb_parse_mode(smode, 0777); 75 if (mmode == (mode_t)-1) { 74 76 bb_error_msg_and_die("invalid mode '%s'", smode); 75 77 } … … 78 80 if (opt & 2) 79 81 flags |= FILEUTILS_RECUR; 82 if ((opt & 4) && FILEUTILS_VERBOSE) 83 flags |= FILEUTILS_VERBOSE; 80 84 #if ENABLE_SELINUX 81 if (opt & 4) {85 if (opt & 8) { 82 86 selinux_or_die(); 83 87 setfscreatecon_or_die(scontext); -
branches/3.3/mindi-busybox/coreutils/mv.c
r3232 r3621 34 34 "force\0" No_argument "f" 35 35 "no-clobber\0" No_argument "n" 36 IF_FEATURE_VERBOSE( 36 37 "verbose\0" No_argument "v" 38 ) 37 39 ; 38 40 #endif … … 41 43 #define OPT_INTERACTIVE (1 << 1) 42 44 #define OPT_NOCLOBBER (1 << 2) 45 #define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE) 46 43 47 44 48 int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 59 63 * If more than one of -f, -i, -n is specified , only the final one 60 64 * takes effect (it unsets previous options). 61 * -v is accepted but ignored.62 65 */ 63 66 opt_complementary = "-2:f-in:i-fn:n-fi"; … … 149 152 } 150 153 RET_0: 154 if (flags & OPT_VERBOSE) { 155 printf("'%s' -> '%s'\n", *argv, dest); 156 } 151 157 if (dest != last) { 152 158 free((void *) dest); -
branches/3.3/mindi-busybox/coreutils/od_bloaty.c
r3232 r3621 21 21 22 22 /* #include "libbb.h" - done in od.c */ 23 #include "common_bufsiz.h" 23 24 #define assert(a) ((void)0) 24 25 … … 67 68 /* but in coreutils 6.3 it was renamed and now has */ \ 68 69 /* _mandatory_ parameter */ \ 69 &str_A, &str_N, &str_j, &lst_t, &str_S, & bytes_per_block)70 &str_A, &str_N, &str_j, &lst_t, &str_S, &G.bytes_per_block) 70 71 71 72 … … 175 176 }; 176 177 177 static smallint exit_code; 178 179 static unsigned string_min; 180 181 /* An array of specs describing how to format each input block. */ 182 static size_t n_specs; 183 static struct tspec *spec; 184 185 /* Function that accepts an address and an optional following char, 186 and prints the address and char to stdout. */ 187 static void (*format_address)(off_t, char); 188 /* The difference between the old-style pseudo starting address and 189 the number of bytes to skip. */ 178 struct globals { 179 smallint exit_code; 180 181 unsigned string_min; 182 183 /* An array of specs describing how to format each input block. */ 184 unsigned n_specs; 185 struct tspec *spec; 186 187 /* Function that accepts an address and an optional following char, 188 and prints the address and char to stdout. */ 189 void (*format_address)(off_t, char); 190 191 /* The difference between the old-style pseudo starting address and 192 the number of bytes to skip. */ 190 193 #if ENABLE_LONG_OPTS 191 static off_t pseudo_offset; 192 #else 193 enum { pseudo_offset = 0 }; 194 #endif 195 /* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all 196 input is formatted. */ 197 198 /* The number of input bytes formatted per output line. It must be 199 a multiple of the least common multiple of the sizes associated with 200 the specified output types. It should be as large as possible, but 201 no larger than 16 -- unless specified with the -w option. */ 202 static unsigned bytes_per_block = 32; /* have to use unsigned, not size_t */ 203 204 /* A NULL-terminated list of the file-arguments from the command line. */ 205 static const char *const *file_list; 206 207 /* The input stream associated with the current file. */ 208 static FILE *in_stream; 194 off_t pseudo_offset; 195 # define G_pseudo_offset G.pseudo_offset 196 #endif 197 /* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all 198 input is formatted. */ 199 200 /* The number of input bytes formatted per output line. It must be 201 a multiple of the least common multiple of the sizes associated with 202 the specified output types. It should be as large as possible, but 203 no larger than 16 -- unless specified with the -w option. */ 204 unsigned bytes_per_block; /* have to use unsigned, not size_t */ 205 206 /* A NULL-terminated list of the file-arguments from the command line. */ 207 const char *const *file_list; 208 209 /* The input stream associated with the current file. */ 210 FILE *in_stream; 211 212 bool not_first; 213 bool prev_pair_equal; 214 } FIX_ALIASING; 215 #if !ENABLE_LONG_OPTS 216 enum { G_pseudo_offset = 0 }; 217 #endif 218 #define G (*(struct globals*)bb_common_bufsiz1) 219 #define INIT_G() do { \ 220 setup_common_bufsiz(); \ 221 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 222 G.bytes_per_block = 32; \ 223 } while (0) 224 209 225 210 226 #define MAX_INTEGRAL_TYPE_SIZE sizeof(ulonglong_t) … … 388 404 }; 389 405 // buf[N] pos: 01234 56789 390 char buf[12] = " x\0 0xx\0"; 391 // actually " x\0 xxx\0", but want to share string with print_ascii. 406 char buf[12] = " x\0 xxx\0"; 392 407 // [12] because we take three 32bit stack slots anyway, and 393 408 // gcc is too dumb to initialize with constant stores, 394 409 // it copies initializer from rodata. Oh well. 410 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65410 395 411 396 412 while (n_bytes--) { … … 420 436 { 421 437 // buf[N] pos: 01234 56789 422 char buf[12] = " x\0 0xx\0";438 char buf[12] = " x\0 xxx\0"; 423 439 424 440 while (n_bytes--) { … … 456 472 s = " \\v"; 457 473 break; 458 case '\x7f': 459 s = " 177"; 460 break; 461 default: /* c is never larger than 040 */ 462 buf[7] = (c >> 3) + '0'; 474 default: 475 buf[6] = (c >> 6 & 3) + '0'; 476 buf[7] = (c >> 3 & 7) + '0'; 463 477 buf[8] = (c & 7) + '0'; 464 478 s = buf + 5; … … 479 493 { 480 494 while (1) { 481 if (!* file_list)495 if (!*G.file_list) 482 496 return; 483 in_stream = fopen_or_warn_stdin(*file_list++);484 if ( in_stream) {485 break; 486 } 487 exit_code = 1;497 G.in_stream = fopen_or_warn_stdin(*G.file_list++); 498 if (G.in_stream) { 499 break; 500 } 501 G.exit_code = 1; 488 502 } 489 503 490 504 if ((option_mask32 & (OPT_N|OPT_S)) == OPT_N) 491 setbuf( in_stream, NULL);505 setbuf(G.in_stream, NULL); 492 506 } 493 507 … … 502 516 check_and_close(void) 503 517 { 504 if ( in_stream) {505 if (ferror( in_stream)) {506 bb_error_msg("%s: read error", ( in_stream == stdin)518 if (G.in_stream) { 519 if (ferror(G.in_stream)) { 520 bb_error_msg("%s: read error", (G.in_stream == stdin) 507 521 ? bb_msg_standard_input 508 : file_list[-1]522 : G.file_list[-1] 509 523 ); 510 exit_code = 1;511 } 512 fclose_if_not_stdin( in_stream);513 in_stream = NULL;524 G.exit_code = 1; 525 } 526 fclose_if_not_stdin(G.in_stream); 527 G.in_stream = NULL; 514 528 } 515 529 … … 747 761 assert(s != next); 748 762 s = next; 749 spec = xrealloc_vector(spec, 4,n_specs);750 memcpy(& spec[n_specs], &tspec, sizeof(spec[0]));751 n_specs++;763 G.spec = xrealloc_vector(G.spec, 4, G.n_specs); 764 memcpy(&G.spec[G.n_specs], &tspec, sizeof(G.spec[0])); 765 G.n_specs++; 752 766 } 753 767 } … … 766 780 return; 767 781 768 while ( in_stream) { /* !EOF */782 while (G.in_stream) { /* !EOF */ 769 783 struct stat file_stats; 770 784 … … 784 798 as large as the size of the current file, we can 785 799 decrement n_skip and go on to the next file. */ 786 if (fstat(fileno( in_stream), &file_stats) == 0800 if (fstat(fileno(G.in_stream), &file_stats) == 0 787 801 && S_ISREG(file_stats.st_mode) && file_stats.st_size > 0 788 802 ) { … … 791 805 /* take "check & close / open_next" route */ 792 806 } else { 793 if (fseeko( in_stream, n_skip, SEEK_CUR) != 0)794 exit_code = 1;807 if (fseeko(G.in_stream, n_skip, SEEK_CUR) != 0) 808 G.exit_code = 1; 795 809 return; 796 810 } … … 805 819 if (n_skip < n_bytes_to_read) 806 820 n_bytes_to_read = n_skip; 807 n_bytes_read = fread(buf, 1, n_bytes_to_read, in_stream);821 n_bytes_read = fread(buf, 1, n_bytes_to_read, G.in_stream); 808 822 n_skip -= n_bytes_read; 809 823 if (n_bytes_read != n_bytes_to_read) … … 858 872 { 859 873 format_address_std(address, ' '); 860 format_address_paren(address + pseudo_offset, c);874 format_address_paren(address + G_pseudo_offset, c); 861 875 } 862 876 #endif … … 889 903 const char *prev_block, const char *curr_block) 890 904 { 891 static char first = 1; 892 static char prev_pair_equal = 0; 893 size_t i; 905 unsigned i; 894 906 895 907 if (!(option_mask32 & OPT_v) 896 && !first897 && n_bytes == bytes_per_block898 && memcmp(prev_block, curr_block, bytes_per_block) == 0908 && G.not_first 909 && n_bytes == G.bytes_per_block 910 && memcmp(prev_block, curr_block, G.bytes_per_block) == 0 899 911 ) { 900 if ( prev_pair_equal) {912 if (G.prev_pair_equal) { 901 913 /* The two preceding blocks were equal, and the current 902 914 block is the same as the last one, so print nothing. */ 903 915 } else { 904 916 puts("*"); 905 prev_pair_equal = 1;917 G.prev_pair_equal = 1; 906 918 } 907 919 } else { 908 first = 0;909 prev_pair_equal = 0;910 for (i = 0; i < n_specs; i++) {920 G.not_first = 1; 921 G.prev_pair_equal = 0; 922 for (i = 0; i < G.n_specs; i++) { 911 923 if (i == 0) 912 format_address(current_offset, '\0');924 G.format_address(current_offset, '\0'); 913 925 else 914 926 printf("%*s", address_pad_len_char - '0', ""); 915 (* spec[i].print_function) (n_bytes, curr_block,spec[i].fmt_string);916 if ( spec[i].hexl_mode_trailer) {927 (*G.spec[i].print_function) (n_bytes, curr_block, G.spec[i].fmt_string); 928 if (G.spec[i].hexl_mode_trailer) { 917 929 /* space-pad out to full line width, then dump the trailer */ 918 unsigned datum_width = width_bytes[ spec[i].size];919 unsigned blank_fields = ( bytes_per_block - n_bytes) / datum_width;920 unsigned field_width = spec[i].field_width + 1;930 unsigned datum_width = width_bytes[G.spec[i].size]; 931 unsigned blank_fields = (G.bytes_per_block - n_bytes) / datum_width; 932 unsigned field_width = G.spec[i].field_width + 1; 921 933 printf("%*s", blank_fields * field_width, ""); 922 934 dump_hexl_mode_trailer(n_bytes, curr_block); … … 930 942 read_block(size_t n, char *block, size_t *n_bytes_in_buffer) 931 943 { 932 assert(0 < n && n <= bytes_per_block);944 assert(0 < n && n <= G.bytes_per_block); 933 945 934 946 *n_bytes_in_buffer = 0; … … 937 949 return; 938 950 939 while ( in_stream != NULL) { /* EOF. */951 while (G.in_stream != NULL) { /* EOF. */ 940 952 size_t n_needed; 941 953 size_t n_read; 942 954 943 955 n_needed = n - *n_bytes_in_buffer; 944 n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, in_stream);956 n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, G.in_stream); 945 957 *n_bytes_in_buffer += n_read; 946 958 if (n_read == n_needed) … … 961 973 int l_c_m = 1; 962 974 963 for (i = 0; i < n_specs; i++)964 l_c_m = lcm(l_c_m, width_bytes[(int) spec[i].size]);975 for (i = 0; i < G.n_specs; i++) 976 l_c_m = lcm(l_c_m, width_bytes[(int) G.spec[i].size]); 965 977 return l_c_m; 966 978 } … … 983 995 size_t n_bytes_read; 984 996 985 block[0] = xmalloc(2 * bytes_per_block);986 block[1] = block[0] + bytes_per_block;997 block[0] = xmalloc(2 * G.bytes_per_block); 998 block[1] = block[0] + G.bytes_per_block; 987 999 988 1000 idx = 0; … … 994 1006 break; 995 1007 } 996 n_needed = MIN(end_offset - current_offset, (off_t) bytes_per_block);1008 n_needed = MIN(end_offset - current_offset, (off_t) G.bytes_per_block); 997 1009 read_block(n_needed, block[idx], &n_bytes_read); 998 if (n_bytes_read < bytes_per_block)1010 if (n_bytes_read < G.bytes_per_block) 999 1011 break; 1000 assert(n_bytes_read == bytes_per_block);1012 assert(n_bytes_read == G.bytes_per_block); 1001 1013 write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]); 1002 1014 current_offset += n_bytes_read; … … 1005 1017 } else { 1006 1018 while (1) { 1007 read_block( bytes_per_block, block[idx], &n_bytes_read);1008 if (n_bytes_read < bytes_per_block)1019 read_block(G.bytes_per_block, block[idx], &n_bytes_read); 1020 if (n_bytes_read < G.bytes_per_block) 1009 1021 break; 1010 assert(n_bytes_read == bytes_per_block);1022 assert(n_bytes_read == G.bytes_per_block); 1011 1023 write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]); 1012 1024 current_offset += n_bytes_read; … … 1031 1043 } 1032 1044 1033 format_address(current_offset, '\n');1045 G.format_address(current_offset, '\n'); 1034 1046 1035 1047 if ((option_mask32 & OPT_N) && current_offset >= end_offset) … … 1062 1074 dump_strings(off_t address, off_t end_offset) 1063 1075 { 1064 unsigned bufsize = MAX(100, string_min);1076 unsigned bufsize = MAX(100, G.string_min); 1065 1077 unsigned char *buf = xmalloc(bufsize); 1066 1078 … … 1069 1081 int c; 1070 1082 1071 /* See if the next ' string_min' chars are all printing chars. */1083 /* See if the next 'G.string_min' chars are all printing chars. */ 1072 1084 tryline: 1073 if ((option_mask32 & OPT_N) && (end_offset - string_min <= address))1085 if ((option_mask32 & OPT_N) && (end_offset - G.string_min <= address)) 1074 1086 break; 1075 1087 i = 0; … … 1080 1092 } 1081 1093 1082 while ( in_stream) { /* !EOF */1083 c = fgetc( in_stream);1094 while (G.in_stream) { /* !EOF */ 1095 c = fgetc(G.in_stream); 1084 1096 if (c != EOF) 1085 1097 goto got_char; … … 1098 1110 } 1099 1111 1100 if (i < string_min) /* Too short! */1112 if (i < G.string_min) /* Too short! */ 1101 1113 goto tryline; 1102 1114 1103 1115 /* If we get here, the string is all printable and NUL-terminated */ 1104 1116 buf[i] = 0; 1105 format_address(address - i - 1, ' ');1117 G.format_address(address - i - 1, ' '); 1106 1118 1107 1119 for (i = 0; (c = buf[i]); i++) { … … 1121 1133 1122 1134 /* We reach this point only if we search through 1123 (max_bytes_to_format - string_min) bytes before reaching EOF. */1135 (max_bytes_to_format - G.string_min) bytes before reaching EOF. */ 1124 1136 check_and_close(); 1125 1137 ret: … … 1167 1179 int od_main(int argc UNUSED_PARAM, char **argv) 1168 1180 { 1169 static const struct suffix_mult bkm[] = {1170 { "b", 512 },1171 { "k", 1024 },1172 { "m", 1024*1024 },1173 { "", 0 }1174 };1175 1181 #if ENABLE_LONG_OPTS 1176 1182 static const char od_longopts[] ALIGN1 = … … 1199 1205 off_t max_bytes_to_format = 0; 1200 1206 1201 spec = NULL; 1202 format_address = format_address_std; 1207 INIT_G(); 1208 1209 /*G.spec = NULL; - already is */ 1210 G.format_address = format_address_std; 1203 1211 address_base_char = 'o'; 1204 1212 address_pad_len_char = '7'; … … 1226 1234 "'%c' (must be [doxn])", str_A[0]); 1227 1235 pos = p - doxn; 1228 if (pos == 3) format_address = format_address_none;1236 if (pos == 3) G.format_address = format_address_none; 1229 1237 address_base_char = doxn_address_base_char[pos]; 1230 1238 address_pad_len_char = doxn_address_pad_len_char[pos]; 1231 1239 } 1232 1240 if (opt & OPT_N) { 1233 max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm );1241 max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes); 1234 1242 } 1235 1243 if (opt & OPT_a) decode_format_string("a"); … … 1240 1248 if (opt & OPT_h) decode_format_string("x2"); 1241 1249 if (opt & OPT_i) decode_format_string("d2"); 1242 if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm );1250 if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes); 1243 1251 if (opt & OPT_l) decode_format_string("d4"); 1244 1252 if (opt & OPT_o) decode_format_string("o2"); … … 1249 1257 if (opt & OPT_s) decode_format_string("d2"); 1250 1258 if (opt & OPT_S) { 1251 string_min = xstrtou_sfx(str_S, 0, bkm);1259 G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes); 1252 1260 } 1253 1261 1254 1262 // Bloat: 1255 //if ((option_mask32 & OPT_S) && n_specs > 0)1263 //if ((option_mask32 & OPT_S) && G.n_specs > 0) 1256 1264 // bb_error_msg_and_die("no type may be specified when dumping strings"); 1257 1265 … … 1309 1317 1310 1318 if (pseudo_start >= 0) { 1311 if ( format_address == format_address_none) {1319 if (G.format_address == format_address_none) { 1312 1320 address_base_char = 'o'; 1313 1321 address_pad_len_char = '7'; 1314 format_address = format_address_paren;1322 G.format_address = format_address_paren; 1315 1323 } else { 1316 format_address = format_address_label;1324 G.format_address = format_address_label; 1317 1325 } 1318 pseudo_offset = pseudo_start - n_bytes_to_skip;1326 G_pseudo_offset = pseudo_start - n_bytes_to_skip; 1319 1327 } 1320 1328 } … … 1329 1337 } 1330 1338 1331 if ( n_specs == 0) {1339 if (G.n_specs == 0) { 1332 1340 decode_format_string("o2"); 1333 /* n_specs = 1; - done by decode_format_string */1341 /*G.n_specs = 1; - done by decode_format_string */ 1334 1342 } 1335 1343 … … 1337 1345 set the global pointer FILE_LIST so that it 1338 1346 references the null-terminated list of one name: "-". */ 1339 file_list = bb_argv_dash;1347 G.file_list = bb_argv_dash; 1340 1348 if (argv[0]) { 1341 1349 /* Set the global pointer FILE_LIST so that it 1342 1350 references the first file-argument on the command-line. */ 1343 file_list = (char const *const *) argv;1351 G.file_list = (char const *const *) argv; 1344 1352 } 1345 1353 … … 1348 1356 /* Skip over any unwanted header bytes */ 1349 1357 skip(n_bytes_to_skip); 1350 if (! in_stream)1358 if (!G.in_stream) 1351 1359 return EXIT_FAILURE; 1352 1360 … … 1355 1363 1356 1364 if (opt & OPT_w) { /* -w: width */ 1357 if (! bytes_per_block ||bytes_per_block % l_c_m != 0) {1365 if (!G.bytes_per_block || G.bytes_per_block % l_c_m != 0) { 1358 1366 bb_error_msg("warning: invalid width %u; using %d instead", 1359 (unsigned) bytes_per_block, l_c_m);1360 bytes_per_block = l_c_m;1367 (unsigned)G.bytes_per_block, l_c_m); 1368 G.bytes_per_block = l_c_m; 1361 1369 } 1362 1370 } else { 1363 bytes_per_block = l_c_m;1371 G.bytes_per_block = l_c_m; 1364 1372 if (l_c_m < DEFAULT_BYTES_PER_BLOCK) 1365 bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m;1373 G.bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m; 1366 1374 } 1367 1375 1368 1376 #ifdef DEBUG 1369 for (i = 0; i < n_specs; i++) {1377 for (i = 0; i < G.n_specs; i++) { 1370 1378 printf("%d: fmt=\"%s\" width=%d\n", 1371 1379 i, spec[i].fmt_string, width_bytes[spec[i].size]); … … 1381 1389 bb_perror_msg_and_die(bb_msg_standard_input); 1382 1390 1383 return exit_code;1384 } 1391 return G.exit_code; 1392 } -
branches/3.3/mindi-busybox/coreutils/printf.c
r3232 r3621 132 132 } 133 133 134 /* Handles %b */135 static voidprint_esc_string(const char *str)134 /* Handles %b; return 1 if output is to be short-circuited by \c */ 135 static int print_esc_string(const char *str) 136 136 { 137 137 char c; … … 146 146 } 147 147 } 148 else if (*str == 'c') { 149 return 1; 150 } 148 151 { 149 152 /* optimization: don't force arg to be on-stack, … … 156 159 putchar(c); 157 160 } 161 162 return 0; 158 163 } 159 164 … … 281 286 if (*f == 'b') { 282 287 if (*argv) { 283 print_esc_string(*argv); 288 if (print_esc_string(*argv)) 289 return saved_argv; /* causes main() to exit */ 284 290 ++argv; 285 291 } -
branches/3.3/mindi-busybox/coreutils/readlink.c
r3232 r3621 40 40 * -v, --verbose report error messages 41 41 * 42 * bbox supports: -f -n -v (fully), -q -s (accepts but ignores) 42 * bbox supports: -f (partially) -n -v (fully), -q -s (accepts but ignores) 43 * Note: we export the -f flag, but our -f behaves like coreutils' -e. 44 * Unfortunately, there isn't a C lib function we can leverage to get this 45 * behavior which means we'd have to implement the full stack ourselves :(. 43 46 */ 44 47 -
branches/3.3/mindi-busybox/coreutils/rm.c
r3232 r3621 39 39 40 40 opt_complementary = "f-i:i-f"; 41 /* -v (verbose) is ignored */42 41 opt = getopt32(argv, "fiRrv"); 43 42 argv += optind; … … 48 47 if (opt & (8|4)) 49 48 flags |= FILEUTILS_RECUR; 49 if ((opt & 16) && FILEUTILS_VERBOSE) 50 flags |= FILEUTILS_VERBOSE; 50 51 51 52 if (*argv != NULL) { -
branches/3.3/mindi-busybox/coreutils/rmdir.c
r3232 r3621 32 32 33 33 #define PARENTS (1 << 0) 34 //efine VERBOSE (1 << 1) //accepted but ignored 34 #define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE) 35 35 #define IGNORE_NON_EMPTY (1 << 2) 36 36 … … 45 45 static const char rmdir_longopts[] ALIGN1 = 46 46 "parents\0" No_argument "p" 47 "verbose\0" No_argument "v"48 47 /* Debian etch: many packages fail to be purged or installed 49 48 * because they desperately want this option: */ 50 49 "ignore-fail-on-non-empty\0" No_argument "\xff" 50 IF_FEATURE_VERBOSE( 51 "verbose\0" No_argument "v" 52 ) 51 53 ; 52 54 applet_long_options = rmdir_longopts; … … 63 65 64 66 while (1) { 67 if (flags & VERBOSE) { 68 printf("rmdir: removing directory, '%s'\n", path); 69 } 70 65 71 if (rmdir(path) < 0) { 66 72 #if ENABLE_FEATURE_RMDIR_LONG_OPTIONS -
branches/3.3/mindi-busybox/coreutils/sort.c
r3232 r3621 15 15 //usage:#define sort_trivial_usage 16 16 //usage: "[-nru" 17 //usage: IF_FEATURE_SORT_BIG("gMcszbdfi mSTokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR")17 //usage: IF_FEATURE_SORT_BIG("gMcszbdfiokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR") 18 18 //usage: "] [FILE]..." 19 19 //usage:#define sort_full_usage "\n\n" 20 20 //usage: "Sort lines of text\n" 21 21 //usage: IF_FEATURE_SORT_BIG( 22 //usage: "\n -o FILE Output to FILE" 23 //usage: "\n -c Check whether input is sorted" 22 24 //usage: "\n -b Ignore leading blanks" 23 //usage: "\n -c Check whether input is sorted" 25 //usage: "\n -f Ignore case" 26 //usage: "\n -i Ignore unprintable characters" 24 27 //usage: "\n -d Dictionary order (blank or alphanumeric only)" 25 //usage: "\n -f Ignore case"26 28 //usage: "\n -g General numerical sort" 27 //usage: "\n -i Ignore unprintable characters"28 //usage: "\n -k Sort key"29 29 //usage: "\n -M Sort month" 30 30 //usage: ) 31 //-h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G) 31 32 //usage: "\n -n Sort numbers" 32 33 //usage: IF_FEATURE_SORT_BIG( 33 //usage: "\n -o Output to file" 34 //usage: "\n -k Sort by key" 35 //usage: "\n -t CHAR Key separator" 34 //usage: "\n -t CHAR Field separator" 35 //usage: "\n -k N[,M] Sort by Nth field" 36 36 //usage: ) 37 37 //usage: "\n -r Reverse sort order" … … 42 42 //usage: IF_FEATURE_SORT_BIG( 43 43 //usage: "\n -z Lines are terminated by NUL, not newline" 44 //usage: "\n -mST Ignored for GNU compatibility") 44 ////usage: "\n -m Ignored for GNU compatibility" 45 ////usage: "\n -S BUFSZ Ignored for GNU compatibility" 46 ////usage: "\n -T TMPDIR Ignored for GNU compatibility" 47 //usage: ) 45 48 //usage: 46 49 //usage:#define sort_example_usage … … 107 110 static char *get_key(char *str, struct sort_key *key, int flags) 108 111 { 109 int start = 0, end = 0, len, j; 112 int start = start; /* for compiler */ 113 int end; 114 int len, j; 110 115 unsigned i; 111 116 … … 124 129 /* Loop through fields */ 125 130 else { 131 unsigned char ch = 0; 132 126 133 end = 0; 127 134 for (i = 1; i < key->range[2*j] + j; i++) { 128 135 if (key_separator) { 129 136 /* Skip body of key and separator */ 130 while (str[end]) { 131 if (str[end++] == key_separator) 137 while ((ch = str[end]) != '\0') { 138 end++; 139 if (ch == key_separator) 132 140 break; 133 141 } … … 137 145 end++; 138 146 /* Skip body of key */ 139 while (str[end] ) {147 while (str[end] != '\0') { 140 148 if (isspace(str[end])) 141 149 break; … … 144 152 } 145 153 } 154 /* Remove last delim: "abc:def:" => "abc:def" */ 155 if (j && ch) { 156 //if (str[end-1] != key_separator) 157 // bb_error_msg(_and_die("BUG! " 158 // "str[start:%d,end:%d]:'%.*s'", 159 // start, end, (int)(end-start), &str[start]); 160 end--; 161 } 146 162 } 147 163 if (!j) start = end; 148 164 } 149 165 /* Strip leading whitespace if necessary */ 150 //XXX: skip_whitespace()151 166 if (flags & FLAG_b) 167 /* not using skip_whitespace() for speed */ 152 168 while (isspace(str[start])) start++; 153 169 /* Strip trailing whitespace if necessary */ 154 170 if (flags & FLAG_bb) 155 171 while (end > start && isspace(str[end-1])) end--; 156 /* Handle offsets on start and end*/172 /* -kSTART,N.ENDCHAR: honor ENDCHAR (1-based) */ 157 173 if (key->range[3]) { 158 end += key->range[3] - 1;174 end = key->range[3]; 159 175 if (end > len) end = len; 160 176 } 177 /* -kN.STARTCHAR[,...]: honor STARTCHAR (1-based) */ 161 178 if (key->range[1]) { 162 179 start += key->range[1] - 1; … … 164 181 } 165 182 /* Make the copy */ 166 if (end < start) end = start; 183 if (end < start) 184 end = start; 167 185 str = xstrndup(str+start, end-start); 168 186 /* Handle -d */ … … 226 244 #endif 227 245 /* Perform actual comparison */ 228 switch (flags & 7) {246 switch (flags & (FLAG_n | FLAG_M | FLAG_g)) { 229 247 default: 230 248 bb_error_msg_and_die("unknown sort type"); … … 278 296 retval = 1; 279 297 else 280 retval = (dx == thyme.tm_mon) ? 0 :dx - thyme.tm_mon;298 retval = dx - thyme.tm_mon; 281 299 break; 282 300 } … … 303 321 304 322 /* Perform fallback sort if necessary */ 305 if (!retval && !(option_mask32 & FLAG_s)) 323 if (!retval && !(option_mask32 & FLAG_s)) { 324 flags = option_mask32; 306 325 retval = strcmp(*(char **)xarg, *(char **)yarg); 307 308 if (flags & FLAG_r) return -retval; 326 } 327 328 if (flags & FLAG_r) 329 return -retval; 330 309 331 return retval; 310 332 } … … 329 351 char *str_ignored, *str_o, *str_t; 330 352 llist_t *lst_k = NULL; 331 int i , flag;353 int i; 332 354 int linecount; 333 355 unsigned opts; … … 352 374 * since that reduces register pressure and makes code smaller */ 353 375 354 /* parse sort key */376 /* Parse sort key */ 355 377 while (lst_k) { 356 378 enum { … … 379 401 } 380 402 while (*str_k) { 381 const char *temp2; 403 int flag; 404 const char *idx; 382 405 383 406 if (*str_k == ',' && !i++) { … … 386 409 } /* no else needed: fall through to syntax error 387 410 because comma isn't in OPT_STR */ 388 temp2= strchr(OPT_STR, *str_k);389 if (! temp2)411 idx = strchr(OPT_STR, *str_k); 412 if (!idx) 390 413 bb_error_msg_and_die("unknown key option"); 391 flag = 1 << ( temp2- OPT_STR);414 flag = 1 << (idx - OPT_STR); 392 415 if (flag & ~FLAG_allowed_for_k) 393 416 bb_error_msg_and_die("unknown sort type"); … … 423 446 424 447 #if ENABLE_FEATURE_SORT_BIG 425 /* if no key, perform alphabetic sort */448 /* If no key, perform alphabetic sort */ 426 449 if (!key_list) 427 450 add_key()->range[0] = 1; 428 /* handle -c */451 /* Handle -c */ 429 452 if (option_mask32 & FLAG_c) { 430 453 int j = (option_mask32 & FLAG_u) ? -1 : 0; … … 440 463 /* Perform the actual sort */ 441 464 qsort(lines, linecount, sizeof(lines[0]), compare_keys); 442 /* handle -u */ 465 466 /* Handle -u */ 443 467 if (option_mask32 & FLAG_u) { 444 flag= 0;468 int j = 0; 445 469 /* coreutils 6.3 drop lines for which only key is the same */ 446 470 /* -- disabling last-resort compare... */ 447 471 option_mask32 |= FLAG_s; 448 472 for (i = 1; i < linecount; i++) { 449 if (compare_keys(&lines[ flag], &lines[i]) == 0)473 if (compare_keys(&lines[j], &lines[i]) == 0) 450 474 free(lines[i]); 451 475 else 452 lines[++ flag] = lines[i];476 lines[++j] = lines[i]; 453 477 } 454 478 if (linecount) 455 linecount = flag+1;479 linecount = j+1; 456 480 } 457 481 … … 462 486 xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO); 463 487 #endif 464 flag = (option_mask32 & FLAG_z) ? '\0' : '\n'; 465 for (i = 0; i < linecount; i++) 466 printf("%s%c", lines[i], flag); 488 { 489 int ch = (option_mask32 & FLAG_z) ? '\0' : '\n'; 490 for (i = 0; i < linecount; i++) 491 printf("%s%c", lines[i], ch); 492 } 467 493 468 494 fflush_stdout_and_exit(EXIT_SUCCESS); -
branches/3.3/mindi-busybox/coreutils/split.c
r3232 r3621 23 23 24 24 #include "libbb.h" 25 #include "common_bufsiz.h" 25 26 26 static const struct suffix_mult split_suffices[] = {27 27 #if ENABLE_FEATURE_SPLIT_FANCY 28 static const struct suffix_mult split_suffixes[] = { 28 29 { "b", 512 }, 29 #endif30 30 { "k", 1024 }, 31 31 { "m", 1024*1024 }, 32 #if ENABLE_FEATURE_SPLIT_FANCY33 32 { "g", 1024*1024*1024 }, 34 #endif35 33 { "", 0 } 36 34 }; 35 #endif 37 36 38 37 /* Increment the suffix part of the filename. … … 81 80 char *src; 82 81 82 setup_common_bufsiz(); 83 83 84 opt_complementary = "?2:a+"; /* max 2 args; -a N */ 84 85 opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); … … 87 88 cnt = XATOOFF(count_p); 88 89 if (opt & SPLIT_OPT_b) // FIXME: also needs XATOOFF 89 cnt = xatoull_sfx(count_p, split_suffices); 90 cnt = xatoull_sfx(count_p, 91 IF_FEATURE_SPLIT_FANCY(split_suffixes) 92 IF_NOT_FEATURE_SPLIT_FANCY(km_suffixes) 93 ); 90 94 sfx = "x"; 91 95 -
branches/3.3/mindi-busybox/coreutils/stat.c
r3232 r3621 13 13 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 14 14 */ 15 //config:config STAT 16 //config: bool "stat" 17 //config: default y 18 //config: help 19 //config: display file or filesystem status. 20 //config: 21 //config:config FEATURE_STAT_FORMAT 22 //config: bool "Enable custom formats (-c)" 23 //config: default y 24 //config: depends on STAT 25 //config: help 26 //config: Without this, stat will not support the '-c format' option where 27 //config: users can pass a custom format string for output. This adds about 28 //config: 7k to a nonstatic build on amd64. 29 //config: 30 //config:config FEATURE_STAT_FILESYSTEM 31 //config: bool "Enable display of filesystem status (-f)" 32 //config: default y 33 //config: depends on STAT 34 //config: select PLATFORM_LINUX # statfs() 35 //config: help 36 //config: Without this, stat will not support the '-f' option to display 37 //config: information about filesystem status. 38 15 39 16 40 //usage:#define stat_trivial_usage 17 41 //usage: "[OPTIONS] FILE..." 18 42 //usage:#define stat_full_usage "\n\n" 19 //usage: "Display file (default) or filesystem status\n" 43 //usage: "Display file" 44 //usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem") 45 //usage: " status\n" 20 46 //usage: IF_FEATURE_STAT_FORMAT( 21 //usage: "\n -c fmtUse the specified format"47 //usage: "\n -c FMT Use the specified format" 22 48 //usage: ) 49 //usage: IF_FEATURE_STAT_FILESYSTEM( 23 50 //usage: "\n -f Display filesystem status" 51 //usage: ) 24 52 //usage: "\n -L Follow links" 25 //usage: "\n -t Display info in terse form"53 //usage: "\n -t Terse display" 26 54 //usage: IF_SELINUX( 27 55 //usage: "\n -Z Print security context" 28 56 //usage: ) 29 57 //usage: IF_FEATURE_STAT_FORMAT( 30 //usage: "\n\n Valid format sequences for files:\n"58 //usage: "\n\nFMT sequences"IF_FEATURE_STAT_FILESYSTEM(" for files")":\n" 31 59 //usage: " %a Access rights in octal\n" 32 60 //usage: " %A Access rights in human readable form\n" 33 61 //usage: " %b Number of blocks allocated (see %B)\n" 34 //usage: " %B The size in bytes of each block reported by %b\n"62 //usage: " %B Size in bytes of each block reported by %b\n" 35 63 //usage: " %d Device number in decimal\n" 36 64 //usage: " %D Device number in hex\n" 37 65 //usage: " %f Raw mode in hex\n" 38 66 //usage: " %F File type\n" 39 //usage: " %g Group ID of owner\n"40 //usage: " %G Group name of owner\n"67 //usage: " %g Group ID\n" 68 //usage: " %G Group name\n" 41 69 //usage: " %h Number of hard links\n" 42 70 //usage: " %i Inode number\n" … … 44 72 //usage: " %N File name, with -> TARGET if symlink\n" 45 73 //usage: " %o I/O block size\n" 46 //usage: " %s Total size ,in bytes\n"74 //usage: " %s Total size in bytes\n" 47 75 //usage: " %t Major device type in hex\n" 48 76 //usage: " %T Minor device type in hex\n" 49 //usage: " %u User ID of owner\n"50 //usage: " %U User name of owner\n"77 //usage: " %u User ID\n" 78 //usage: " %U User name\n" 51 79 //usage: " %x Time of last access\n" 52 80 //usage: " %X Time of last access as seconds since Epoch\n" … … 55 83 //usage: " %z Time of last change\n" 56 84 //usage: " %Z Time of last change as seconds since Epoch\n" 57 //usage: "\nValid format sequences for file systems:\n" 85 //usage: IF_FEATURE_STAT_FILESYSTEM( 86 //usage: "\nFMT sequences for file systems:\n" 58 87 //usage: " %a Free blocks available to non-superuser\n" 59 //usage: " %b Total data blocks in file system\n"60 //usage: " %c Total file nodes in file system\n"61 //usage: " %d Free file nodes in file system\n"62 //usage: " %f Free blocks in file system\n"88 //usage: " %b Total data blocks\n" 89 //usage: " %c Total file nodes\n" 90 //usage: " %d Free file nodes\n" 91 //usage: " %f Free blocks\n" 63 92 //usage: IF_SELINUX( 64 93 //usage: " %C Security context in selinux\n" … … 72 101 //usage: " %T Type in human readable form" 73 102 //usage: ) 103 //usage: ) 74 104 75 105 #include "libbb.h" 76 77 #define OPT_FILESYS (1 << 0) 78 #define OPT_TERSE (1 << 1) 79 #define OPT_DEREFERENCE (1 << 2) 80 #define OPT_SELINUX (1 << 3) 106 #include "common_bufsiz.h" 107 108 enum { 109 OPT_TERSE = (1 << 0), 110 OPT_DEREFERENCE = (1 << 1), 111 OPT_FILESYS = (1 << 2) * ENABLE_FEATURE_STAT_FILESYSTEM, 112 OPT_SELINUX = (1 << (2+ENABLE_FEATURE_STAT_FILESYSTEM)) * ENABLE_SELINUX, 113 }; 81 114 82 115 #if ENABLE_FEATURE_STAT_FORMAT … … 127 160 /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/ 128 161 #define buf bb_common_bufsiz1 129 130 str ftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t));162 setup_common_bufsiz(); 163 strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000"); 131 164 return buf; 132 165 #undef buf 133 166 } 134 167 168 #if ENABLE_FEATURE_STAT_FILESYSTEM 135 169 /* Return the type of the specified file system. 136 170 * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris) … … 203 237 return r; 204 238 } 239 #endif /* FEATURE_STAT_FILESYSTEM */ 205 240 206 241 #if ENABLE_FEATURE_STAT_FORMAT … … 218 253 } 219 254 255 #if ENABLE_FEATURE_STAT_FILESYSTEM 220 256 /* print statfs info */ 221 257 static void FAST_FUNC print_statfs(char *pformat, const char m, … … 264 300 } 265 301 } 302 #endif 266 303 267 304 /* print stat info */ … … 375 412 /* Create a working copy of the format string */ 376 413 char *format = xstrdup(masterformat); 377 /* Add 2 to accom odate our conversion of the stat '%s' format string414 /* Add 2 to accommodate our conversion of the stat '%s' format string 378 415 * to the printf '%llu' one. */ 379 416 char *dest = xmalloc(strlen(format) + 2 + 1); … … 424 461 #endif /* FEATURE_STAT_FORMAT */ 425 462 463 #if ENABLE_FEATURE_STAT_FILESYSTEM 426 464 /* Stat the file system and print what we find. */ 427 465 #if !ENABLE_FEATURE_STAT_FORMAT … … 539 577 return 1; 540 578 } 579 #endif /* FEATURE_STAT_FILESYSTEM */ 541 580 542 581 /* stat the file and print what we find */ … … 656 695 # if ENABLE_SELINUX 657 696 if (option_mask32 & OPT_SELINUX) 658 printf(" % lc\n", *scontext);697 printf(" %s\n", scontext); 659 698 else 660 699 bb_putchar('\n'); … … 701 740 (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN"); 702 741 # if ENABLE_SELINUX 703 printf(" S_Context: %lc\n", *scontext); 742 if (option_mask32 & OPT_SELINUX) 743 printf(" S_Context: %s\n", scontext); 704 744 # endif 705 745 printf("Access: %s\n", human_time(statbuf.st_atime)); … … 721 761 722 762 opt_complementary = "-1"; /* min one arg */ 723 opts = getopt32(argv, "ftL" 763 opts = getopt32(argv, "tL" 764 IF_FEATURE_STAT_FILESYSTEM("f") 724 765 IF_SELINUX("Z") 725 766 IF_FEATURE_STAT_FORMAT("c:", &format) 726 767 ); 768 #if ENABLE_FEATURE_STAT_FILESYSTEM 727 769 if (opts & OPT_FILESYS) /* -f */ 728 770 statfunc = do_statfs; 771 #endif 729 772 #if ENABLE_SELINUX 730 773 if (opts & OPT_SELINUX) { -
branches/3.3/mindi-busybox/coreutils/stty.c
r3232 r3621 33 33 34 34 #include "libbb.h" 35 #include "common_bufsiz.h" 35 36 36 37 #ifndef _POSIX_VDISABLE … … 247 248 /* Which member(s) of 'struct termios' a mode uses */ 248 249 enum { 249 /* Do NOT change the order or values, as mode_type_flag()250 * depends on them */251 250 control, input, output, local, combination 252 251 }; 252 static tcflag_t *get_ptr_to_tcflag(unsigned type, const struct termios *mode) 253 { 254 static const uint8_t tcflag_offsets[] ALIGN1 = { 255 offsetof(struct termios, c_cflag), /* control */ 256 offsetof(struct termios, c_iflag), /* input */ 257 offsetof(struct termios, c_oflag), /* output */ 258 offsetof(struct termios, c_lflag) /* local */ 259 }; 260 if (type <= local) { 261 return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]); 262 } 263 return NULL; 264 } 253 265 254 266 /* Flags for 'struct mode_info' */ … … 307 319 308 320 /* Mode names given on command line */ 309 static const char mode_name[] =321 static const char mode_name[] ALIGN1 = 310 322 MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) 311 323 MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) … … 670 682 671 683 /* Name given on command line */ 672 static const char control_name[] =684 static const char control_name[] ALIGN1 = 673 685 CI_ENTRY("intr", CINTR, VINTR ) 674 686 CI_ENTRY("quit", CQUIT, VQUIT ) … … 712 724 #define CI_ENTRY(n,s,o) { s, o }, 713 725 714 static const struct control_info control_info[] = {726 static const struct control_info control_info[] ALIGN2 = { 715 727 /* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */ 716 728 CI_ENTRY("intr", CINTR, VINTR ) … … 765 777 char buf[10]; 766 778 } FIX_ALIASING; 767 #define G (*(struct globals*) &bb_common_bufsiz1)779 #define G (*(struct globals*)bb_common_bufsiz1) 768 780 #define INIT_G() do { \ 769 781 G.device_name = bb_msg_standard_input; \ 770 782 G.max_col = 80; \ 771 783 } while (0) 772 773 774 /* Return a string that is the printable representation of character CH */775 /* Adapted from 'cat' by Torbjorn Granlund */776 static const char *visible(unsigned ch)777 {778 char *bpout = G.buf;779 780 if (ch == _POSIX_VDISABLE)781 return "<undef>";782 783 if (ch >= 128) {784 ch -= 128;785 *bpout++ = 'M';786 *bpout++ = '-';787 }788 789 if (ch < 32) {790 *bpout++ = '^';791 *bpout++ = ch + 64;792 } else if (ch < 127) {793 *bpout++ = ch;794 } else {795 *bpout++ = '^';796 *bpout++ = '?';797 }798 799 *bpout = '\0';800 return G.buf;801 }802 803 static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)804 {805 static const uint8_t tcflag_offsets[] ALIGN1 = {806 offsetof(struct termios, c_cflag), /* control */807 offsetof(struct termios, c_iflag), /* input */808 offsetof(struct termios, c_oflag), /* output */809 offsetof(struct termios, c_lflag) /* local */810 };811 812 if (type <= local) {813 return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]);814 }815 return NULL;816 }817 784 818 785 static void set_speed_or_die(enum speed_setting type, const char *arg, … … 1043 1010 1044 1011 for (i = 0; i != CIDX_min; ++i) { 1012 char ch; 1045 1013 /* If swtch is the same as susp, don't print both */ 1046 1014 #if VSWTCH == VSUSP … … 1056 1024 } 1057 1025 #endif 1058 wrapf("%s = %s;", nth_string(control_name, i), 1059 visible(mode->c_cc[control_info[i].offset])); 1026 ch = mode->c_cc[control_info[i].offset]; 1027 if (ch == _POSIX_VDISABLE) 1028 strcpy(G.buf, "<undef>"); 1029 else 1030 visible(ch, G.buf, 0); 1031 wrapf("%s = %s;", nth_string(control_name, i), G.buf); 1060 1032 } 1061 1033 #if VEOF == VMIN … … 1073 1045 } 1074 1046 1075 bitsp = mode_type_flag(mode_info[i].type, mode);1047 bitsp = get_ptr_to_tcflag(mode_info[i].type, mode); 1076 1048 mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; 1077 1049 if ((*bitsp & mask) == mode_info[i].bits) { … … 1092 1064 { 1093 1065 int i; 1094 tcflag_t *bitsp;1095 1066 1096 1067 for (i = 0; i < NUM_control_info; ++i) { … … 1103 1074 1104 1075 for (i = 0; i < NUM_mode_info; ++i) { 1076 tcflag_t val; 1077 tcflag_t *bitsp = get_ptr_to_tcflag(mode_info[i].type, mode); 1078 1079 if (!bitsp) 1080 continue; 1081 val = *bitsp & ~((unsigned long)mode_info[i].mask); 1105 1082 if (mode_info[i].flags & SANE_SET) { 1106 bitsp = mode_type_flag(mode_info[i].type, mode); 1107 *bitsp = (*bitsp & ~((unsigned long)mode_info[i].mask)) 1108 | mode_info[i].bits; 1109 } else if (mode_info[i].flags & SANE_UNSET) { 1110 bitsp = mode_type_flag(mode_info[i].type, mode); 1111 *bitsp = *bitsp & ~((unsigned long)mode_info[i].mask) 1112 & ~mode_info[i].bits; 1083 *bitsp = val | mode_info[i].bits; 1084 } else 1085 if (mode_info[i].flags & SANE_UNSET) { 1086 *bitsp = val & ~mode_info[i].bits; 1113 1087 } 1114 1088 } … … 1120 1094 tcflag_t *bitsp; 1121 1095 1122 bitsp = mode_type_flag(info->type, mode);1096 bitsp = get_ptr_to_tcflag(info->type, mode); 1123 1097 1124 1098 if (bitsp) { 1099 tcflag_t val = *bitsp & ~info->mask; 1125 1100 if (reversed) 1126 *bitsp = *bitsp & ~info->mask& ~info->bits;1101 *bitsp = val & ~info->bits; 1127 1102 else 1128 *bitsp = (*bitsp & ~info->mask)| info->bits;1103 *bitsp = val | info->bits; 1129 1104 return; 1130 1105 } 1131 1106 1132 /* Combinationmode */1107 /* !bitsp - it's a "combination" mode */ 1133 1108 if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) { 1134 1109 if (reversed) … … 1430 1405 1431 1406 if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) { 1432 get_terminal_width_height(STDOUT_FILENO, &G.max_col, NULL);1407 G.max_col = get_terminal_width(STDOUT_FILENO); 1433 1408 output_func(&mode, display_all); 1434 1409 return EXIT_SUCCESS; … … 1535 1510 1536 1511 if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) { 1537 #if CIBAUD 1512 /* 1513 * I think the below chunk is not necessary on Linux. 1514 * If you are deleting it, also delete STTY_speed_was_set bit - 1515 * it is only ever checked here. 1516 */ 1517 #if 0 /* was "if CIBAUD" */ 1538 1518 /* SunOS 4.1.3 (at least) has the problem that after this sequence, 1539 1519 tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2); -
branches/3.3/mindi-busybox/coreutils/sum.c
r3232 r3621 22 22 23 23 #include "libbb.h" 24 #include "common_bufsiz.h" 24 25 25 26 enum { SUM_BSD, PRINT_NAME, SUM_SYSV }; … … 31 32 static unsigned sum_file(const char *file, unsigned type) 32 33 { 33 #define buf bb_common_bufsiz134 34 unsigned long long total_bytes = 0; 35 35 int fd, r; 36 36 /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ 37 37 unsigned s = 0; 38 39 #define buf bb_common_bufsiz1 40 setup_common_bufsiz(); 38 41 39 42 fd = open_or_warn_stdin(file); … … 42 45 43 46 while (1) { 44 size_t bytes_read = safe_read(fd, buf, BUFSIZ);47 size_t bytes_read = safe_read(fd, buf, COMMON_BUFSIZE); 45 48 46 49 if ((ssize_t)bytes_read <= 0) { … … 71 74 r = (s & 0xffff) + ((s & 0xffffffff) >> 16); 72 75 s = (r & 0xffff) + (r >> 16); 73 printf("% d%llu %s\n", s, (total_bytes + 511) / 512, file);76 printf("%u %llu %s\n", s, (total_bytes + 511) / 512, file); 74 77 } else 75 printf("%05 d%5llu %s\n", s, (total_bytes + 1023) / 1024, file);78 printf("%05u %5llu %s\n", s, (total_bytes + 1023) / 1024, file); 76 79 return 1; 77 80 #undef buf -
branches/3.3/mindi-busybox/coreutils/sync.c
r3232 r3621 4 4 * 5 5 * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. 6 * Copyright (C) 2015 by Ari Sundholm <ari@tuxera.com> 6 7 * 7 8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. … … 9 10 10 11 /* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ 12 //config:config SYNC 13 //config: bool "sync" 14 //config: default y 15 //config: help 16 //config: sync is used to flush filesystem buffers. 17 //config:config FEATURE_SYNC_FANCY 18 //config: bool "Enable -d and -f flags (requres syncfs(2) in libc)" 19 //config: default y 20 //config: depends on SYNC 21 //config: help 22 //config: sync -d FILE... executes fdatasync() on each FILE. 23 //config: sync -f FILE... executes syncfs() on each FILE. 24 25 //kbuild:lib-$(CONFIG_SYNC) += sync.o 26 //applet:IF_SYNC(APPLET_NOFORK(sync, sync, BB_DIR_BIN, BB_SUID_DROP, sync)) 11 27 12 28 //usage:#define sync_trivial_usage 13 //usage: "" 29 //usage: ""IF_FEATURE_SYNC_FANCY("[-df] [FILE]...") 14 30 //usage:#define sync_full_usage "\n\n" 31 //usage: IF_NOT_FEATURE_SYNC_FANCY( 15 32 //usage: "Write all buffered blocks to disk" 33 //usage: ) 34 //usage: IF_FEATURE_SYNC_FANCY( 35 //usage: "Write all buffered blocks (in FILEs) to disk" 36 //usage: "\n -d Avoid syncing metadata" 37 //usage: "\n -f Sync filesystems underlying FILEs" 38 //usage: ) 16 39 17 40 #include "libbb.h" … … 22 45 int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) 23 46 { 47 #if !ENABLE_FEATURE_SYNC_FANCY 24 48 /* coreutils-6.9 compat */ 25 49 bb_warn_ignoring_args(argv[1]); 50 sync(); 51 return EXIT_SUCCESS; 52 #else 53 unsigned opts; 54 int ret = EXIT_SUCCESS; 26 55 27 sync(); 56 enum { 57 OPT_DATASYNC = (1 << 0), 58 OPT_SYNCFS = (1 << 1), 59 }; 28 60 29 return EXIT_SUCCESS; 61 opt_complementary = "d--f:f--d"; 62 opts = getopt32(argv, "df"); 63 argv += optind; 64 65 /* Handle the no-argument case. */ 66 if (!argv[0]) 67 sync(); 68 69 while (*argv) { 70 int fd = open_or_warn(*argv, O_RDONLY); 71 72 if (fd < 0) { 73 ret = EXIT_FAILURE; 74 goto next; 75 } 76 if (opts & OPT_DATASYNC) { 77 if (fdatasync(fd)) 78 goto err; 79 goto do_close; 80 } 81 if (opts & OPT_SYNCFS) { 82 /* 83 * syncfs is documented to only fail with EBADF, 84 * which can't happen here. So, no error checks. 85 */ 86 syncfs(fd); 87 goto do_close; 88 } 89 if (fsync(fd)) { 90 err: 91 bb_simple_perror_msg(*argv); 92 ret = EXIT_FAILURE; 93 } 94 do_close: 95 close(fd); 96 next: 97 ++argv; 98 } 99 100 return ret; 101 #endif 30 102 } -
branches/3.3/mindi-busybox/coreutils/tail.c
r3232 r3621 25 25 */ 26 26 27 //kbuild:lib-$(CONFIG_TAIL) += tail.o 28 27 29 //usage:#define tail_trivial_usage 28 30 //usage: "[OPTIONS] [FILE]..." … … 31 33 //usage: "With more than one FILE, precede each with a filename header.\n" 32 34 //usage: "\n -f Print data as file grows" 35 //usage: "\n -c [+]N[kbm] Print last N bytes" 36 //usage: "\n -n N[kbm] Print last N lines" 37 //usage: "\n -n +N[kbm] Start on Nth line and print the rest" 33 38 //usage: IF_FEATURE_FANCY_TAIL( 39 //usage: "\n -q Never print headers" 34 40 //usage: "\n -s SECONDS Wait SECONDS between reads with -f" 35 //usage: )36 //usage: "\n -n N[kbm] Print last N lines"37 //usage: IF_FEATURE_FANCY_TAIL(38 //usage: "\n -c N[kbm] Print last N bytes"39 //usage: "\n -q Never print headers"40 41 //usage: "\n -v Always print headers" 42 //usage: "\n -F Same as -f, but keep retrying" 41 43 //usage: "\n" 42 44 //usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)." 43 //usage: "\nIf N starts with a '+', output begins with the Nth item from the start"44 //usage: "\nof each file, not from the end."45 45 //usage: ) 46 46 //usage: … … 50 50 51 51 #include "libbb.h" 52 53 static const struct suffix_mult tail_suffixes[] = { 54 { "b", 512 }, 55 { "k", 1024 }, 56 { "m", 1024*1024 }, 57 { "", 0 } 58 }; 52 #include "common_bufsiz.h" 59 53 60 54 struct globals { … … 62 56 bool exitcode; 63 57 } FIX_ALIASING; 64 #define G (*(struct globals*) &bb_common_bufsiz1)65 #define INIT_G() do { } while (0)58 #define G (*(struct globals*)bb_common_bufsiz1) 59 #define INIT_G() do { setup_common_bufsiz(); } while (0) 66 60 67 61 static void tail_xprint_header(const char *fmt, const char *filename) … … 74 68 { 75 69 ssize_t r; 76 off_t current;77 struct stat sbuf;78 79 /* /proc files report zero st_size, don't lseek them. */80 if (fstat(fd, &sbuf) == 0 && sbuf.st_size > 0) {81 current = lseek(fd, 0, SEEK_CUR);82 if (sbuf.st_size < current)83 xlseek(fd, 0, SEEK_SET);84 }85 70 86 71 r = full_read(fd, buf, count); … … 103 88 G.from_top = 1; 104 89 } 105 return xatou_sfx(p, tail_suffixes);90 return xatou_sfx(p, bkm_suffixes); 106 91 } 107 92 … … 121 106 int *fds; 122 107 const char *fmt; 108 int prev_fd; 123 109 124 110 INIT_G(); … … 325 311 } 326 312 } while (++i < nfiles); 313 prev_fd = fds[i-1]; 327 314 328 315 tailbuf = xrealloc(tailbuf, BUFSIZ); … … 368 355 fmt = header_fmt_str; 369 356 } 370 while ((nread = tail_read(fd, tailbuf, BUFSIZ)) > 0) { 371 if (fmt) { 357 for (;;) { 358 /* tail -f keeps following files even if they are truncated */ 359 struct stat sbuf; 360 /* /proc files report zero st_size, don't lseek them */ 361 if (fstat(fd, &sbuf) == 0 && sbuf.st_size > 0) { 362 off_t current = lseek(fd, 0, SEEK_CUR); 363 if (sbuf.st_size < current) 364 xlseek(fd, 0, SEEK_SET); 365 } 366 367 nread = tail_read(fd, tailbuf, BUFSIZ); 368 if (nread <= 0) 369 break; 370 if (fmt && (fd != prev_fd)) { 372 371 tail_xprint_header(fmt, filename); 373 372 fmt = NULL; 373 prev_fd = fd; 374 374 } 375 375 xwrite(STDOUT_FILENO, tailbuf, nread); -
branches/3.3/mindi-busybox/coreutils/tee.c
r3232 r3621 24 24 25 25 #include "libbb.h" 26 #include "common_bufsiz.h" 26 27 27 28 int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 38 39 ssize_t c; 39 40 # define buf bb_common_bufsiz1 41 setup_common_bufsiz(); 40 42 #else 41 43 int c; … … 80 82 81 83 #if ENABLE_FEATURE_TEE_USE_BLOCK_IO 82 while ((c = safe_read(STDIN_FILENO, buf, sizeof(buf))) > 0) {84 while ((c = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE)) > 0) { 83 85 fp = files; 84 86 do -
branches/3.3/mindi-busybox/coreutils/test.c
r3232 r3621 40 40 //config: Enable 64-bit support in test. 41 41 42 /* "test --help" does not print help (POSIX compat), only "[ --help" does. 43 * We display "<applet> EXPRESSION ]" here (not "<applet> EXPRESSION") 44 * Unfortunately, it screws up generated BusyBox.html. TODO. */ 45 //usage:#define test_trivial_usage 46 //usage: "EXPRESSION ]" 47 //usage:#define test_full_usage "\n\n" 48 //usage: "Check file types, compare values etc. Return a 0/1 exit code\n" 49 //usage: "depending on logical value of EXPRESSION" 42 /* "test --help" is special-cased to ignore --help */ 43 //usage:#define test_trivial_usage NOUSAGE_STR 44 //usage:#define test_full_usage "" 50 45 //usage: 51 46 //usage:#define test_example_usage … … 827 822 int res; 828 823 const char *arg0; 829 // bool negate = 0;830 824 831 825 arg0 = bb_basename(argv[0]); … … 845 839 argv[argc] = NULL; 846 840 } 841 /* argc is unused after this point */ 847 842 848 843 /* We must do DEINIT_S() prior to returning */ … … 863 858 /*ngroups = 0; - done by INIT_S() */ 864 859 865 //argc--;866 860 argv++; 867 868 /* Implement special cases from POSIX.2, section 4.62.4 */ 869 if (!argv[0]) { /* "test" */ 870 res = 1; 871 goto ret; 872 } 873 #if 0 874 // Now it's fixed in the parser and should not be needed 875 if (LONE_CHAR(argv[0], '!') && argv[1]) { 876 negate = 1; 877 //argc--; 878 argv++; 879 } 880 if (!argv[1]) { /* "test [!] arg" */ 881 res = (*argv[0] == '\0'); 882 goto ret; 883 } 884 if (argv[2] && !argv[3]) { 885 check_operator(argv[1]); 886 if (last_operator->op_type == BINOP) { 887 /* "test [!] arg1 <binary_op> arg2" */ 888 args = argv; 889 res = (binop() == 0); 890 goto ret; 861 args = argv; 862 863 /* Implement special cases from POSIX.2, section 4.62.4. 864 * Testcase: "test '(' = '('" 865 * The general parser would misinterpret '(' as group start. 866 */ 867 if (1) { 868 int negate = 0; 869 again: 870 if (!argv[0]) { 871 /* "test" */ 872 res = 1; 873 goto ret_special; 891 874 } 892 } 893 894 /* Some complex expression. Undo '!' removal */ 895 if (negate) { 896 negate = 0; 897 //argc++; 898 argv--; 899 } 900 #endif 901 args = argv; 875 if (!argv[1]) { 876 /* "test [!] arg" */ 877 res = (argv[0][0] == '\0'); 878 goto ret_special; 879 } 880 if (argv[2] && !argv[3]) { 881 check_operator(argv[1]); 882 if (last_operator->op_type == BINOP) { 883 /* "test [!] arg1 <binary_op> arg2" */ 884 args = argv; 885 res = (binop() == 0); 886 ret_special: 887 /* If there was leading "!" op... */ 888 res ^= negate; 889 goto ret; 890 } 891 } 892 if (LONE_CHAR(argv[0], '!')) { 893 argv++; 894 negate ^= 1; 895 goto again; 896 } 897 } 898 902 899 res = !oexpr(check_operator(*args)); 903 900 … … 912 909 ret: 913 910 DEINIT_S(); 914 // return negate ? !res : res;915 911 return res; 916 912 } -
branches/3.3/mindi-busybox/coreutils/touch.c
r3232 r3621 27 27 //config: modification timestamp of specified files. 28 28 //config: 29 //config:config FEATURE_TOUCH_NODEREF 30 //config: bool "Add support for -h" 31 //config: default y 32 //config: depends on TOUCH 33 //config: help 34 //config: Enable touch to have the -h option. 35 //config: This requires libc support for lutimes() function. 36 //config: 29 37 //config:config FEATURE_TOUCH_SUSV3 30 38 //config: bool "Add support for SUSV3 features (-d -t -r)" … … 43 51 //usage: "Update the last-modified date on the given FILE[s]\n" 44 52 //usage: "\n -c Don't create files" 53 //usage: IF_FEATURE_TOUCH_NODEREF( 54 //usage: "\n -h Don't follow links" 55 //usage: ) 45 56 //usage: IF_FEATURE_TOUCH_SUSV3( 46 57 //usage: "\n -d DT Date/time to use" … … 66 77 * -f (ignored, BSD compat) 67 78 * -m change only the modification time 79 * -h, --no-dereference 68 80 * -r, --reference=FILE 69 81 * use this file's times instead of current time … … 80 92 int status = EXIT_SUCCESS; 81 93 int opts; 94 enum { 95 OPT_c = (1 << 0), 96 OPT_r = (1 << 1) * ENABLE_FEATURE_TOUCH_SUSV3, 97 OPT_d = (1 << 2) * ENABLE_FEATURE_TOUCH_SUSV3, 98 OPT_t = (1 << 3) * ENABLE_FEATURE_TOUCH_SUSV3, 99 OPT_h = (1 << 4) * ENABLE_FEATURE_TOUCH_NODEREF, 100 }; 82 101 #if ENABLE_FEATURE_TOUCH_SUSV3 83 102 # if ENABLE_LONG_OPTS … … 87 106 "reference\0" Required_argument "r" 88 107 "date\0" Required_argument "d" 108 IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h") 89 109 ; 90 110 # endif … … 106 126 * We accept the same formats for both */ 107 127 opts = getopt32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:") 128 IF_FEATURE_TOUCH_NODEREF("h") 108 129 /*ignored:*/ "fma" 109 130 IF_FEATURE_TOUCH_SUSV3(, &reference_file) … … 112 133 ); 113 134 114 opts &= 1; /* only -c bit is left */115 135 argv += optind; 116 136 if (!*argv) { … … 122 142 xstat(reference_file, &stbuf); 123 143 timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime; 144 /* Can use .st_mtim.tv_nsec 145 * (or is it .st_mtimensec?? see date.c) 146 * to set microseconds too. 147 */ 124 148 } 125 149 … … 142 166 143 167 do { 144 if (utimes(*argv, (reference_file || date_str) ? timebuf : NULL) != 0) { 145 if (errno == ENOENT) { /* no such file */ 146 if (opts) { /* creation is disabled, so ignore */ 168 int result; 169 result = ( 170 #if ENABLE_FEATURE_TOUCH_NODEREF 171 (opts & OPT_h) ? lutimes : 172 #endif 173 utimes)(*argv, (reference_file || date_str) ? timebuf : NULL); 174 if (result != 0) { 175 if (errno == ENOENT) { /* no such file? */ 176 if (opts & OPT_c) { 177 /* Creation is disabled, so ignore */ 147 178 continue; 148 179 } -
branches/3.3/mindi-busybox/coreutils/tr.c
r3232 r3621 92 92 * Equiv classess, e.g. [=A=] ==> A (hmmmmmmm?) 93 93 * not supported: 94 * \ooo-\ooo - octal ranges95 94 * [x*N] - repeat char x N times 96 95 * [x*] - repeat char x until it fills STRING2: … … 100 99 * qweddd 101 100 */ 102 static unsigned expand(c onst char *arg, char **buffer_p)101 static unsigned expand(char *arg, char **buffer_p) 103 102 { 104 103 char *buffer = *buffer_p; … … 114 113 } 115 114 if (*arg == '\\') { 115 const char *z; 116 116 arg++; 117 buffer[pos++] = bb_process_escape_sequence(&arg); 118 continue; 117 z = arg; 118 ac = bb_process_escape_sequence(&z); 119 arg = (char *)z; 120 arg--; 121 *arg = ac; 122 /* 123 * fall through, there may be a range. 124 * If not, current char will be treated anyway. 125 */ 119 126 } 120 127 if (arg[1] == '-') { /* "0-9..." */ … … 125 132 } 126 133 i = (unsigned char) *arg; 134 arg += 3; /* skip 0-9 or 0-\ */ 135 if (ac == '\\') { 136 const char *z; 137 z = arg; 138 ac = bb_process_escape_sequence(&z); 139 arg = (char *)z; 140 } 127 141 while (i <= ac) /* ok: i is unsigned _int_ */ 128 142 buffer[pos++] = i++; 129 arg += 3; /* skip 0-9 */130 143 continue; 131 144 } -
branches/3.3/mindi-busybox/coreutils/true.c
r3232 r3621 11 11 /* http://www.opengroup.org/onlinepubs/007904975/utilities/true.html */ 12 12 13 //usage:#define true_trivial_usage 14 //usage: "" 15 //usage:#define true_full_usage "\n\n" 16 //usage: "Return an exit code of TRUE (0)" 17 //usage: 13 /* "true --help" is special-cased to ignore --help */ 14 //usage:#define true_trivial_usage NOUSAGE_STR 15 //usage:#define true_full_usage "" 18 16 //usage:#define true_example_usage 19 17 //usage: "$ true\n" -
branches/3.3/mindi-busybox/coreutils/uname.c
r3232 r3621 50 50 51 51 //usage:#define uname_trivial_usage 52 //usage: "[-amnrspv ]"52 //usage: "[-amnrspvio]" 53 53 //usage:#define uname_full_usage "\n\n" 54 54 //usage: "Print system information\n" … … 56 56 //usage: "\n -m The machine (hardware) type" 57 57 //usage: "\n -n Hostname" 58 //usage: "\n -r OSrelease"59 //usage: "\n -s OSname (default)"58 //usage: "\n -r Kernel release" 59 //usage: "\n -s Kernel name (default)" 60 60 //usage: "\n -p Processor type" 61 //usage: "\n -v OS version" 61 //usage: "\n -v Kernel version" 62 //usage: "\n -i The hardware platform" 63 //usage: "\n -o OS name" 62 64 //usage: 63 65 //usage:#define uname_example_usage … … 73 75 char processor[sizeof(((struct utsname*)NULL)->machine)]; 74 76 char platform[sizeof(((struct utsname*)NULL)->machine)]; 75 char os[sizeof( "GNU/Linux")];77 char os[sizeof(CONFIG_UNAME_OSNAME)]; 76 78 } uname_info_t; 77 79 … … 140 142 strcpy(uname_info.processor, unknown_str); 141 143 strcpy(uname_info.platform, unknown_str); 142 strcpy(uname_info.os, "GNU/Linux");144 strcpy(uname_info.os, CONFIG_UNAME_OSNAME); 143 145 #if 0 144 146 /* Fedora does something like this */ -
branches/3.3/mindi-busybox/coreutils/uniq.c
r3232 r3621 113 113 printf("%7lu ", dups + 1); 114 114 } 115 p rintf("%s\n",old_line);115 puts(old_line); 116 116 } 117 117 free(old_line); -
branches/3.3/mindi-busybox/coreutils/uudecode.c
r3232 r3621 30 30 char *line; 31 31 32 while ((line = xmalloc_fgetline(src_stream)) != NULL) {32 for (;;) { 33 33 int encoded_len, str_len; 34 34 char *line_ptr, *dst; 35 size_t line_len; 36 37 line_len = 64 * 1024; 38 line = xmalloc_fgets_str_len(src_stream, "\n", &line_len); 39 if (!line) 40 break; 41 /* Handle both Unix and MSDOS text, and stray trailing spaces */ 42 str_len = line_len; 43 while (--str_len >= 0 && isspace(line[str_len])) 44 line[str_len] = '\0'; 35 45 36 46 if (strcmp(line, "end") == 0) { … … 47 57 encoded_len = line[0] * 4 / 3; 48 58 /* Check that line is not too short. (we tolerate 49 * overly _long_ line to accom odate possible extra '`').59 * overly _long_ line to accommodate possible extra '`'). 50 60 * Empty line case is also caught here. */ 51 61 if (str_len <= encoded_len) { … … 111 121 int mode; 112 122 113 if ( strncmp(line, "begin-base64 ", 13) == 0) {123 if (is_prefixed_with(line, "begin-base64 ")) { 114 124 line_ptr = line + 13; 115 125 decode_fn_ptr = read_base64; 116 } else if ( strncmp(line, "begin ", 6) == 0) {126 } else if (is_prefixed_with(line, "begin ")) { 117 127 line_ptr = line + 6; 118 128 decode_fn_ptr = read_stduu; … … 129 139 break; 130 140 outname++; 141 trim(outname); /* remove trailing space (and '\r' for DOS text) */ 131 142 if (!outname[0]) 132 143 break; -
branches/3.3/mindi-busybox/coreutils/who.c
r3232 r3621 74 74 int who_main(int argc UNUSED_PARAM, char **argv) 75 75 { 76 struct utmp *ut;76 struct utmpx *ut; 77 77 unsigned opt; 78 78 int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u')); … … 82 82 opt = getopt32(argv, do_users ? "" : "aH"); 83 83 if (opt & 2) // -H 84 p rintf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n");84 puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST"); 85 85 86 setut ent();87 while ((ut = getut ent()) != NULL) {86 setutxent(); 87 while ((ut = getutxent()) != NULL) { 88 88 if (ut->ut_user[0] 89 89 && ((opt & 1) || ut->ut_type == USER_PROCESS) … … 127 127 bb_putchar('\n'); 128 128 if (ENABLE_FEATURE_CLEAN_UP) 129 endut ent();129 endutxent(); 130 130 return EXIT_SUCCESS; 131 131 }
Note:
See TracChangeset
for help on using the changeset viewer.