1 /* vi: set sw=4 ts=4: */
3 * strings implementation for busybox
5 * Copyright Tito Ragusa <farmatito@tiscali.it>
7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
14 #define PRINT_OFFSET 4
17 int strings_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
18 int strings_main(int argc UNUSED_PARAM, char **argv)
20 int n, c, status = EXIT_SUCCESS;
26 const char *fmt = "%s: ";
27 const char *n_arg = "4";
29 opt = getopt32(argv, "afon:", &n_arg);
30 /* -a is our default behaviour */
34 n = xatou_range(n_arg, 1, INT_MAX);
35 string = xzalloc(n + 1);
40 *--argv = (char *)bb_msg_standard_input;
44 file = fopen_or_warn_stdin(*argv);
46 status = EXIT_FAILURE;
53 if (isprint(c) || c == '\t') {
59 if (opt & PRINT_NAME) {
62 if (opt & PRINT_OFFSET) {
63 printf("%7"OFF_FMT"o ", offset - n);
65 fputs(string, stdout);
77 fclose_if_not_stdin(file);
80 if (ENABLE_FEATURE_CLEAN_UP)
83 fflush_stdout_and_exit(status);