Add a getline() variant to zzcat.

This commit is contained in:
Sam Hocevar
2009-10-27 22:44:09 +00:00
committed by sam
parent 2c701d10b4
commit bdc2b59edd
2 changed files with 23 additions and 1 deletions

View File

@@ -20,7 +20,7 @@ checkutils()
else
check "$ZZOPTS" "< $file" "zzuf"
fi
for n in 0 20 21 22 30 31 40 41 42; do
for n in 0 20 21 22 23 30 31 40 41 42; do
check "$ZZOPTS" "$ZZCAT $n $file" "zzcat $n"
done
if [ "$STATIC_CAT" = "" ]; then

View File

@@ -54,6 +54,7 @@ int main(int argc, char *argv[])
char const *name;
FILE *stream;
int i, j, fd;
char c;
if(argc != 3)
return EXIT_FAILURE;
@@ -111,6 +112,27 @@ int main(int argc, char *argv[])
data[i] = fgetc(stream);
fclose(stream);
break;
#if defined HAVE_GETLINE
case 23: /* getline() calls */
stream = fopen(name, "r");
if(!stream)
return EXIT_FAILURE;
i = 0;
while ((c = getc(stream)) != EOF)
{
char *line;
ssize_t ret;
size_t n;
ungetc(c, stream);
line = NULL;
ret = getline(&line, &n, stream);
for (j = 0; j < ret; i++, j++)
data[i] = line[j];
}
fclose(stream);
break;
#endif
case 30: /* one fread(), then only getc() calls */
stream = fopen(name, "r");
if(!stream)