diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2016-12-03 08:18:56 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2016-12-04 07:48:47 -0800 |
commit | 123f9cfaf7730dcc52c380eaf04c15dc3e0b15f8 (patch) | |
tree | e5f159d765beaba71aa9d0493f7fd4e179fa06fe /gzwrite.c | |
parent | 9dc5a8585f429109ef1948ab71b6b71bfa7181e2 (diff) | |
download | zlib-123f9cfaf7730dcc52c380eaf04c15dc3e0b15f8.tar.gz zlib-123f9cfaf7730dcc52c380eaf04c15dc3e0b15f8.tar.bz2 zlib-123f9cfaf7730dcc52c380eaf04c15dc3e0b15f8.zip |
Clean up gz* function return values.
In some cases the return values did not match the documentation,
or the documentation did not document all of the return values.
gzprintf() now consistently returns negative values on error,
which matches the behavior of the stdio fprintf() function.
Diffstat (limited to 'gzwrite.c')
-rw-r--r-- | gzwrite.c | 44 |
1 files changed, 23 insertions, 21 deletions
@@ -11,7 +11,8 @@ local int gz_comp OF((gz_statep, int)); | |||
11 | local int gz_zero OF((gz_statep, z_off64_t)); | 11 | local int gz_zero OF((gz_statep, z_off64_t)); |
12 | 12 | ||
13 | /* Initialize state for writing a gzip file. Mark initialization by setting | 13 | /* Initialize state for writing a gzip file. Mark initialization by setting |
14 | state->size to non-zero. Return -1 on failure or 0 on success. */ | 14 | state->size to non-zero. Return -1 on a memory allocation failure, or 0 on |
15 | success. */ | ||
15 | local int gz_init(state) | 16 | local int gz_init(state) |
16 | gz_statep state; | 17 | gz_statep state; |
17 | { | 18 | { |
@@ -63,11 +64,11 @@ local int gz_init(state) | |||
63 | } | 64 | } |
64 | 65 | ||
65 | /* Compress whatever is at avail_in and next_in and write to the output file. | 66 | /* Compress whatever is at avail_in and next_in and write to the output file. |
66 | Return -1 if there is an error writing to the output file, otherwise 0. | 67 | Return -1 if there is an error writing to the output file or if gz_init() |
67 | flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, | 68 | fails to allocate memory, otherwise 0. flush is assumed to be a valid |
68 | then the deflate() state is reset to start a new gzip stream. If gz->direct | 69 | deflate() flush value. If flush is Z_FINISH, then the deflate() state is |
69 | is true, then simply write to the output file without compressing, and | 70 | reset to start a new gzip stream. If gz->direct is true, then simply write |
70 | ignore flush. */ | 71 | to the output file without compressing, and ignore flush. */ |
71 | local int gz_comp(state, flush) | 72 | local int gz_comp(state, flush) |
72 | gz_statep state; | 73 | gz_statep state; |
73 | int flush; | 74 | int flush; |
@@ -136,7 +137,8 @@ local int gz_comp(state, flush) | |||
136 | return 0; | 137 | return 0; |
137 | } | 138 | } |
138 | 139 | ||
139 | /* Compress len zeros to output. Return -1 on error, 0 on success. */ | 140 | /* Compress len zeros to output. Return -1 on a write error or memory |
141 | allocation failure by gz_comp(), or 0 on success. */ | ||
140 | local int gz_zero(state, len) | 142 | local int gz_zero(state, len) |
141 | gz_statep state; | 143 | gz_statep state; |
142 | z_off64_t len; | 144 | z_off64_t len; |
@@ -324,23 +326,23 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) | |||
324 | 326 | ||
325 | /* get internal structure */ | 327 | /* get internal structure */ |
326 | if (file == NULL) | 328 | if (file == NULL) |
327 | return -1; | 329 | return Z_STREAM_ERROR; |
328 | state = (gz_statep)file; | 330 | state = (gz_statep)file; |
329 | strm = &(state->strm); | 331 | strm = &(state->strm); |
330 | 332 | ||
331 | /* check that we're writing and that there's no error */ | 333 | /* check that we're writing and that there's no error */ |
332 | if (state->mode != GZ_WRITE || state->err != Z_OK) | 334 | if (state->mode != GZ_WRITE || state->err != Z_OK) |
333 | return 0; | 335 | return Z_STREAM_ERROR; |
334 | 336 | ||
335 | /* make sure we have some buffer space */ | 337 | /* make sure we have some buffer space */ |
336 | if (state->size == 0 && gz_init(state) == -1) | 338 | if (state->size == 0 && gz_init(state) == -1) |
337 | return 0; | 339 | return state->err; |
338 | 340 | ||
339 | /* check for seek request */ | 341 | /* check for seek request */ |
340 | if (state->seek) { | 342 | if (state->seek) { |
341 | state->seek = 0; | 343 | state->seek = 0; |
342 | if (gz_zero(state, state->skip) == -1) | 344 | if (gz_zero(state, state->skip) == -1) |
343 | return 0; | 345 | return state->err; |
344 | } | 346 | } |
345 | 347 | ||
346 | /* do the printf() into the input buffer, put length in len -- the input | 348 | /* do the printf() into the input buffer, put length in len -- the input |
@@ -378,7 +380,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) | |||
378 | left = strm->avail_in - state->size; | 380 | left = strm->avail_in - state->size; |
379 | strm->avail_in = state->size; | 381 | strm->avail_in = state->size; |
380 | if (gz_comp(state, Z_NO_FLUSH) == -1) | 382 | if (gz_comp(state, Z_NO_FLUSH) == -1) |
381 | return 0; | 383 | return state->err; |
382 | memcpy(state->in, state->in + state->size, left); | 384 | memcpy(state->in, state->in + state->size, left); |
383 | strm->next_in = state->in; | 385 | strm->next_in = state->in; |
384 | strm->avail_in = left; | 386 | strm->avail_in = left; |
@@ -414,27 +416,27 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, | |||
414 | 416 | ||
415 | /* get internal structure */ | 417 | /* get internal structure */ |
416 | if (file == NULL) | 418 | if (file == NULL) |
417 | return -1; | 419 | return Z_STREAM_ERROR; |
418 | state = (gz_statep)file; | 420 | state = (gz_statep)file; |
419 | strm = &(state->strm); | 421 | strm = &(state->strm); |
420 | 422 | ||
421 | /* check that can really pass pointer in ints */ | 423 | /* check that can really pass pointer in ints */ |
422 | if (sizeof(int) != sizeof(void *)) | 424 | if (sizeof(int) != sizeof(void *)) |
423 | return 0; | 425 | return Z_STREAM_ERROR; |
424 | 426 | ||
425 | /* check that we're writing and that there's no error */ | 427 | /* check that we're writing and that there's no error */ |
426 | if (state->mode != GZ_WRITE || state->err != Z_OK) | 428 | if (state->mode != GZ_WRITE || state->err != Z_OK) |
427 | return 0; | 429 | return Z_STREAM_ERROR; |
428 | 430 | ||
429 | /* make sure we have some buffer space */ | 431 | /* make sure we have some buffer space */ |
430 | if (state->size == 0 && gz_init(state) == -1) | 432 | if (state->size == 0 && gz_init(state) == -1) |
431 | return 0; | 433 | return state->error; |
432 | 434 | ||
433 | /* check for seek request */ | 435 | /* check for seek request */ |
434 | if (state->seek) { | 436 | if (state->seek) { |
435 | state->seek = 0; | 437 | state->seek = 0; |
436 | if (gz_zero(state, state->skip) == -1) | 438 | if (gz_zero(state, state->skip) == -1) |
437 | return 0; | 439 | return state->error; |
438 | } | 440 | } |
439 | 441 | ||
440 | /* do the printf() into the input buffer, put length in len -- the input | 442 | /* do the printf() into the input buffer, put length in len -- the input |
@@ -477,7 +479,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, | |||
477 | left = strm->avail_in - state->size; | 479 | left = strm->avail_in - state->size; |
478 | strm->avail_in = state->size; | 480 | strm->avail_in = state->size; |
479 | if (gz_comp(state, Z_NO_FLUSH) == -1) | 481 | if (gz_comp(state, Z_NO_FLUSH) == -1) |
480 | return 0; | 482 | return state->err; |
481 | memcpy(state->in, state->in + state->size, left); | 483 | memcpy(state->in, state->in + state->size, left); |
482 | strm->next_in = state->in; | 484 | strm->next_in = state->in; |
483 | strm->avail_in = left; | 485 | strm->avail_in = left; |
@@ -496,7 +498,7 @@ int ZEXPORT gzflush(file, flush) | |||
496 | 498 | ||
497 | /* get internal structure */ | 499 | /* get internal structure */ |
498 | if (file == NULL) | 500 | if (file == NULL) |
499 | return -1; | 501 | return Z_STREAM_ERROR; |
500 | state = (gz_statep)file; | 502 | state = (gz_statep)file; |
501 | 503 | ||
502 | /* check that we're writing and that there's no error */ | 504 | /* check that we're writing and that there's no error */ |
@@ -511,7 +513,7 @@ int ZEXPORT gzflush(file, flush) | |||
511 | if (state->seek) { | 513 | if (state->seek) { |
512 | state->seek = 0; | 514 | state->seek = 0; |
513 | if (gz_zero(state, state->skip) == -1) | 515 | if (gz_zero(state, state->skip) == -1) |
514 | return -1; | 516 | return state->err; |
515 | } | 517 | } |
516 | 518 | ||
517 | /* compress remaining data with requested flush */ | 519 | /* compress remaining data with requested flush */ |
@@ -546,7 +548,7 @@ int ZEXPORT gzsetparams(file, level, strategy) | |||
546 | if (state->seek) { | 548 | if (state->seek) { |
547 | state->seek = 0; | 549 | state->seek = 0; |
548 | if (gz_zero(state, state->skip) == -1) | 550 | if (gz_zero(state, state->skip) == -1) |
549 | return -1; | 551 | return state->err; |
550 | } | 552 | } |
551 | 553 | ||
552 | /* change compression parameters for subsequent input */ | 554 | /* change compression parameters for subsequent input */ |