summaryrefslogtreecommitdiff
path: root/coreutils/comm.c
diff options
context:
space:
mode:
authorMike Frysinger2005-05-12 22:50:12 +0000
committerMike Frysinger2005-05-12 22:50:12 +0000
commitdad4cf7e6307b5b6032d928f0c897235b3e1042d (patch)
tree7e7366348fe8c8dab7eebad25cfdd1adad8ba460 /coreutils/comm.c
parentb3a6ec3e623d120eee39bd003c8efdff85c0497a (diff)
downloadbusybox-dad4cf7e6307b5b6032d928f0c897235b3e1042d.zip
busybox-dad4cf7e6307b5b6032d928f0c897235b3e1042d.tar.gz
use a bunch of if statements since it is a few bytes smaller than a switch; also use bb_xfopen() instead of fopen() so comm doesnt segfault when given non-existant files :(
Diffstat (limited to 'coreutils/comm.c')
-rw-r--r--coreutils/comm.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/coreutils/comm.c b/coreutils/comm.c
index 2354bac..b0384fe 100644
--- a/coreutils/comm.c
+++ b/coreutils/comm.c
@@ -40,25 +40,21 @@ static int both;
/* writeline outputs the input given, appropriately aligned according to class */
static void writeline(char *line, int class)
{
- switch (class) {
- case 1:
- if (!only_file_1)
- return;
- break;
- case 2:
- if (!only_file_2)
- return;
- if (only_file_1)
- putchar('\t');
- break;
- case 3:
- if (!both)
- return;
- if (only_file_1)
- putchar('\t');
- if (only_file_2)
- putchar('\t');
- break;
+ if (class == 1 && !only_file_1)
+ return;
+ else if (class == 2) {
+ if (!only_file_2)
+ return;
+ if (only_file_1)
+ putchar('\t');
+ }
+ else if (class == 3) {
+ if (!both)
+ return;
+ if (only_file_1)
+ putchar('\t');
+ if (only_file_2)
+ putchar('\t');
}
fputs(line, stdout);
}
@@ -71,7 +67,7 @@ static int cmp_files(char **infiles)
int i = 0;
for (i = 0; i < 2; i++) {
- streams[i] = (strcmp(infiles[i], "=") == 0 ? stdin : fopen(infiles[i], "r"));
+ streams[i] = (strcmp(infiles[i], "=") == 0 ? stdin : bb_xfopen(infiles[i], "r"));
fgets(thisline[i], 100, streams[i]);
}