Add a getc_unlocked method to zzcat.

This commit is contained in:
Sam Hocevar
2009-11-22 18:54:17 +00:00
committed by sam
parent cbd74358b4
commit e6604121cb
2 changed files with 16 additions and 8 deletions
+1 -1
View File
@@ -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
+15 -7
View File
@@ -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