Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/sum.c


Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/coreutils/sum.c

    r1765 r2725  
    1111 * Taken from coreutils and turned into a busybox applet by Mike Frysinger
    1212 *
    13  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
     13 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1414 */
    1515
     
    2222/* SYSV: calculate and print the checksum and the size in 512-byte blocks */
    2323/* Return 1 if successful.  */
    24 static unsigned sum_file(const char *file, const unsigned type)
     24static unsigned sum_file(const char *file, unsigned type)
    2525{
    2626#define buf bb_common_bufsiz1
    27     uintmax_t total_bytes = 0;
    28     int fd = 0, r;
    29 
     27    unsigned long long total_bytes = 0;
     28    int fd, r;
    3029    /* The sum of all the input bytes, modulo (UINT_MAX + 1).  */
    3130    unsigned s = 0;
    3231
    33     if (NOT_LONE_DASH(file)) {
    34         fd = open(file, O_RDONLY);
    35         if (fd == -1)
    36             goto ret_bad;
    37     }
     32    fd = open_or_warn_stdin(file);
     33    if (fd == -1)
     34        return 0;
    3835
    3936    while (1) {
     
    4542                /* no error */
    4643                break;
    47  ret_bad:
    48             bb_perror_msg(file);
     44            bb_simple_perror_msg(file);
    4945            return 0;
    5046        }
     
    6864        r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
    6965        s = (r & 0xffff) + (r >> 16);
    70         printf("%d %ju %s\n", s, (total_bytes+511)/512, file);
     66        printf("%d %llu %s\n", s, (total_bytes + 511) / 512, file);
    7167    } else
    72         printf("%05d %5ju %s\n", s, (total_bytes+1023)/1024, file);
     68        printf("%05d %5llu %s\n", s, (total_bytes + 1023) / 1024, file);
    7369    return 1;
    7470#undef buf
    7571}
    7672
    77 int sum_main(int argc, char **argv);
    78 int sum_main(int argc, char **argv)
     73int sum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     74int sum_main(int argc UNUSED_PARAM, char **argv)
    7975{
    8076    unsigned n;
     
    8278
    8379    n = getopt32(argv, "sr");
     80    argv += optind;
    8481    if (n & 1) type = SUM_SYSV;
    8582    /* give the bsd priority over sysv func */
    8683    if (n & 2) type = SUM_BSD;
    8784
    88     if (argc == optind) {
     85    if (!argv[0]) {
    8986        /* Do not print the name */
    9087        n = sum_file("-", type);
     
    9390           - more than one file given
    9491           - doing sysv */
    95         type += argc - 1 > optind || type == SUM_SYSV;
    96         for (n = 1; optind < argc; optind++)
    97             n &= sum_file(argv[optind], type);
     92        type += (argv[1] || type == SUM_SYSV);
     93        n = 1;
     94        do {
     95            n &= sum_file(*argv, type);
     96        } while (*++argv);
    9897    }
    9998    return !n;
Note: See TracChangeset for help on using the changeset viewer.