]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Style cleanup for gzfile code
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 25 May 2015 21:01:55 +0000 (23:01 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 25 May 2015 21:01:55 +0000 (23:01 +0200)
gzclose.c
gzguts.h
gzlib.c
gzread.c
gzwrite.c

index 023d2a650135bc4a20c6a57b7044d7b0bff52f8f..48d6a86f04b6ea57f7158c19694023a9948438da 100644 (file)
--- a/gzclose.c
+++ b/gzclose.c
@@ -8,8 +8,7 @@
 /* gzclose() is in a separate file so that it is linked in only if it is used.
    That way the other gzclose functions can be used instead to avoid linking in
    unneeded compression or decompression routines. */
-int ZEXPORT gzclose(gzFile file)
-{
+int ZEXPORT gzclose(gzFile file) {
 #ifndef NO_GZCOMPRESS
     gz_statep state;
 
index f5cbec18315016ebcc8d675141b1643467943574..88996f3f0f9b56364fda0ea388878f5e08316a78 100644 (file)
--- a/gzguts.h
+++ b/gzguts.h
@@ -1,3 +1,5 @@
+#ifndef GZGUTS_H_
+#define GZGUTS_H_
 /* gzguts.h -- zlib internal header definitions for gz* operations
  * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
 #endif
 
 #include <stdio.h>
-#include "zlib.h"
 #include <string.h>
 #include <stdlib.h>
 #include <limits.h>
 #include <fcntl.h>
+#include "zlib.h"
 
 #ifdef _WIN32
 #  include <stddef.h>
 
 /* provide prototypes for these when building zlib without LFS */
 #if (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) && defined(WITH_GZFILEOP)
-    ZEXTERN gzFile ZEXPORT gzopen64 (const char *, const char *);
-    ZEXTERN z_off64_t ZEXPORT gzseek64 (gzFile, z_off64_t, int);
-    ZEXTERN z_off64_t ZEXPORT gztell64 (gzFile);
-    ZEXTERN z_off64_t ZEXPORT gzoffset64 (gzFile);
+    ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
+    ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
+    ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
+    ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
 #endif
 
 /* default memLevel */
@@ -136,7 +138,7 @@ typedef struct {
 typedef gz_state *gz_statep;
 
 /* shared functions */
-void ZLIB_INTERNAL gz_error (gz_statep, int, const char *);
+void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
 
 /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
    value -- needed when comparing unsigned to z_off64_t, which is signed
@@ -144,6 +146,8 @@ void ZLIB_INTERNAL gz_error (gz_statep, int, const char *);
 #ifdef INT_MAX
 #  define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
 #else
-unsigned ZLIB_INTERNAL gz_intmax (void);
+unsigned ZLIB_INTERNAL gz_intmax(void);
 #  define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
 #endif
+
+#endif /* GZGUTS_H_ */
diff --git a/gzlib.c b/gzlib.c
index 6ad5633e9a2852ef048ea1946ab37b6db6faf2bc..50e2c50254401ce49603805f752daff9af6a10c6 100644 (file)
--- a/gzlib.c
+++ b/gzlib.c
 #endif
 
 /* Local functions */
-local void gz_reset (gz_statep);
-local gzFile gz_open (const void *, int, const char *);
+local void gz_reset(gz_statep);
+local gzFile gz_open(const void *, int, const char *);
 
 /* Reset gzip file state */
-local void gz_reset(gz_statep state)
-{
+local void gz_reset(gz_statep state) {
     state->x.have = 0;              /* no output data available */
     if (state->mode == GZ_READ) {   /* for reading ... */
         state->eof = 0;             /* not at end of file */
@@ -35,8 +34,7 @@ local void gz_reset(gz_statep state)
 }
 
 /* Open a gzip file either by name or file descriptor. */
-local gzFile gz_open(const void *path, int fd, const char *mode)
-{
+local gzFile gz_open(const void *path, int fd, const char *mode) {
     gz_statep state;
     size_t len;
     int oflag;
@@ -65,9 +63,9 @@ local gzFile gz_open(const void *path, int fd, const char *mode)
     state->strategy = Z_DEFAULT_STRATEGY;
     state->direct = 0;
     while (*mode) {
-        if (*mode >= '0' && *mode <= '9')
+        if (*mode >= '0' && *mode <= '9') {
             state->level = *mode - '0';
-        else
+        } else {
             switch (*mode) {
             case 'r':
                 state->mode = GZ_READ;
@@ -111,8 +109,9 @@ local gzFile gz_open(const void *path, int fd, const char *mode)
                 state->direct = 1;
                 break;
             default:        /* could consider as an error, but just ignore */
-                ;
+                {}
             }
+        }
         mode++;
     }
 
@@ -137,8 +136,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode)
         len = wcstombs(NULL, path, 0);
         if (len == (size_t)-1)
             len = 0;
-    }
-    else
+    } else
 #endif
         len = strlen((const char *)path);
     state->path = (char *)malloc(len + 1);
@@ -148,10 +146,11 @@ local gzFile gz_open(const void *path, int fd, const char *mode)
     }
 #if defined(_WIN32) || defined(__CYGWIN__)
     if (fd == -2)
-        if (len)
+        if (len) {
             wcstombs(state->path, path, len + 1);
-        else
+        } else {
             *(state->path) = 0;
+        }
     else
 #endif
         snprintf(state->path, len + 1, "%s", (const char *)path);
@@ -207,20 +206,17 @@ local gzFile gz_open(const void *path, int fd, const char *mode)
 }
 
 /* -- see zlib.h -- */
-gzFile ZEXPORT gzopen(const char *path, const char *mode)
-{
+gzFile ZEXPORT gzopen(const char *path, const char *mode) {
     return gz_open(path, -1, mode);
 }
 
 /* -- see zlib.h -- */
-gzFile ZEXPORT gzopen64(const char *path, const char *mode)
-{
+gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
     return gz_open(path, -1, mode);
 }
 
 /* -- see zlib.h -- */
-gzFile ZEXPORT gzdopen(int fd, const char *mode)
-{
+gzFile ZEXPORT gzdopen(int fd, const char *mode) {
     char *path;         /* identifier for error messages */
     gzFile gz;
 
@@ -234,15 +230,13 @@ gzFile ZEXPORT gzdopen(int fd, const char *mode)
 
 /* -- see zlib.h -- */
 #if defined(_WIN32) || defined(__CYGWIN__)
-gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode)
-{
+gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) {
     return gz_open(path, -2, mode);
 }
 #endif
 
 /* -- see zlib.h -- */
-int ZEXPORT gzbuffer(gzFile file, unsigned size)
-{
+int ZEXPORT gzbuffer(gzFile file, unsigned size) {
     gz_statep state;
 
     /* get internal structure and check integrity */
@@ -264,8 +258,7 @@ int ZEXPORT gzbuffer(gzFile file, unsigned size)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzrewind(gzFile file)
-{
+int ZEXPORT gzrewind(gzFile file) {
     gz_statep state;
 
     /* get internal structure */
@@ -274,8 +267,7 @@ int ZEXPORT gzrewind(gzFile file)
     state = (gz_statep)file;
 
     /* check that we're reading and that there's no error */
-    if (state->mode != GZ_READ ||
-            (state->err != Z_OK && state->err != Z_BUF_ERROR))
+    if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return -1;
 
     /* back up and start over */
@@ -286,8 +278,7 @@ int ZEXPORT gzrewind(gzFile file)
 }
 
 /* -- see zlib.h -- */
-z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
-{
+z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
     unsigned n;
     z_off64_t ret;
     gz_statep state;
@@ -315,8 +306,7 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
     state->seek = 0;
 
     /* if within raw area while reading, just go there */
-    if (state->mode == GZ_READ && state->how == COPY &&
-            state->x.pos + offset >= 0) {
+    if (state->mode == GZ_READ && state->how == COPY && state->x.pos + offset >= 0) {
         ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
         if (ret == -1)
             return -1;
@@ -343,8 +333,7 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
 
     /* if reading, skip what's in output buffer (one less gzgetc() check) */
     if (state->mode == GZ_READ) {
-        n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
-            (unsigned)offset : state->x.have;
+        n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ? (unsigned)offset : state->x.have;
         state->x.have -= n;
         state->x.next += n;
         state->x.pos += n;
@@ -360,8 +349,7 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
 }
 
 /* -- see zlib.h -- */
-z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
-{
+z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
     z_off64_t ret;
 
     ret = gzseek64(file, (z_off64_t)offset, whence);
@@ -369,8 +357,7 @@ z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
 }
 
 /* -- see zlib.h -- */
-z_off64_t ZEXPORT gztell64(gzFile file)
-{
+z_off64_t ZEXPORT gztell64(gzFile file) {
     gz_statep state;
 
     /* get internal structure and check integrity */
@@ -385,8 +372,7 @@ z_off64_t ZEXPORT gztell64(gzFile file)
 }
 
 /* -- see zlib.h -- */
-z_off_t ZEXPORT gztell(gzFile file)
-{
+z_off_t ZEXPORT gztell(gzFile file) {
     z_off64_t ret;
 
     ret = gztell64(file);
@@ -394,8 +380,7 @@ z_off_t ZEXPORT gztell(gzFile file)
 }
 
 /* -- see zlib.h -- */
-z_off64_t ZEXPORT gzoffset64(gzFile file)
-{
+z_off64_t ZEXPORT gzoffset64(gzFile file) {
     z_off64_t offset;
     gz_statep state;
 
@@ -416,8 +401,7 @@ z_off64_t ZEXPORT gzoffset64(gzFile file)
 }
 
 /* -- see zlib.h -- */
-z_off_t ZEXPORT gzoffset(gzFile file)
-{
+z_off_t ZEXPORT gzoffset(gzFile file) {
     z_off64_t ret;
 
     ret = gzoffset64(file);
@@ -425,8 +409,7 @@ z_off_t ZEXPORT gzoffset(gzFile file)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzeof(gzFile file)
-{
+int ZEXPORT gzeof(gzFile file) {
     gz_statep state;
 
     /* get internal structure and check integrity */
@@ -441,8 +424,7 @@ int ZEXPORT gzeof(gzFile file)
 }
 
 /* -- see zlib.h -- */
-const char * ZEXPORT gzerror(gzFile file, int *errnum)
-{
+const char * ZEXPORT gzerror(gzFile file, int *errnum) {
     gz_statep state;
 
     /* get internal structure and check integrity */
@@ -455,13 +437,11 @@ const char * ZEXPORT gzerror(gzFile file, int *errnum)
     /* return error information */
     if (errnum != NULL)
         *errnum = state->err;
-    return state->err == Z_MEM_ERROR ? "out of memory" :
-                                       (state->msg == NULL ? "" : state->msg);
+    return state->err == Z_MEM_ERROR ? "out of memory" : (state->msg == NULL ? "" : state->msg);
 }
 
 /* -- see zlib.h -- */
-void ZEXPORT gzclearerr(gzFile file)
-{
+void ZEXPORT gzclearerr(gzFile file) {
     gz_statep state;
 
     /* get internal structure and check integrity */
@@ -485,8 +465,7 @@ void ZEXPORT gzclearerr(gzFile file)
    memory).  Simply save the error message as a static string.  If there is an
    allocation failure constructing the error message, then convert the error to
    out of memory. */
-void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
-{
+void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
     /* free previously allocated message and clear */
     if (state->msg != NULL) {
         if (state->err != Z_MEM_ERROR)
@@ -508,13 +487,11 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
         return;
 
     /* construct error message with path */
-    if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
-            NULL) {
+    if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
         state->err = Z_MEM_ERROR;
         return;
     }
-    snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
-             "%s%s%s", state->path, ": ", msg);
+    snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, "%s%s%s", state->path, ": ", msg);
     return;
 }
 
@@ -523,8 +500,7 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
    available) -- we need to do this to cover cases where 2's complement not
    used, since C standard permits 1's complement and sign-bit representations,
    otherwise we could just use ((unsigned)-1) >> 1 */
-unsigned ZLIB_INTERNAL gz_intmax()
-{
+unsigned ZLIB_INTERNAL gz_intmax() {
     unsigned p, q;
 
     p = 1;
index c61128acce91fae88f1927e3d01472eefe990b9c..5db2c5045baf6950ff58402dbe68fb516e106cc2 100644 (file)
--- a/gzread.c
+++ b/gzread.c
@@ -6,19 +6,18 @@
 #include "gzguts.h"
 
 /* Local functions */
-local int gz_load (gz_statep, unsigned char *, unsigned, unsigned *);
-local int gz_avail (gz_statep);
-local int gz_look (gz_statep);
-local int gz_decomp (gz_statep);
-local int gz_fetch (gz_statep);
-local int gz_skip (gz_statep, z_off64_t);
+local int gz_load(gz_statep, unsigned char *, unsigned, unsigned *);
+local int gz_avail(gz_statep);
+local int gz_look(gz_statep);
+local int gz_decomp(gz_statep);
+local int gz_fetch(gz_statep);
+local int gz_skip(gz_statep, z_off64_t);
 
 /* Use read() to load a buffer -- return -1 on error, otherwise 0.  Read from
    state->fd, and update state->eof, state->err, and state->msg as appropriate.
    This function needs to loop on read(), since read() is not guaranteed to
    read the number of bytes requested, depending on the type of descriptor. */
-local int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *have)
-{
+local int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *have) {
     int ret;
 
     *have = 0;
@@ -44,8 +43,7 @@ local int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *h
    If strm->avail_in != 0, then the current data is moved to the beginning of
    the input buffer, and then the remainder of the buffer is loaded with the
    available data from the input file. */
-local int gz_avail(gz_statep state)
-{
+local int gz_avail(gz_statep state) {
     unsigned got;
     z_stream *strm = &(state->strm);
 
@@ -60,8 +58,7 @@ local int gz_avail(gz_statep state)
                 *p++ = *q++;
             } while (--n);
         }
-        if (gz_load(state, state->in + strm->avail_in,
-                    state->size - strm->avail_in, &got) == -1)
+        if (gz_load(state, state->in + strm->avail_in, state->size - strm->avail_in, &got) == -1)
             return -1;
         strm->avail_in += got;
         strm->next_in = state->in;
@@ -78,8 +75,7 @@ local int gz_avail(gz_statep state)
    case, all further file reads will be directly to either the output buffer or
    a user buffer.  If decompressing, the inflate state will be initialized.
    gz_look() will return 0 on success or -1 on failure. */
-local int gz_look(gz_statep state)
-{
+local int gz_look(gz_statep state) {
     z_stream *strm = &(state->strm);
 
     /* allocate read buffers and inflate memory */
@@ -163,8 +159,7 @@ local int gz_look(gz_statep state)
    data.  If the gzip stream completes, state->how is reset to LOOK to look for
    the next gzip stream or raw data, once state->x.have is depleted.  Returns 0
    on success, -1 on failure. */
-local int gz_decomp(gz_statep state)
-{
+local int gz_decomp(gz_statep state) {
     int ret = Z_OK;
     unsigned had;
     z_stream *strm = &(state->strm);
@@ -183,8 +178,7 @@ local int gz_decomp(gz_statep state)
         /* decompress and handle errors */
         ret = inflate(strm, Z_NO_FLUSH);
         if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
-            gz_error(state, Z_STREAM_ERROR,
-                     "internal error: inflate stream corrupt");
+            gz_error(state, Z_STREAM_ERROR, "internal error: inflate stream corrupt");
             return -1;
         }
         if (ret == Z_MEM_ERROR) {
@@ -192,8 +186,7 @@ local int gz_decomp(gz_statep state)
             return -1;
         }
         if (ret == Z_DATA_ERROR) {              /* deflate stream invalid */
-            gz_error(state, Z_DATA_ERROR,
-                     strm->msg == NULL ? "compressed data error" : strm->msg);
+            gz_error(state, Z_DATA_ERROR, strm->msg == NULL ? "compressed data error" : strm->msg);
             return -1;
         }
     } while (strm->avail_out && ret != Z_STREAM_END);
@@ -216,12 +209,11 @@ local int gz_decomp(gz_statep state)
    looked for to determine whether to copy or decompress.  Returns -1 on error,
    otherwise 0.  gz_fetch() will leave state->how as COPY or GZIP unless the
    end of the input file has been reached and all data has been processed.  */
-local int gz_fetch(gz_statep state)
-{
+local int gz_fetch(gz_statep state) {
     z_stream *strm = &(state->strm);
 
     do {
-        switch(state->how) {
+        switch (state->how) {
         case LOOK:      /* -> LOOK, COPY (only if never GZIP), or GZIP */
             if (gz_look(state) == -1)
                 return -1;
@@ -245,8 +237,7 @@ local int gz_fetch(gz_statep state)
 }
 
 /* Skip len uncompressed bytes of output.  Return -1 on error, 0 on success. */
-local int gz_skip(gz_statep state, z_off64_t len)
-{
+local int gz_skip(gz_statep state, z_off64_t len) {
     unsigned n;
 
     /* skip over len bytes or reach end-of-file, whichever comes first */
@@ -259,14 +250,11 @@ local int gz_skip(gz_statep state, z_off64_t len)
             state->x.next += n;
             state->x.pos += n;
             len -= n;
-        }
-
-        /* output buffer empty -- return if we're at the end of the input */
-        else if (state->eof && state->strm.avail_in == 0)
+        } else if (state->eof && state->strm.avail_in == 0) {
+            /* output buffer empty -- return if we're at the end of the input */
             break;
-
-        /* need more data to skip -- load up output buffer */
-        else {
+        } else {
+            /* need more data to skip -- load up output buffer */
             /* get more output, looking for header if required */
             if (gz_fetch(state) == -1)
                 return -1;
@@ -275,8 +263,7 @@ local int gz_skip(gz_statep state, z_off64_t len)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzread(gzFile file, void *buf, unsigned len)
-{
+int ZEXPORT gzread(gzFile file, void *buf, unsigned len) {
     unsigned got, n;
     gz_statep state;
     z_stream *strm;
@@ -288,8 +275,7 @@ int ZEXPORT gzread(gzFile file, void *buf, unsigned len)
     strm = &(state->strm);
 
     /* check that we're reading and that there's no (serious) error */
-    if (state->mode != GZ_READ ||
-            (state->err != Z_OK && state->err != Z_BUF_ERROR))
+    if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return -1;
 
     /* since an int is returned, make sure len fits in one, otherwise return
@@ -319,33 +305,24 @@ int ZEXPORT gzread(gzFile file, void *buf, unsigned len)
             memcpy(buf, state->x.next, n);
             state->x.next += n;
             state->x.have -= n;
-        }
-
-        /* output buffer empty -- return if we're at the end of the input */
-        else if (state->eof && strm->avail_in == 0) {
+        } else if (state->eof && strm->avail_in == 0) {
+            /* output buffer empty -- return if we're at the end of the input */
             state->past = 1;        /* tried to read past end */
             break;
-        }
-
-        /* need output data -- for small len or new stream load up our output
-           buffer */
-        else if (state->how == LOOK || len < (state->size << 1)) {
+        } else if (state->how == LOOK || len < (state->size << 1)) {
+            /* need output data -- for small len or new stream load up our output buffer */
             /* get more output, looking for header if required */
             if (gz_fetch(state) == -1)
                 return -1;
             continue;       /* no progress yet -- go back to copy above */
             /* the copy above assures that we will leave with space in the
                output buffer, allowing at least one gzungetc() to succeed */
-        }
-
-        /* large len -- read directly into user buffer */
-        else if (state->how == COPY) {      /* read directly */
+        } else if (state->how == COPY) {      /* read directly */
+            /* large len -- read directly into user buffer */
             if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
                 return -1;
-        }
-
-        /* large len -- decompress directly into user buffer */
-        else {  /* state->how == GZIP */
+        } else {  /* state->how == GZIP */
+            /* large len -- decompress directly into user buffer */
             strm->avail_out = len;
             strm->next_out = (unsigned char *)buf;
             if (gz_decomp(state) == -1)
@@ -367,8 +344,7 @@ int ZEXPORT gzread(gzFile file, void *buf, unsigned len)
 
 /* -- see zlib.h -- */
 #undef gzgetc
-int ZEXPORT gzgetc(gzFile file)
-{
+int ZEXPORT gzgetc(gzFile file) {
     int ret;
     unsigned char buf[1];
     gz_statep state;
@@ -379,8 +355,7 @@ int ZEXPORT gzgetc(gzFile file)
     state = (gz_statep)file;
 
     /* check that we're reading and that there's no (serious) error */
-    if (state->mode != GZ_READ ||
-        (state->err != Z_OK && state->err != Z_BUF_ERROR))
+    if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return -1;
 
     /* try output buffer (no need to check for skip request) */
@@ -395,14 +370,12 @@ int ZEXPORT gzgetc(gzFile file)
     return ret < 1 ? -1 : buf[0];
 }
 
-int ZEXPORT gzgetc_(gzFile file)
-{
+int ZEXPORT gzgetc_(gzFile file) {
     return gzgetc(file);
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzungetc(int c, gzFile file)
-{
+int ZEXPORT gzungetc(int c, gzFile file) {
     gz_statep state;
 
     /* get internal structure */
@@ -411,8 +384,7 @@ int ZEXPORT gzungetc(int c, gzFile file)
     state = (gz_statep)file;
 
     /* check that we're reading and that there's no (serious) error */
-    if (state->mode != GZ_READ ||
-        (state->err != Z_OK && state->err != Z_BUF_ERROR))
+    if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return -1;
 
     /* process a skip request */
@@ -459,8 +431,7 @@ int ZEXPORT gzungetc(int c, gzFile file)
 }
 
 /* -- see zlib.h -- */
-char * ZEXPORT gzgets(gzFile file, char *buf, int len)
-{
+char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
     unsigned left, n;
     char *str;
     unsigned char *eol;
@@ -472,8 +443,7 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len)
     state = (gz_statep)file;
 
     /* check that we're reading and that there's no (serious) error */
-    if (state->mode != GZ_READ ||
-        (state->err != Z_OK && state->err != Z_BUF_ERROR))
+    if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
         return NULL;
 
     /* process a skip request */
@@ -520,13 +490,13 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzdirect(gzFile file)
-{
+int ZEXPORT gzdirect(gzFile file) {
     gz_statep state;
 
     /* get internal structure */
     if (file == NULL)
         return 0;
+
     state = (gz_statep)file;
 
     /* if the state is not known, but we can find out, then do so (this is
@@ -539,14 +509,14 @@ int ZEXPORT gzdirect(gzFile file)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzclose_r(gzFile file)
-{
+int ZEXPORT gzclose_r(gzFile file) {
     int ret, err;
     gz_statep state;
 
     /* get internal structure */
     if (file == NULL)
         return Z_STREAM_ERROR;
+
     state = (gz_statep)file;
 
     /* check that we're reading */
index 90811fb0c8538089ad879f883ae227b6ff9019a1..58b5897970eb8ef66c9921687cce1a5d4cef78ae 100644 (file)
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -3,17 +3,17 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
+#include <stdarg.h>
 #include "gzguts.h"
 
 /* Local functions */
-local int gz_init (gz_statep);
-local int gz_comp (gz_statep, int);
-local int gz_zero (gz_statep, z_off64_t);
+local int gz_init(gz_statep);
+local int gz_comp(gz_statep, int);
+local int gz_zero(gz_statep, z_off64_t);
 
 /* Initialize state for writing a gzip file.  Mark initialization by setting
    state->size to non-zero.  Return -1 on failure or 0 on success. */
-local int gz_init(gz_statep state)
-{
+local int gz_init(gz_statep state) {
     int ret;
     z_stream *strm = &(state->strm);
 
@@ -38,8 +38,7 @@ local int gz_init(gz_statep state)
         strm->zalloc = Z_NULL;
         strm->zfree = Z_NULL;
         strm->opaque = Z_NULL;
-        ret = deflateInit2(strm, state->level, Z_DEFLATED,
-                           MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
+        ret = deflateInit2(strm, state->level, Z_DEFLATED, MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
         if (ret != Z_OK) {
             free(state->out);
             free(state->in);
@@ -66,8 +65,7 @@ local int gz_init(gz_statep state)
    then the deflate() state is reset to start a new gzip stream.  If gz->direct
    is true, then simply write to the output file without compressing, and
    ignore flush. */
-local int gz_comp(gz_statep state, int flush)
-{
+local int gz_comp(gz_statep state, int flush) {
     int ret, got;
     unsigned have;
     z_stream *strm = &(state->strm);
@@ -92,11 +90,9 @@ local int gz_comp(gz_statep state, int flush)
     do {
         /* write out current buffer contents if full, or if flushing, but if
            doing Z_FINISH then don't write until we get to Z_STREAM_END */
-        if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
-            (flush != Z_FINISH || ret == Z_STREAM_END))) {
+        if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && (flush != Z_FINISH || ret == Z_STREAM_END))) {
             have = (unsigned)(strm->next_out - state->x.next);
-            if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
-                         (unsigned)got != have)) {
+            if (have && ((got = write(state->fd, state->x.next, have)) < 0 || (unsigned)got != have)) {
                 gz_error(state, Z_ERRNO, zstrerror());
                 return -1;
             }
@@ -111,8 +107,7 @@ local int gz_comp(gz_statep state, int flush)
         have = strm->avail_out;
         ret = deflate(strm, flush);
         if (ret == Z_STREAM_ERROR) {
-            gz_error(state, Z_STREAM_ERROR,
-                      "internal error: deflate stream corrupt");
+            gz_error(state, Z_STREAM_ERROR, "internal error: deflate stream corrupt");
             return -1;
         }
         have -= strm->avail_out;
@@ -127,8 +122,7 @@ local int gz_comp(gz_statep state, int flush)
 }
 
 /* Compress len zeros to output.  Return -1 on error, 0 on success. */
-local int gz_zero(gz_statep state, z_off64_t len)
-{
+local int gz_zero(gz_statep state, z_off64_t len) {
     int first;
     unsigned n;
     z_stream *strm = &(state->strm);
@@ -140,8 +134,7 @@ local int gz_zero(gz_statep state, z_off64_t len)
     /* compress len zeros (len guaranteed > 0) */
     first = 1;
     while (len) {
-        n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
-            (unsigned)len : state->size;
+        n = GT_OFF(state->size) || (z_off64_t)state->size > len ? (unsigned)len : state->size;
         if (first) {
             memset(state->in, 0, n);
             first = 0;
@@ -157,8 +150,7 @@ local int gz_zero(gz_statep state, z_off64_t len)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzwrite(gzFile file, void const *buf, unsigned len)
-{
+int ZEXPORT gzwrite(gzFile file, void const *buf, unsigned len) {
     unsigned put = len;
     gz_statep state;
     z_stream *strm;
@@ -215,8 +207,7 @@ int ZEXPORT gzwrite(gzFile file, void const *buf, unsigned len)
             if (len && gz_comp(state, Z_NO_FLUSH) == -1)
                 return 0;
         } while (len);
-    }
-    else {
+    } else {
         /* consume whatever's left in the input buffer */
         if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
             return 0;
@@ -234,8 +225,7 @@ int ZEXPORT gzwrite(gzFile file, void const *buf, unsigned len)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzputc(gzFile file, int c)
-{
+int ZEXPORT gzputc(gzFile file, int c) {
     unsigned have;
     unsigned char buf[1];
     gz_statep state;
@@ -280,8 +270,7 @@ int ZEXPORT gzputc(gzFile file, int c)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzputs(gzFile file, const char *str)
-{
+int ZEXPORT gzputs(gzFile file, const char *str) {
     int ret;
     unsigned len;
 
@@ -291,11 +280,8 @@ int ZEXPORT gzputs(gzFile file, const char *str)
     return ret == 0 && len != 0 ? -1 : ret;
 }
 
-#include <stdarg.h>
-
 /* -- see zlib.h -- */
-int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
-{
+int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
     int size, len;
     gz_statep state;
     z_stream *strm;
@@ -341,8 +327,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
     return len;
 }
 
-int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
-{
+int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
     va_list va;
     int ret;
 
@@ -353,8 +338,7 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzflush(gzFile file, int flush)
-{
+int ZEXPORT gzflush(gzFile file, int flush) {
     gz_statep state;
 
     /* get internal structure */
@@ -383,8 +367,7 @@ int ZEXPORT gzflush(gzFile file, int flush)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
-{
+int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
     gz_statep state;
     z_stream *strm;
 
@@ -422,8 +405,7 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
 }
 
 /* -- see zlib.h -- */
-int ZEXPORT gzclose_w(gzFile file)
-{
+int ZEXPORT gzclose_w(gzFile file) {
     int ret = Z_OK;
     gz_statep state;