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/cksum.c

    r1765 r2725  
    55 * Copyright (C) 2006 by Rob Sullivan, with ideas from code by Walter Harms
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */
    8 
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
     8 */
    99#include "libbb.h"
    1010
    11 int cksum_main(int argc, char **argv);
    12 int cksum_main(int argc, char **argv)
     11/* This is a NOEXEC applet. Be very careful! */
     12
     13int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     14int cksum_main(int argc UNUSED_PARAM, char **argv)
    1315{
    1416    uint32_t *crc32_table = crc32_filltable(NULL, 1);
     17    uint32_t crc;
     18    off_t length, filesize;
     19    int bytes_read;
     20    int exit_code = EXIT_SUCCESS;
    1521
    16     FILE *fp;
    17     uint32_t crc;
    18     long length, filesize;
    19     int bytes_read;
    20     char *cp;
    21 
    22     int inp_stdin = (argc == optind) ? 1 : 0;
     22#if ENABLE_DESKTOP
     23    getopt32(argv, ""); /* coreutils 6.9 compat */
     24    argv += optind;
     25#else
     26    argv++;
     27#endif
    2328
    2429    do {
    25         fp = fopen_or_warn_stdin((inp_stdin) ? bb_msg_standard_input : *++argv);
     30        int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
    2631
     32        if (fd < 0) {
     33            exit_code = EXIT_FAILURE;
     34            continue;
     35        }
    2736        crc = 0;
    2837        length = 0;
    2938
    3039#define read_buf bb_common_bufsiz1
    31         while ((bytes_read = fread(read_buf, 1, BUFSIZ, fp)) > 0) {
    32             cp = read_buf;
    33             length += bytes_read;
    34             while (bytes_read--)
    35                 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ (*cp++)) & 0xffL];
     40        while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) {
     41            crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
    3642        }
     43        close(fd);
    3744
    3845        filesize = length;
    3946
    40         for (; length; length >>= 8)
    41             crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ length) & 0xffL];
    42         crc ^= 0xffffffffL;
     47        while (length) {
     48            crc = (crc << 8) ^ crc32_table[(uint8_t)(crc >> 24) ^ (uint8_t)length];
     49            /* must ensure that shift is unsigned! */
     50            if (sizeof(length) <= sizeof(unsigned))
     51                length = (unsigned)length >> 8;
     52            else if (sizeof(length) <= sizeof(unsigned long))
     53                length = (unsigned long)length >> 8;
     54            else
     55                length = (unsigned long long)length >> 8;
     56        }
     57        crc = ~crc;
    4358
    44         if (inp_stdin) {
    45             printf("%" PRIu32 " %li\n", crc, filesize);
    46             break;
    47         }
     59        printf((*argv ? "%"PRIu32" %"OFF_FMT"i %s\n" : "%"PRIu32" %"OFF_FMT"i\n"),
     60                crc, filesize, *argv);
     61    } while (*argv && *++argv);
    4862
    49         printf("%" PRIu32 " %li %s\n", crc, filesize, *argv);
    50         fclose(fp);
    51     } while (*(argv + 1));
    52 
    53     fflush_stdout_and_exit(EXIT_SUCCESS);
     63    fflush_stdout_and_exit(exit_code);
    5464}
Note: See TracChangeset for help on using the changeset viewer.