11 |
/* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */ |
/* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */ |
12 |
/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */ |
/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */ |
13 |
|
|
14 |
#include "busybox.h" |
#include "libbb.h" |
15 |
|
|
16 |
static const char head_opts[] = |
static const char head_opts[] ALIGN1 = |
17 |
"n:" |
"n:" |
18 |
#if ENABLE_FEATURE_FANCY_HEAD |
#if ENABLE_FEATURE_FANCY_HEAD |
19 |
"c:qv" |
"c:qv" |
25 |
{ "b", 512 }, |
{ "b", 512 }, |
26 |
{ "k", 1024 }, |
{ "k", 1024 }, |
27 |
{ "m", 1024*1024 }, |
{ "m", 1024*1024 }, |
28 |
{ NULL, 0 } |
{ } |
29 |
}; |
}; |
30 |
#endif |
#endif |
31 |
|
|
32 |
static const char header_fmt_str[] = "\n==> %s <==\n"; |
static const char header_fmt_str[] ALIGN1 = "\n==> %s <==\n"; |
33 |
|
|
34 |
|
int head_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
35 |
int head_main(int argc, char **argv) |
int head_main(int argc, char **argv) |
36 |
{ |
{ |
37 |
unsigned long count = 10; |
unsigned long count = 10; |
91 |
} |
} |
92 |
} |
} |
93 |
|
|
94 |
|
argc -= optind; |
95 |
argv += optind; |
argv += optind; |
96 |
if (!*argv) { |
if (!*argv) |
97 |
*--argv = "-"; |
*--argv = (char*)"-"; |
|
} |
|
98 |
|
|
99 |
fmt = header_fmt_str + 1; |
fmt = header_fmt_str + 1; |
100 |
#if ENABLE_FEATURE_FANCY_HEAD |
#if ENABLE_FEATURE_FANCY_HEAD |
101 |
if (argc - optind <= header_threshhold) { |
if (argc <= header_threshhold) { |
102 |
header_threshhold = 0; |
header_threshhold = 0; |
103 |
} |
} |
104 |
#else |
#else |
105 |
if (argc <= optind + 1) { |
if (argc <= 1) { |
106 |
fmt += 11; |
fmt += 11; /* "" */ |
107 |
} |
} |
108 |
/* Now define some things here to avoid #ifdefs in the code below. |
/* Now define some things here to avoid #ifdefs in the code below. |
109 |
* These should optimize out of the if conditions below. */ |
* These should optimize out of the if conditions below. */ |
128 |
putchar(c); |
putchar(c); |
129 |
} |
} |
130 |
if (fclose_if_not_stdin(fp)) { |
if (fclose_if_not_stdin(fp)) { |
131 |
bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ |
bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */ |
132 |
retval = EXIT_FAILURE; |
retval = EXIT_FAILURE; |
133 |
} |
} |
134 |
die_if_ferror_stdout(); |
die_if_ferror_stdout(); |