aboutsummaryrefslogtreecommitdiff
path: root/coreutils/sum.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-16 23:49:13 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-16 23:49:13 +0000
commit9f739445cd3deddd0343c3a8d5a981ede26bef30 (patch)
tree6dc013e44d2281eb1e6f61c4bca1ae7546001f79 /coreutils/sum.c
parenta597aaddfa76d589d3e1a37b1f1c3401c2decffd (diff)
downloadbusybox-w32-9f739445cd3deddd0343c3a8d5a981ede26bef30.tar.gz
busybox-w32-9f739445cd3deddd0343c3a8d5a981ede26bef30.tar.bz2
busybox-w32-9f739445cd3deddd0343c3a8d5a981ede26bef30.zip
inline strcmp(s, "-") [actually macro-ize it for now - gcc is too stupid]
Diffstat (limited to 'coreutils/sum.c')
-rw-r--r--coreutils/sum.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/coreutils/sum.c b/coreutils/sum.c
index 93f4e22eb..68a857816 100644
--- a/coreutils/sum.c
+++ b/coreutils/sum.c
@@ -18,9 +18,6 @@
18/* 1 if any of the files read were the standard input */ 18/* 1 if any of the files read were the standard input */
19static int have_read_stdin; 19static int have_read_stdin;
20 20
21/* make a little more readable and avoid using strcmp for just 2 bytes */
22#define IS_STDIN(s) (s[0] == '-' && s[1] == '\0')
23
24/* Calculate and print the rotated checksum and the size in 1K blocks 21/* Calculate and print the rotated checksum and the size in 1K blocks
25 of file FILE, or of the standard input if FILE is "-". 22 of file FILE, or of the standard input if FILE is "-".
26 If PRINT_NAME is >1, print FILE next to the checksum and size. 23 If PRINT_NAME is >1, print FILE next to the checksum and size.
@@ -34,7 +31,7 @@ static int bsd_sum_file(const char *file, int print_name)
34 int ch; /* Each character read. */ 31 int ch; /* Each character read. */
35 int ret = 0; 32 int ret = 0;
36 33
37 if (IS_STDIN(file)) { 34 if (LONE_DASH(file)) {
38 fp = stdin; 35 fp = stdin;
39 have_read_stdin++; 36 have_read_stdin++;
40 } else { 37 } else {
@@ -84,7 +81,7 @@ static int sysv_sum_file(const char *file, int print_name)
84 /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ 81 /* The sum of all the input bytes, modulo (UINT_MAX + 1). */
85 unsigned int s = 0; 82 unsigned int s = 0;
86 83
87 if (IS_STDIN(file)) { 84 if (LONE_DASH(file)) {
88 fd = 0; 85 fd = 0;
89 have_read_stdin = 1; 86 have_read_stdin = 1;
90 } else { 87 } else {
@@ -103,7 +100,7 @@ static int sysv_sum_file(const char *file, int print_name)
103release_and_ret: 100release_and_ret:
104 bb_perror_msg(file); 101 bb_perror_msg(file);
105 RELEASE_CONFIG_BUFFER(buf); 102 RELEASE_CONFIG_BUFFER(buf);
106 if (!IS_STDIN(file)) 103 if (NOT_LONE_DASH(file))
107 close(fd); 104 close(fd);
108 return 0; 105 return 0;
109 } 106 }
@@ -113,7 +110,7 @@ release_and_ret:
113 s += buf[bytes_read]; 110 s += buf[bytes_read];
114 } 111 }
115 112
116 if (!IS_STDIN(file) && close(fd) == -1) 113 if (NOT_LONE_DASH(file) && close(fd) == -1)
117 goto release_and_ret; 114 goto release_and_ret;
118 else 115 else
119 RELEASE_CONFIG_BUFFER(buf); 116 RELEASE_CONFIG_BUFFER(buf);