Name

gzdopen — Attempts to associate the open file referenced by fd with a gzFile object.


Library

Libz.lib


Synopsis

#include <zlib.h>
gzFile gzdopen ( int fd, const char *mode );


Return Value

On success, gzdopen() shall return a gzFile object. On failure, gzdopen() shall return Z_NULL and may set errno accordingly.

Note

Note: At version 1.2.2, zlib does not set errno for several error conditions.
Applications may not be able to determine the cause of an error.


Detailed Description

The gzdopen() function shall attempt to associate the open file referenced by fd with a gzFile object. The mode argument is based on that of fopen(), but the mode parameter may also contain the following characters:

digit  

set the compression level to digit. A low value (e.g. 1) means high speed, while a high value (e.g. 9) means high compression. A compression level of 0 (zero) means no compression. See defaultInit2_() for further details.

[fhR]  

set the compression strategy to [fhR]. The letter f corresponds to filtered data, the letter h corresponds to Huffman only compression, and the letter R corresponds to Run Length Encoding. See defaultInit2_() for further details.

If fd refers to an uncompressed file, and mode refers to a read mode, gzdopen() shall attempt to open the file and return a gzFile object suitable for reading directly from the file without any decompression.

If mode is NULL, or if mode does not contain one of r, w, or a, gzdopen() shall return Z_NULL, and need not set any other error condition.


Examples

To associate the open file referenced by fd with a gzFile object:

#include <stdio.h>
#include <zlib.h>
void Gzdopen( )
{
int len = (int)strlen(hello)+1;
const char hello[] = "hello, hello!";
gzFile file;
const char * fname = TESTFILE ;

FILE* fp = fopen(fname, "rb");
file = gzdopen(fileno(fp), "rb");
gzclose(file);
}


Errors

On error, gzdopen() may set the global variable errno to indicate the error.


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