Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/coreutils/head.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/coreutils/head.c
r821 r1770 12 12 /* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */ 13 13 14 #include <stdio.h> 15 #include <stdlib.h> 16 #include <limits.h> 17 #include <ctype.h> 18 #include <unistd.h> 19 #include "busybox.h" 14 #include "libbb.h" 20 15 21 static const char head_opts[] =16 static const char head_opts[] ALIGN1 = 22 17 "n:" 23 18 #if ENABLE_FEATURE_FANCY_HEAD … … 31 26 { "k", 1024 }, 32 27 { "m", 1024*1024 }, 33 { NULL, 0}28 { } 34 29 }; 35 30 #endif 36 37 static const char header_fmt_str[] = "\n==> %s <==\n";38 31 32 static const char header_fmt_str[] ALIGN1 = "\n==> %s <==\n"; 33 34 int head_main(int argc, char **argv); 39 35 int head_main(int argc, char **argv) 40 36 { … … 53 49 int retval = EXIT_SUCCESS; 54 50 55 #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD51 #if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD 56 52 /* Allow legacy syntax of an initial numeric option without -n. */ 57 if ((argc > 1) && (argv[1][0] == '-') 58 /* && (isdigit)(argv[1][1]) */ 59 && (((unsigned int)(argv[1][1] - '0')) <= 9) 53 if (argc > 1 && argv[1][0] == '-' 54 && isdigit(argv[1][1]) 60 55 ) { 61 56 --argc; … … 66 61 #endif 67 62 68 /* No size benefit in converting this to bb_getopt_ulflags*/63 /* No size benefit in converting this to getopt32 */ 69 64 while ((opt = getopt(argc, argv, head_opts)) > 0) { 70 switch (opt) {65 switch (opt) { 71 66 #if ENABLE_FEATURE_FANCY_HEAD 72 73 74 75 76 77 78 79 80 67 case 'q': 68 header_threshhold = INT_MAX; 69 break; 70 case 'v': 71 header_threshhold = -1; 72 break; 73 case 'c': 74 count_bytes = 1; 75 /* fall through */ 81 76 #endif 82 83 84 #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD85 77 case 'n': 78 p = optarg; 79 #if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD 80 GET_COUNT: 86 81 #endif 87 82 88 83 #if !ENABLE_FEATURE_FANCY_HEAD 89 count = bb_xgetularg10(p);84 count = xatoul(p); 90 85 #else 91 count = bb_xgetularg_bnd_sfx(p, 10, 92 0, ULONG_MAX, 93 head_suffixes); 86 count = xatoul_sfx(p, head_suffixes); 94 87 #endif 95 96 97 88 break; 89 default: 90 bb_show_usage(); 98 91 } 99 92 } … … 101 94 argv += optind; 102 95 if (!*argv) { 103 *--argv = "-";96 *--argv = (char*)"-"; 104 97 } 105 98 … … 120 113 121 114 do { 122 if ((fp = bb_wfopen_input(*argv)) != NULL) { 115 fp = fopen_or_warn_stdin(*argv); 116 if (fp) { 123 117 if (fp == stdin) { 124 118 *argv = (char *) bb_msg_standard_input; 125 119 } 126 120 if (header_threshhold) { 127 bb_printf(fmt, *argv);121 printf(fmt, *argv); 128 122 } 129 123 i = count; … … 134 128 putchar(c); 135 129 } 136 if ( bb_fclose_nonstdin(fp)) {130 if (fclose_if_not_stdin(fp)) { 137 131 bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ 138 132 retval = EXIT_FAILURE; 139 133 } 140 bb_xferror_stdout();134 die_if_ferror_stdout(); 141 135 } 142 136 fmt = header_fmt_str; 143 137 } while (*++argv); 144 138 145 bb_fflush_stdout_and_exit(retval);139 fflush_stdout_and_exit(retval); 146 140 }
Note:
See TracChangeset
for help on using the changeset viewer.