diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-04-18 20:57:28 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-04-18 20:57:28 +0000 |
commit | 78c31a3618aea534bb8e81e10ee4116bb52a1552 (patch) | |
tree | 298605b657f6e9c5338a24907ffee31f71f578a7 | |
parent | 39f883e1a5268692b676666214f8535a03dd15eb (diff) | |
download | busybox-w32-78c31a3618aea534bb8e81e10ee4116bb52a1552.tar.gz busybox-w32-78c31a3618aea534bb8e81e10ee4116bb52a1552.tar.bz2 busybox-w32-78c31a3618aea534bb8e81e10ee4116bb52a1552.zip |
New applet cksum, from Rob Sullivan.
git-svn-id: svn://busybox.net/trunk/busybox@14917 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | coreutils/Config.in | 6 | ||||
-rw-r--r-- | coreutils/Makefile.in | 1 | ||||
-rw-r--r-- | coreutils/cksum.c | 56 | ||||
-rw-r--r-- | include/applets.h | 1 | ||||
-rw-r--r-- | include/usage.h | 5 |
5 files changed, 69 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 | } | ||
diff --git a/include/applets.h b/include/applets.h index 12d438cea..059472248 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -70,6 +70,7 @@ USE_CHMOD(APPLET(chmod, chmod_main, _BB_DIR_BIN, _BB_SUID_NEVER)) | |||
70 | USE_CHOWN(APPLET(chown, chown_main, _BB_DIR_BIN, _BB_SUID_NEVER)) | 70 | USE_CHOWN(APPLET(chown, chown_main, _BB_DIR_BIN, _BB_SUID_NEVER)) |
71 | USE_CHROOT(APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | 71 | USE_CHROOT(APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) |
72 | USE_CHVT(APPLET(chvt, chvt_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 72 | USE_CHVT(APPLET(chvt, chvt_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
73 | USE_CKSUM(APPLET(cksum, cksum_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | ||
73 | USE_CLEAR(APPLET(clear, clear_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 74 | USE_CLEAR(APPLET(clear, clear_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
74 | USE_CMP(APPLET(cmp, cmp_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 75 | USE_CMP(APPLET(cmp, cmp_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
75 | USE_COMM(APPLET(comm, comm_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 76 | USE_COMM(APPLET(comm, comm_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
diff --git a/include/usage.h b/include/usage.h index d458936ca..3edb0f7ca 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -224,6 +224,11 @@ | |||
224 | #define chvt_full_usage \ | 224 | #define chvt_full_usage \ |
225 | "Changes the foreground virtual terminal to /dev/ttyN" | 225 | "Changes the foreground virtual terminal to /dev/ttyN" |
226 | 226 | ||
227 | #define cksum_trivial_usage \ | ||
228 | "FILES..." | ||
229 | #define cksum_full_usage \ | ||
230 | "Calculates the CRC32 checksums of FILES." | ||
231 | |||
227 | #define clear_trivial_usage \ | 232 | #define clear_trivial_usage \ |
228 | "" | 233 | "" |
229 | #define clear_full_usage \ | 234 | #define clear_full_usage \ |