[BusyBox-cvs] svn commit: trunk/busybox/coreutils

vapier at busybox.net vapier at busybox.net
Mon May 16 22:36:00 UTC 2005


Author: vapier
Date: 2005-05-16 16:35:59 -0600 (Mon, 16 May 2005)
New Revision: 10343

Log:
use more busybox functions and remove redundant code

Modified:
   trunk/busybox/coreutils/sum.c


Changeset:
Modified: trunk/busybox/coreutils/sum.c
===================================================================
--- trunk/busybox/coreutils/sum.c	2005-05-16 22:05:07 UTC (rev 10342)
+++ trunk/busybox/coreutils/sum.c	2005-05-16 22:35:59 UTC (rev 10343)
@@ -56,11 +56,9 @@
 		fp = stdin;
 		have_read_stdin = 1;
 	} else {
-		fp = fopen(file, "r");
-		if (fp == NULL) {
-			bb_perror_msg("%s", file);
+		fp = bb_wfopen(file, "r");
+		if (fp == NULL)
 			return 0;
-		}
 	}
 
 	while ((ch = getc(fp)) != EOF) {
@@ -71,22 +69,22 @@
 	}
 
 	if (ferror(fp)) {
-		bb_perror_msg("%s", file);
-		if (!IS_STDIN(file))
-			fclose(fp);
+		bb_perror_msg(file);
+		bb_fclose_nonstdin(fp);
 		return 0;
 	}
 
-	if (!IS_STDIN(file) && fclose(fp) == EOF) {
-		bb_perror_msg("%s", file);
+	if (bb_fclose_nonstdin(fp) == EOF) {
+		bb_perror_msg(file);
 		return 0;
 	}
 
-	printf("%05d %5s", checksum,
+	printf("%05d %5s ", checksum,
 	       make_human_readable_str(total_bytes, 1, 1024));
 	if (print_name > 1)
-		printf(" %s", file);
-	putchar('\n');
+		puts(file);
+	else
+		printf("\n");
 
 	return 1;
 }
@@ -112,7 +110,7 @@
 	} else {
 		fd = open(file, O_RDONLY);
 		if (fd == -1) {
-			bb_perror_msg("%s", file);
+			bb_perror_msg(file);
 			return 0;
 		}
 	}
@@ -125,7 +123,7 @@
 			break;
 
 		if (bytes_read == -1) {
-			bb_perror_msg("%s", file);
+			bb_perror_msg(file);
 			if (!IS_STDIN(file))
 				close(fd);
 			return 0;
@@ -137,18 +135,19 @@
 	}
 
 	if (!IS_STDIN(file) && close(fd) == -1) {
-		bb_perror_msg("%s", file);
+		bb_perror_msg(file);
 		return 0;
 	}
 
 	r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
 	checksum = (r & 0xffff) + (r >> 16);
 
-	printf("%d %s", checksum,
+	printf("%d %s ", checksum,
 	       make_human_readable_str(total_bytes, 1, 512));
 	if (print_name)
-		printf(" %s", file);
-	putchar('\n');
+		puts(file);
+	else
+		printf("\n");
 
 	return 1;
 }




More information about the busybox-cvs mailing list