From e6604121cb0d80382cdb942167546c34aa3f81c6 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 22 Nov 2009 18:54:17 +0000 Subject: [PATCH] Add a getc_unlocked method to zzcat. --- test/check-utils | 2 +- test/zzcat.c | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/check-utils b/test/check-utils index c6ac5c7..1453b22 100755 --- a/test/check-utils +++ b/test/check-utils @@ -20,7 +20,7 @@ checkutils() else check "$ZZOPTS" "< $file" "zzuf" fi - for n in 0 20 21 22 23 30 31 40 41 42; do + for n in 0 20 21 22 23 24 25 30 31 40 41 42; do check "$ZZOPTS" "$ZZCAT $n $file" "zzcat $n" done if [ "$STATIC_CAT" = "" ]; then diff --git a/test/zzcat.c b/test/zzcat.c index 98e7a20..8e9ab36 100644 --- a/test/zzcat.c +++ b/test/zzcat.c @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) unsigned char *data; char const *name; FILE *stream; - int i, j, fd; + int cmd, i, j, fd; char c; if(argc != 3) @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) close(fd); /* Read shit here and there, using different methods */ - switch(atoi(argv[1])) + switch((cmd = atoi(argv[1]))) { /* 0x: simple fd calls * 1x: complex fd calls */ @@ -97,14 +97,22 @@ int main(int argc, char *argv[]) fclose(stream); break; case 21: /* only getc() calls */ +#if defined HAVE_GETC_UNLOCKED + case 22: /* only getc_unlocked() calls */ +#endif stream = fopen(name, "r"); if(!stream) return EXIT_FAILURE; for(i = 0; i < len; i++) +#if defined HAVE_GETC_UNLOCKED + data[i] = cmd == 21 ? getc(stream) + : getc_unlocked(stream); +#else data[i] = getc(stream); +#endif fclose(stream); break; - case 22: /* only fgetc() calls */ + case 23: /* only fgetc() calls */ stream = fopen(name, "r"); if(!stream) return EXIT_FAILURE; @@ -113,17 +121,17 @@ int main(int argc, char *argv[]) fclose(stream); break; #if defined HAVE_GETLINE - case 23: /* getline() and getc() calls */ + case 24: /* getline() and getc() calls */ #if defined HAVE_GETC_UNLOCKED - case 24: /* getline() and getc_unlocked() calls */ + case 25: /* getline() and getc_unlocked() calls */ #endif stream = fopen(name, "r"); if(!stream) return EXIT_FAILURE; i = 0; #if defined HAVE_GETC_UNLOCKED - while ((c = (atoi(argv[1]) == 23) ? getc(stream) - : getc_unlocked(stream)) != EOF) + while ((c = (cmd == 24 ? getc(stream) + : getc_unlocked(stream))) != EOF) #else while ((c = getc(stream)) != EOF) #endif