diff options
| author | Rob Landley <rob@landley.net> | 2006-04-18 20:57:28 +0000 |
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2006-04-18 20:57:28 +0000 |
| commit | 856489b63c276571387a9646d418081b5609628b (patch) | |
| tree | 298605b657f6e9c5338a24907ffee31f71f578a7 /coreutils | |
| parent | bbd50b58ea82ff64d7a522d6fa9a3c828ba47531 (diff) | |
| download | busybox-w32-856489b63c276571387a9646d418081b5609628b.tar.gz busybox-w32-856489b63c276571387a9646d418081b5609628b.tar.bz2 busybox-w32-856489b63c276571387a9646d418081b5609628b.zip | |
New applet cksum, from Rob Sullivan.
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/Config.in | 6 | ||||
| -rw-r--r-- | coreutils/Makefile.in | 1 | ||||
| -rw-r--r-- | coreutils/cksum.c | 56 |
3 files changed, 63 insertions, 0 deletions
diff --git a/coreutils/Config.in b/coreutils/Config.in index c77a1c90f..5d2965b47 100644 --- a/coreutils/Config.in +++ b/coreutils/Config.in | |||
| @@ -52,6 +52,12 @@ config CONFIG_CHROOT | |||
| 52 | chroot is used to change the root directory and run a command. | 52 | chroot is used to change the root directory and run a command. |
| 53 | The default command is `/bin/sh'. | 53 | The default command is `/bin/sh'. |
| 54 | 54 | ||
| 55 | config CONFIG_CKSUM | ||
| 56 | bool "cksum" | ||
| 57 | default n | ||
| 58 | help | ||
| 59 | cksum is used to calculate the CRC32 checksum of a file. | ||
| 60 | |||
| 55 | config CONFIG_CMP | 61 | config CONFIG_CMP |
| 56 | bool "cmp" | 62 | bool "cmp" |
| 57 | default n | 63 | default n |
diff --git a/coreutils/Makefile.in b/coreutils/Makefile.in index ff0e89b4d..24eee0b91 100644 --- a/coreutils/Makefile.in +++ b/coreutils/Makefile.in | |||
| @@ -18,6 +18,7 @@ COREUTILS-$(CONFIG_CHGRP) += chgrp.o | |||
| 18 | COREUTILS-$(CONFIG_CHMOD) += chmod.o | 18 | COREUTILS-$(CONFIG_CHMOD) += chmod.o |
| 19 | COREUTILS-$(CONFIG_CHOWN) += chown.o | 19 | COREUTILS-$(CONFIG_CHOWN) += chown.o |
| 20 | COREUTILS-$(CONFIG_CHROOT) += chroot.o | 20 | COREUTILS-$(CONFIG_CHROOT) += chroot.o |
| 21 | COREUTILS-$(CONFIG_CKSUM) += cksum.o | ||
| 21 | COREUTILS-$(CONFIG_CMP) += cmp.o | 22 | COREUTILS-$(CONFIG_CMP) += cmp.o |
| 22 | COREUTILS-$(CONFIG_COMM) += comm.o | 23 | COREUTILS-$(CONFIG_COMM) += comm.o |
| 23 | COREUTILS-$(CONFIG_CP) += cp.o | 24 | COREUTILS-$(CONFIG_CP) += cp.o |
diff --git a/coreutils/cksum.c b/coreutils/cksum.c new file mode 100644 index 000000000..194ea7d2a --- /dev/null +++ b/coreutils/cksum.c | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * cksum - calculate the CRC32 checksum of a file | ||
| 4 | * | ||
| 5 | * Copyright (C) 2006 by Rob Sullivan, with ideas from code by Walter Harms | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ | ||
| 8 | |||
| 9 | #include <stdio.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | #include <fcntl.h> | ||
| 12 | #include <inttypes.h> | ||
| 13 | #include "busybox.h" | ||
| 14 | |||
| 15 | int cksum_main(int argc, char **argv) { | ||
| 16 | |||
| 17 | uint32_t *crc32_table = bb_crc32_filltable(1); | ||
| 18 | |||
| 19 | FILE *fp; | ||
| 20 | uint32_t crc; | ||
| 21 | long length, filesize; | ||
| 22 | int bytes_read; | ||
| 23 | char *cp; | ||
| 24 | RESERVE_CONFIG_BUFFER(buf, BUFSIZ); | ||
| 25 | int inp_stdin = (argc == optind) ? 1 : 0; | ||
| 26 | |||
| 27 | do { | ||
| 28 | fp = bb_wfopen_input((inp_stdin) ? bb_msg_standard_input : *++argv); | ||
| 29 | |||
| 30 | crc = 0; | ||
| 31 | length = 0; | ||
| 32 | |||
| 33 | while ((bytes_read = fread(buf, 1, BUFSIZ, fp)) > 0) { | ||
| 34 | cp = buf; | ||
| 35 | length += bytes_read; | ||
| 36 | while (bytes_read--) | ||
| 37 | crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ (*cp++)) & 0xffL]; | ||
| 38 | } | ||
| 39 | |||
| 40 | filesize = length; | ||
| 41 | |||
| 42 | for (; length; length >>= 8) | ||
| 43 | crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ length) & 0xffL]; | ||
| 44 | crc ^= 0xffffffffL; | ||
| 45 | |||
| 46 | if (inp_stdin) { | ||
| 47 | printf("%"PRIu32" %li\n", crc, filesize); | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | |||
| 51 | printf("%"PRIu32" %li %s\n", crc, filesize, *argv); | ||
| 52 | fclose(fp); | ||
| 53 | } while (*(argv+1)); | ||
| 54 | |||
| 55 | return EXIT_SUCCESS; | ||
| 56 | } | ||
