diff options
| author | Mike Frysinger <vapier@gentoo.org> | 2005-09-10 02:47:19 +0000 |
|---|---|---|
| committer | Mike Frysinger <vapier@gentoo.org> | 2005-09-10 02:47:19 +0000 |
| commit | a80b290e30d96007bcbf460f73b243545917c836 (patch) | |
| tree | d1afdb0d47c750c4f889905236eb45b3b16a646a /coreutils | |
| parent | 6b00d0d3cab2dfdfc7fab309ded4047d1a993149 (diff) | |
| download | busybox-w32-a80b290e30d96007bcbf460f73b243545917c836.tar.gz busybox-w32-a80b290e30d96007bcbf460f73b243545917c836.tar.bz2 busybox-w32-a80b290e30d96007bcbf460f73b243545917c836.zip | |
some tweaks by cow to shrink a little
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/sum.c | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/coreutils/sum.c b/coreutils/sum.c index d68043cf3..70b9b3a0a 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 1 | /* | 2 | /* |
| 2 | * sum -- checksum and count the blocks in a file | 3 | * sum -- checksum and count the blocks in a file |
| 3 | * Like BSD sum or SysV sum -r, except like SysV sum if -s option is given. | 4 | * Like BSD sum or SysV sum -r, except like SysV sum if -s option is given. |
| @@ -9,20 +10,7 @@ | |||
| 9 | * Written by Kayvan Aghaiepour and David MacKenzie | 10 | * Written by Kayvan Aghaiepour and David MacKenzie |
| 10 | * Taken from coreutils and turned into a busybox applet by Mike Frysinger | 11 | * Taken from coreutils and turned into a busybox applet by Mike Frysinger |
| 11 | * | 12 | * |
| 12 | * This program is free software; you can redistribute it and/or modify | 13 | * Licensed under the GPL v2, see the file LICENSE in this tarball. |
| 13 | * it under the terms of the GNU General Public License as published by | ||
| 14 | * the Free Software Foundation; either version 2 of the License, or | ||
| 15 | * (at your option) any later version. | ||
| 16 | * | ||
| 17 | * This program is distributed in the hope that it will be useful, | ||
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 20 | * General Public License for more details. | ||
| 21 | * | ||
| 22 | * You should have received a copy of the GNU General Public License | ||
| 23 | * along with this program; if not, write to the Free Software | ||
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 25 | * | ||
| 26 | */ | 14 | */ |
| 27 | 15 | ||
| 28 | #include <stdio.h> | 16 | #include <stdio.h> |
| @@ -32,7 +20,7 @@ | |||
| 32 | #include <unistd.h> | 20 | #include <unistd.h> |
| 33 | #include <getopt.h> | 21 | #include <getopt.h> |
| 34 | 22 | ||
| 35 | #include "libbb.h" | 23 | #include "busybox.h" |
| 36 | 24 | ||
| 37 | /* 1 if any of the files read were the standard input */ | 25 | /* 1 if any of the files read were the standard input */ |
| 38 | static int have_read_stdin; | 26 | static int have_read_stdin; |
| @@ -95,10 +83,10 @@ static int bsd_sum_file(const char *file, int print_name) | |||
| 95 | Return 1 if successful. */ | 83 | Return 1 if successful. */ |
| 96 | static int sysv_sum_file(const char *file, int print_name) | 84 | static int sysv_sum_file(const char *file, int print_name) |
| 97 | { | 85 | { |
| 86 | #define MY_BUF_SIZE 8192 | ||
| 98 | int fd; | 87 | int fd; |
| 99 | unsigned char buf[8192]; | 88 | unsigned char buf[MY_BUF_SIZE]; |
| 100 | uintmax_t total_bytes = 0; | 89 | uintmax_t total_bytes = 0; |
| 101 | int r; | ||
| 102 | int checksum; | 90 | int checksum; |
| 103 | 91 | ||
| 104 | /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ | 92 | /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ |
| @@ -117,7 +105,7 @@ static int sysv_sum_file(const char *file, int print_name) | |||
| 117 | 105 | ||
| 118 | while (1) { | 106 | while (1) { |
| 119 | size_t i; | 107 | size_t i; |
| 120 | size_t bytes_read = safe_read(fd, buf, sizeof(buf)); | 108 | size_t bytes_read = safe_read(fd, buf, MY_BUF_SIZE); |
| 121 | 109 | ||
| 122 | if (bytes_read == 0) | 110 | if (bytes_read == 0) |
| 123 | break; | 111 | break; |
| @@ -139,15 +127,14 @@ static int sysv_sum_file(const char *file, int print_name) | |||
| 139 | return 0; | 127 | return 0; |
| 140 | } | 128 | } |
| 141 | 129 | ||
| 142 | r = (s & 0xffff) + ((s & 0xffffffff) >> 16); | 130 | { |
| 143 | checksum = (r & 0xffff) + (r >> 16); | 131 | int r = (s & 0xffff) + ((s & 0xffffffff) >> 16); |
| 132 | checksum = (r & 0xffff) + (r >> 16); | ||
| 133 | } | ||
| 144 | 134 | ||
| 145 | printf("%d %s ", checksum, | 135 | printf("%d %s ", checksum, |
| 146 | make_human_readable_str(total_bytes, 1, 512)); | 136 | make_human_readable_str(total_bytes, 1, 512)); |
| 147 | if (print_name) | 137 | puts(print_name ? file : ""); |
| 148 | puts(file); | ||
| 149 | else | ||
| 150 | printf("\n"); | ||
| 151 | 138 | ||
| 152 | return 1; | 139 | return 1; |
| 153 | } | 140 | } |
