aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-09-10 02:47:19 +0000
committervapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-09-10 02:47:19 +0000
commita860144fda57227515b77e24663b4609d782c689 (patch)
treed1afdb0d47c750c4f889905236eb45b3b16a646a
parent2ccfc6f3a26b04d109764fb18882a927f03abd07 (diff)
downloadbusybox-w32-a860144fda57227515b77e24663b4609d782c689.tar.gz
busybox-w32-a860144fda57227515b77e24663b4609d782c689.tar.bz2
busybox-w32-a860144fda57227515b77e24663b4609d782c689.zip
some tweaks by cow to shrink a little
git-svn-id: svn://busybox.net/trunk/busybox@11419 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--coreutils/sum.c35
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 */
38static int have_read_stdin; 26static 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. */
96static int sysv_sum_file(const char *file, int print_name) 84static 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}