Name

gzseek — Sets the file-position indicator for the compressed file stream file.


Library

Libz.lib


Synopsis

#include <zlib.h>
z_off_t gzseek(gzFile file, z_off_t offset, int whence);


Return Value

On success, gzseek() shall return the resulting offset in the file expressed as a byte position in the uncompressed data stream. On error, gzseek() shall return -1, and may set the error value for file accordingly.


Detailed Description

The gzseek() function shall set the file-position indicator for the compressed file stream file. The file-position indicator controls where the next read or write operation on the compressed file stream shall take place. The offset indicates a byte offset in the uncompressed data. The whence parameter may be one of:

SEEK_SET  

the offset is relative to the start of the uncompressed data.

SEEK_CUR  

the offset is relative to the current positition in the uncompressed data.


Note

Note: The value SEEK_END need not be supported.

If the file is open for writing, the new offset must be greater than or equal to the current offset. In this case, gzseek() shall compress a sequence of null bytes to fill the gap from the previous offset to the new offset.


Examples

To set the file-position indicator for the compressed file stream file:

#include <stdio.h>
#include <zlib.h>

void Gzseek( )
{
Byte *compr, *uncompr;
uLong comprLen = 20*sizeof(int);
uLong uncomprLen = comprLen;
static const char* myVersion = ZLIB_VERSION;
const char hello[] = "hello, hello!";
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
compress(compr, &comprLen, (const Bytef*)hello, len);

int len = (int)strlen(hello)+1;
gzFile file;
file = gzopen(TESTFILE, "wb");
gzputc(file, 'h');
gzputs(file, "ello");

gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
free(compr);
free(uncompr);
}


Errors

On error, gzseek() shall return -1. The following conditions shall always result in an error:


Application Usage (informative)

If file is open for reading, the implementation may still need to uncompress all of the data up to the new offset. As a result, gzseek() may be extremely slow in some circumstances.


Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top