1 /* vi: set sw=4 ts=4: */
3 * strings implementation for busybox
5 * Copyright 2003 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;
25 const char *fmt = "%s: ";
26 const char *n_arg = "4";
28 getopt32(argv, "afon:", &n_arg);
29 /* -a is our default behaviour */
33 n = xatou_range(n_arg, 1, INT_MAX);
34 string = xzalloc(n + 1);
39 *--argv = (char *)bb_msg_standard_input;
43 file = fopen_or_warn_stdin(*argv);
45 status = EXIT_FAILURE;
52 if (isprint_asciionly(c) || c == '\t') {
58 if (option_mask32 & PRINT_NAME) {
61 if (option_mask32 & PRINT_OFFSET) {
62 printf("%7"OFF_FMT"o ", offset - n);
64 fputs(string, stdout);
76 fclose_if_not_stdin(file);
79 if (ENABLE_FEATURE_CLEAN_UP)
82 fflush_stdout_and_exit(status);