[patch] sum.c: tiny size reduction, use RESERVE_CONFIG_BUFFER

Bernhard Fischer rep.nop at aon.at
Mon Sep 5 11:09:04 UTC 2005


[resending to the list, sorry if you get this twice, Rob]
Hi Rob,

vapier told me to send this to you for review wrt.
RESERVE_CONFIG_BUFFER.

ok?

PS: size before/after is inlined in the patchlet.
thank you,
Bernhard

-------------- next part --------------
\\   text	   data	    bss	    dec	    hex	filename
\\   1134	      0	      4	   1138	    46f	sum.o.oorig
\\   1131	      0	      4	   1135	    46f	sum.o
\\ TIA
diff -Xexcl -rduNp busybox.oorig/coreutils/sum.c busybox/coreutils/sum.c
--- busybox.oorig/coreutils/sum.c	2005-05-31 10:18:42.000000000 +0200
+++ busybox/coreutils/sum.c	2005-09-01 18:04:09.626486812 +0200
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * sum -- checksum and count the blocks in a file
  *     Like BSD sum or SysV sum -r, except like SysV sum if -s option is given.
@@ -9,20 +10,7 @@
  * Written by Kayvan Aghaiepour and David MacKenzie
  * Taken from coreutils and turned into a busybox applet by Mike Frysinger
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ * Licensed under the GPL v2, see the file LICENSE in this tarball.
  */
 
 #include <stdio.h>
@@ -32,7 +20,7 @@
 #include <unistd.h>
 #include <getopt.h>
 
-#include "libbb.h"
+#include "busybox.h"
 
 /* 1 if any of the files read were the standard input */
 static int have_read_stdin;
@@ -96,9 +84,8 @@ static int bsd_sum_file(const char *file
 static int sysv_sum_file(const char *file, int print_name)
 {
 	int fd;
-	unsigned char buf[8192];
+	RESERVE_CONFIG_UBUFFER(buf, 8192);
 	uintmax_t total_bytes = 0;
-	int r;
 	int checksum;
 
 	/* The sum of all the input bytes, modulo (UINT_MAX + 1).  */
@@ -123,6 +110,7 @@ static int sysv_sum_file(const char *fil
 			break;
 
 		if (bytes_read == -1) {
+			RELEASE_CONFIG_BUFFER(buf);
 			bb_perror_msg(file);
 			if (!IS_STDIN(file))
 				close(fd);
@@ -134,20 +122,24 @@ static int sysv_sum_file(const char *fil
 		total_bytes += bytes_read;
 	}
 
+	RELEASE_CONFIG_BUFFER(buf);
 	if (!IS_STDIN(file) && close(fd) == -1) {
 		bb_perror_msg(file);
 		return 0;
 	}
 
-	r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
-	checksum = (r & 0xffff) + (r >> 16);
+	{
+		int r;
+		r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
+		checksum = (r & 0xffff) + (r >> 16);
+	}
 
 	printf("%d %s ", checksum,
 	       make_human_readable_str(total_bytes, 1, 512));
 	if (print_name)
 		puts(file);
 	else
-		printf("\n");
+		putchar('\n');
 
 	return 1;
 }
@@ -179,3 +171,4 @@ int sum_main(int argc, char **argv)
 
 	exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
+



More information about the busybox mailing list