Name

gzgets — Reads a string from a compressed file.


Library

Libz.lib


Synopsis

#include <zlib.h>
char * gzgets (gzFile file, char * buf, int len);

Return Value

On success, gzgets() shall return a pointer to buf. Otherwise, gzgets() shall return Z_NULL. Applications may examine the cause using gzerror().


Detailed Description

The gzgets() function shall attempt to read data from the compressed file stream file, uncompressing it into buf until either len-1 bytes have been inserted into buf, or until a newline character has been uncompressed into buf. A null byte shall be appended to the uncompressed data. The file shall have been opened in for reading (see gzopen() and gzdopen()).


Examples

#include <stdio.h>
#include <zlib.h>
void Gzgets( )
{
Byte *compr, *uncompr;
uLong comprLen = 20*sizeof(int);
uLong uncomprLen = comprLen;
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
compress(compr, &comprLen, (const Bytef*)hello, len);

file = gzopen(fname, "rb");
strcpy((char*)uncompr, "garbage");

gzread(file, uncompr, (unsigned)uncomprLen) != len
gzseek(file, -8L, SEEK_CUR);
gzgets(file, (char*)uncompr, (int)uncomprLen);
int outlen = strlen((char*)uncompr);
printf("length of the output is %d",outlen);
gzclose(file);

free(compr);
free(uncompr);
}

Output

length of the output is 7.

Errors

On error, gzgets() shall return Z_NULL. The following conditions shall always be treated as an error: 

file is NULL, or does not refer to a file open for reading;
buf is NULL;
len is less than or equal to zero.

Feedback

For additional information or queries on this page send feedback

© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top