diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:27:08 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:27:08 -0700 |
commit | 7df877eccdd826e94df53215f65dee639428e83f (patch) | |
tree | 11ed5070798961e28a4c69d9272ecaada500abc3 /zlib.h | |
parent | dc5a43ebfadb6b775f6e64bfeb5a461c66acb394 (diff) | |
download | zlib-7df877eccdd826e94df53215f65dee639428e83f.tar.gz zlib-7df877eccdd826e94df53215f65dee639428e83f.tar.bz2 zlib-7df877eccdd826e94df53215f65dee639428e83f.zip |
zlib 1.2.3.7v1.2.3.7
Diffstat (limited to 'zlib.h')
-rw-r--r-- | zlib.h | 152 |
1 files changed, 94 insertions, 58 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* zlib.h -- interface of the 'zlib' general purpose compression library | 1 | /* zlib.h -- interface of the 'zlib' general purpose compression library |
2 | version 1.2.3.6, Jan 17th, 2010 | 2 | version 1.2.3.7, Jan 24th, 2010 |
3 | 3 | ||
4 | Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler | 4 | Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler |
5 | 5 | ||
@@ -37,8 +37,8 @@ | |||
37 | extern "C" { | 37 | extern "C" { |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #define ZLIB_VERSION "1.2.3.6" | 40 | #define ZLIB_VERSION "1.2.3.7" |
41 | #define ZLIB_VERNUM 0x1236 | 41 | #define ZLIB_VERNUM 0x1237 |
42 | #define ZLIB_VER_MAJOR 1 | 42 | #define ZLIB_VER_MAJOR 1 |
43 | #define ZLIB_VER_MINOR 2 | 43 | #define ZLIB_VER_MINOR 2 |
44 | #define ZLIB_VER_REVISION 3 | 44 | #define ZLIB_VER_REVISION 3 |
@@ -209,6 +209,7 @@ typedef gz_header FAR *gz_headerp; | |||
209 | #define zlib_version zlibVersion() | 209 | #define zlib_version zlibVersion() |
210 | /* for compatibility with versions < 1.0.2 */ | 210 | /* for compatibility with versions < 1.0.2 */ |
211 | 211 | ||
212 | |||
212 | /* basic functions */ | 213 | /* basic functions */ |
213 | 214 | ||
214 | ZEXTERN const char * ZEXPORT zlibVersion OF((void)); | 215 | ZEXTERN const char * ZEXPORT zlibVersion OF((void)); |
@@ -232,8 +233,8 @@ ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); | |||
232 | requests a default compromise between speed and compression (currently | 233 | requests a default compromise between speed and compression (currently |
233 | equivalent to level 6). | 234 | equivalent to level 6). |
234 | 235 | ||
235 | deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not | 236 | deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough |
236 | enough memory, Z_STREAM_ERROR if level is not a valid compression level, | 237 | memory, Z_STREAM_ERROR if level is not a valid compression level, or |
237 | Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible | 238 | Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible |
238 | with the version assumed by the caller (ZLIB_VERSION). msg is set to null | 239 | with the version assumed by the caller (ZLIB_VERSION). msg is set to null |
239 | if there is no error message. deflateInit does not perform any compression: | 240 | if there is no error message. deflateInit does not perform any compression: |
@@ -505,6 +506,7 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); | |||
505 | static string (which must not be deallocated). | 506 | static string (which must not be deallocated). |
506 | */ | 507 | */ |
507 | 508 | ||
509 | |||
508 | /* Advanced functions */ | 510 | /* Advanced functions */ |
509 | 511 | ||
510 | /* | 512 | /* |
@@ -565,9 +567,11 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, | |||
565 | decoder for special applications. | 567 | decoder for special applications. |
566 | 568 | ||
567 | deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough | 569 | deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
568 | memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid | 570 | memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid |
569 | method). msg is set to null if there is no error message. deflateInit2 | 571 | method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is |
570 | does not perform any compression: this will be done by deflate(). | 572 | incompatible with the version assumed by the caller (ZLIB_VERSION). msg is |
573 | set to null if there is no error message. deflateInit2 does not perform any | ||
574 | compression: this will be done by deflate(). | ||
571 | */ | 575 | */ |
572 | 576 | ||
573 | ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, | 577 | ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, |
@@ -1087,11 +1091,11 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); | |||
1087 | /* utility functions */ | 1091 | /* utility functions */ |
1088 | 1092 | ||
1089 | /* | 1093 | /* |
1090 | The following utility functions are implemented on top of the | 1094 | The following utility functions are implemented on top of the basic |
1091 | basic stream-oriented functions. To simplify the interface, some default | 1095 | stream-oriented functions. To simplify the interface, some default options |
1092 | options are assumed (compression level and memory usage, standard memory | 1096 | are assumed (compression level and memory usage, standard memory allocation |
1093 | allocation functions). The source code of these utility functions can | 1097 | functions). The source code of these utility functions can be modified if |
1094 | easily be modified if you need special options. | 1098 | you need special options. |
1095 | */ | 1099 | */ |
1096 | 1100 | ||
1097 | ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, | 1101 | ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, |
@@ -1147,14 +1151,17 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, | |||
1147 | buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. | 1151 | buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. |
1148 | */ | 1152 | */ |
1149 | 1153 | ||
1154 | |||
1155 | /* gzip file access functions */ | ||
1156 | |||
1150 | /* | 1157 | /* |
1151 | This library supports reading and writing files in gzip (.gz) format | 1158 | This library supports reading and writing files in gzip (.gz) format with |
1152 | with an interface similar to that of stdio using the functions that start | 1159 | an interface similar to that of stdio, using the functions that start with |
1153 | with "gz". The gzip format is different from the zlib format. gzip is a | 1160 | "gz". The gzip format is different from the zlib format. gzip is a gzip |
1154 | gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. | 1161 | wrapper, documented in RFC 1952, wrapped around a deflate stream. |
1155 | */ | 1162 | */ |
1156 | 1163 | ||
1157 | typedef voidp gzFile; | 1164 | typedef voidp gzFile; /* opaque gzip file descriptor */ |
1158 | 1165 | ||
1159 | /* | 1166 | /* |
1160 | ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); | 1167 | ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); |
@@ -1172,25 +1179,30 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); | |||
1172 | gzopen can be used to read a file which is not in gzip format; in this | 1179 | gzopen can be used to read a file which is not in gzip format; in this |
1173 | case gzread will directly read from the file without decompression. | 1180 | case gzread will directly read from the file without decompression. |
1174 | 1181 | ||
1175 | gzopen returns NULL if the file could not be opened or if there was | 1182 | gzopen returns NULL if the file could not be opened, if there was |
1176 | insufficient memory to allocate the (de)compression state; errno can be | 1183 | insufficient memory to allocate the gzFile state, or if an invalid mode was |
1177 | checked to distinguish the two cases (if errno is zero, the zlib error is | 1184 | specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). |
1178 | Z_MEM_ERROR). | 1185 | errno can be checked to determine if the reason gzopen failed was that the |
1186 | file could not be opened. | ||
1179 | */ | 1187 | */ |
1180 | 1188 | ||
1181 | ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); | 1189 | ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); |
1182 | /* | 1190 | /* |
1183 | gzdopen() associates a gzFile with the file descriptor fd. File | 1191 | gzdopen associates a gzFile with the file descriptor fd. File descriptors |
1184 | descriptors are obtained from calls like open, dup, creat, pipe or fileno | 1192 | are obtained from calls like open, dup, creat, pipe or fileno (if the file |
1185 | (in the file has been previously opened with fopen). The mode parameter is | 1193 | has been previously opened with fopen). The mode parameter is as in gzopen. |
1186 | as in gzopen. | ||
1187 | 1194 | ||
1188 | The next call of gzclose on the returned gzFile will also close the file | 1195 | The next call of gzclose on the returned gzFile will also close the file |
1189 | descriptor fd, just like fclose(fdopen(fd), mode) closes the file descriptor | 1196 | descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor |
1190 | fd. If you want to keep fd open, use gzdopen(dup(fd), mode). | 1197 | fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, |
1198 | mode);. The duplicated descriptor should be saved to avoid a leak, since | ||
1199 | gzdopen does not close fd if it fails. | ||
1191 | 1200 | ||
1192 | gzdopen returns NULL if there was insufficient memory to allocate the | 1201 | gzdopen returns NULL if there was insufficient memory to allocate the |
1193 | (de)compression state. | 1202 | gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not |
1203 | provided, or '+' was provided), or if fd is -1. The file descriptor is not | ||
1204 | used until the next gz* read, write, seek, or close operation, so gzdopen | ||
1205 | will not detect if fd is invalid (unless fd is -1). | ||
1194 | */ | 1206 | */ |
1195 | 1207 | ||
1196 | ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); | 1208 | ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); |
@@ -1231,16 +1243,16 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); | |||
1231 | will be read if gzread is called until it returns less than the requested | 1243 | will be read if gzread is called until it returns less than the requested |
1232 | len. | 1244 | len. |
1233 | 1245 | ||
1234 | gzread returns the number of uncompressed bytes actually read (less than | 1246 | gzread returns the number of uncompressed bytes actually read, less than |
1235 | len for end of file, -1 for error). | 1247 | len for end of file, or -1 for error. |
1236 | */ | 1248 | */ |
1237 | 1249 | ||
1238 | ZEXTERN int ZEXPORT gzwrite OF((gzFile file, | 1250 | ZEXTERN int ZEXPORT gzwrite OF((gzFile file, |
1239 | voidpc buf, unsigned len)); | 1251 | voidpc buf, unsigned len)); |
1240 | /* | 1252 | /* |
1241 | Writes the given number of uncompressed bytes into the compressed file. | 1253 | Writes the given number of uncompressed bytes into the compressed file. |
1242 | gzwrite returns the number of uncompressed bytes actually written (0 in case | 1254 | gzwrite returns the number of uncompressed bytes written or 0 in case of |
1243 | of error). | 1255 | error. |
1244 | */ | 1256 | */ |
1245 | 1257 | ||
1246 | ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); | 1258 | ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); |
@@ -1254,7 +1266,7 @@ ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); | |||
1254 | nothing written. In this case, there may also be a buffer overflow with | 1266 | nothing written. In this case, there may also be a buffer overflow with |
1255 | unpredictable consequences, which is possible only if zlib was compiled with | 1267 | unpredictable consequences, which is possible only if zlib was compiled with |
1256 | the insecure functions sprintf() or vsprintf() because the secure snprintf() | 1268 | the insecure functions sprintf() or vsprintf() because the secure snprintf() |
1257 | or vsnprintf() functions were not available. This can be checked for using | 1269 | or vsnprintf() functions were not available. This can be determined using |
1258 | zlibCompileFlags(). | 1270 | zlibCompileFlags(). |
1259 | */ | 1271 | */ |
1260 | 1272 | ||
@@ -1273,7 +1285,7 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); | |||
1273 | condition is encountered. The string is then terminated with a null | 1285 | condition is encountered. The string is then terminated with a null |
1274 | character. | 1286 | character. |
1275 | 1287 | ||
1276 | gzgets returns buf, or Z_NULL in case of error. | 1288 | gzgets returns buf, or NULL in case of error. |
1277 | */ | 1289 | */ |
1278 | 1290 | ||
1279 | ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); | 1291 | ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); |
@@ -1290,11 +1302,14 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); | |||
1290 | 1302 | ||
1291 | ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); | 1303 | ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); |
1292 | /* | 1304 | /* |
1293 | Push one character back onto the stream to be read again later. At least | 1305 | Push one character back onto the stream to be read as the first character |
1294 | one character of push-back is allowed. gzungetc() returns the character | 1306 | on the next read. At least one character of push-back is allowed. |
1295 | pushed, or -1 on failure. gzungetc() will fail if c is -1, and may fail if | 1307 | gzungetc() returns the character pushed, or -1 on failure. gzungetc() will |
1296 | a character has been pushed but not read yet. The pushed character will be | 1308 | fail if c is -1, and may fail if a character has been pushed but not read |
1297 | discarded if the stream is repositioned with gzseek() or gzrewind(). | 1309 | yet. If gzungetc is used immediately after gzopen or gzdopen, at least the |
1310 | output buffer size of pushed characters is allowed. (See gzbuffer above.) | ||
1311 | The pushed character will be discarded if the stream is repositioned with | ||
1312 | gzseek() or gzrewind(). | ||
1298 | */ | 1313 | */ |
1299 | 1314 | ||
1300 | ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); | 1315 | ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); |
@@ -1356,43 +1371,63 @@ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); | |||
1356 | Returns the current offset in the file being read or written. This offset | 1371 | Returns the current offset in the file being read or written. This offset |
1357 | includes the count of bytes that precede the gzip stream, for example when | 1372 | includes the count of bytes that precede the gzip stream, for example when |
1358 | appending or when using gzdopen() for reading. When reading, the offset | 1373 | appending or when using gzdopen() for reading. When reading, the offset |
1359 | includes data that has been used to generate what has been provided as | 1374 | does not include as yet unused buffered input. This information can be used |
1360 | uncompressed data so far, but does not include as yet unused buffered input. | 1375 | for a progress indicator. On error, gzoffset() returns -1. |
1361 | On error, gzoffset() returns -1. | ||
1362 | */ | 1376 | */ |
1363 | 1377 | ||
1364 | ZEXTERN int ZEXPORT gzeof OF((gzFile file)); | 1378 | ZEXTERN int ZEXPORT gzeof OF((gzFile file)); |
1365 | /* | 1379 | /* |
1366 | Returns 1 when EOF has previously been detected reading the given input | 1380 | Returns true (1) if the end-of-file indicator has been set while reading, |
1367 | stream, otherwise zero. | 1381 | false (0) otherwise. Note that the end-of-file indicator is set only if the |
1382 | read tried to go past the end of the input, but came up short. Therefore, | ||
1383 | just like feof(), gzeof() may return false even if there is no more data to | ||
1384 | read, in the event that the last read request was for the exact number of | ||
1385 | bytes remaining in the input file. This will happen if the input file size | ||
1386 | is an exact multiple of the buffer size. | ||
1387 | |||
1388 | If gzeof() returns true, then the read functions will return no more data, | ||
1389 | unless the end-of-file indicator is reset by gzclearerr() and the input file | ||
1390 | has grown since the previous end of file was detected. | ||
1368 | */ | 1391 | */ |
1369 | 1392 | ||
1370 | ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); | 1393 | ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); |
1371 | /* | 1394 | /* |
1372 | Returns 1 if file is being read directly without decompression, otherwise | 1395 | Returns true (1) if file is being copied directly while reading, or false |
1373 | zero. gzdirect() called immediately after gzopen() will always return zero, | 1396 | (0) if file is a gzip stream being decompressed. This state can change from |
1374 | since nothing has been read yet. Whether to read the file with | 1397 | false to true while reading the input file if the end of a gzip stream is |
1375 | decompression or not is not determined until after the first read operation | 1398 | reached, but is followed by data that is not another gzip stream. |
1376 | (e.g. gzread(), gzgetc(), etc.). | 1399 | |
1400 | If the input file is empty, gzdirect() will return true, since the input | ||
1401 | does not contain a gzip stream. | ||
1402 | |||
1403 | If gzdirect() is used immediately after gzopen() or gzdopen() it will | ||
1404 | cause buffers to be allocated to allow reading the file to determine if it | ||
1405 | is a gzip file. Therefore if gzbuffer() is used, it should be called before | ||
1406 | gzdirect(). | ||
1377 | */ | 1407 | */ |
1378 | 1408 | ||
1379 | ZEXTERN int ZEXPORT gzclose OF((gzFile file)); | 1409 | ZEXTERN int ZEXPORT gzclose OF((gzFile file)); |
1380 | /* | 1410 | /* |
1381 | Flushes all pending output if necessary, closes the compressed file and | 1411 | Flushes all pending output if necessary, closes the compressed file and |
1382 | deallocates all the (de)compression state. The return value is the zlib | 1412 | deallocates the (de)compression state. Note that once file is closed, you |
1383 | error number. Note that once file is closed, you cannot call gzerror with | 1413 | cannot call gzerror with file, since its structures have been deallocated. |
1384 | file, since its structures have been deallocated. | 1414 | gzclose must not be called more than once on the same file, just as free |
1415 | must not be called more than once on the same allocation. | ||
1416 | |||
1417 | gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a | ||
1418 | file operation error, or Z_OK on success. | ||
1385 | */ | 1419 | */ |
1386 | 1420 | ||
1387 | ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); | 1421 | ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); |
1388 | ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); | 1422 | ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); |
1389 | /* | 1423 | /* |
1390 | Same as gzclose(), but gzclose_r() is only for use when reading, and | 1424 | Same as gzclose(), but gzclose_r() is only for use when reading, and |
1391 | gzclose_w() is only for use when writing. The advantage to using these | 1425 | gzclose_w() is only for use when writing or appending. The advantage to |
1392 | instead of gzclose() is that they avoid linking in zlib compression or | 1426 | using these instead of gzclose() is that they avoid linking in zlib |
1393 | decompression code that is not used when only reading or only writing | 1427 | compression or decompression code that is not used when only reading or only |
1394 | respectively. If gzclose() is used, then both compression and decompression | 1428 | writing respectively. If gzclose() is used, then both compression and |
1395 | code will be included the application when linking to a static zlib library. | 1429 | decompression code will be included the application when linking to a static |
1430 | zlib library. | ||
1396 | */ | 1431 | */ |
1397 | 1432 | ||
1398 | ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); | 1433 | ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); |
@@ -1415,6 +1450,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); | |||
1415 | file that is being written concurrently. | 1450 | file that is being written concurrently. |
1416 | */ | 1451 | */ |
1417 | 1452 | ||
1453 | |||
1418 | /* checksum functions */ | 1454 | /* checksum functions */ |
1419 | 1455 | ||
1420 | /* | 1456 | /* |