Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/coreutils/head.c

    r821 r1765  
    1212/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */
    1313
    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"
    2015
    21 static const char head_opts[] =
     16static const char head_opts[] ALIGN1 =
    2217    "n:"
    2318#if ENABLE_FEATURE_FANCY_HEAD
     
    3126    { "k", 1024 },
    3227    { "m", 1024*1024 },
    33     { NULL, 0 }
     28    { }
    3429};
    3530#endif
    36                                        
    37 static const char header_fmt_str[] = "\n==> %s <==\n";
    3831
     32static const char header_fmt_str[] ALIGN1 = "\n==> %s <==\n";
     33
     34int head_main(int argc, char **argv);
    3935int head_main(int argc, char **argv)
    4036{
     
    5349    int retval = EXIT_SUCCESS;
    5450
    55 #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
     51#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
    5652    /* 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])
    6055    ) {
    6156        --argc;
     
    6661#endif
    6762
    68     /* No size benefit in converting this to bb_getopt_ulflags */
     63    /* No size benefit in converting this to getopt32 */
    6964    while ((opt = getopt(argc, argv, head_opts)) > 0) {
    70         switch(opt) {
     65        switch (opt) {
    7166#if ENABLE_FEATURE_FANCY_HEAD
    72             case 'q':
    73                 header_threshhold = INT_MAX;
    74                 break;
    75             case 'v':
    76                 header_threshhold = -1;
    77                 break;
    78             case 'c':
    79                 count_bytes = 1;
    80                 /* fall through */
     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 */
    8176#endif
    82             case 'n':
    83                 p = optarg;
    84 #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
    85             GET_COUNT:
     77        case 'n':
     78            p = optarg;
     79#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
     80 GET_COUNT:
    8681#endif
    8782
    8883#if !ENABLE_FEATURE_FANCY_HEAD
    89                 count = bb_xgetularg10(p);
     84            count = xatoul(p);
    9085#else
    91                 count = bb_xgetularg_bnd_sfx(p, 10,
    92                                 0, ULONG_MAX,
    93                                 head_suffixes);
     86            count = xatoul_sfx(p, head_suffixes);
    9487#endif
    95                 break;
    96             default:
    97                 bb_show_usage();
     88            break;
     89        default:
     90            bb_show_usage();
    9891        }
    9992    }
     
    10194    argv += optind;
    10295    if (!*argv) {
    103         *--argv = "-";
     96        *--argv = (char*)"-";
    10497    }
    10598
     
    120113
    121114    do {
    122         if ((fp = bb_wfopen_input(*argv)) != NULL) {
     115        fp = fopen_or_warn_stdin(*argv);
     116        if (fp) {
    123117            if (fp == stdin) {
    124118                *argv = (char *) bb_msg_standard_input;
    125119            }
    126120            if (header_threshhold) {
    127                 bb_printf(fmt, *argv);
     121                printf(fmt, *argv);
    128122            }
    129123            i = count;
     
    134128                putchar(c);
    135129            }
    136             if (bb_fclose_nonstdin(fp)) {
     130            if (fclose_if_not_stdin(fp)) {
    137131                bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */
    138132                retval = EXIT_FAILURE;
    139133            }
    140             bb_xferror_stdout();
     134            die_if_ferror_stdout();
    141135        }
    142136        fmt = header_fmt_str;
    143137    } while (*++argv);
    144138
    145     bb_fflush_stdout_and_exit(retval);
     139    fflush_stdout_and_exit(retval);
    146140}
Note: See TracChangeset for help on using the changeset viewer.