~ubuntu-branches/ubuntu/lucid/perl-tk/lucid

« back to all changes in this revision

Viewing changes to PNG/zlib/minigzip.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Tuckley
  • Date: 2008-02-15 13:56:59 UTC
  • mfrom: (1.1.3 upstream) (4.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20080215135659-ru2oqlykuju20fav
Tags: 1:804.028-1
* New Upstream Release (Closes: #463080).
* Update to Debhelper v5.
* Build with XFT=1 (Closes: #411129).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* minigzip.c -- simulate gzip using the zlib compression library
2
 
 * Copyright (C) 1995-2002 Jean-loup Gailly.
3
 
 * For conditions of distribution and use, see copyright notice in zlib.h 
 
2
 * Copyright (C) 1995-2005 Jean-loup Gailly.
 
3
 * For conditions of distribution and use, see copyright notice in zlib.h
4
4
 */
5
5
 
6
6
/*
21
21
#ifdef STDC
22
22
#  include <string.h>
23
23
#  include <stdlib.h>
24
 
#else
25
 
   extern void exit  OF((int));
26
24
#endif
27
25
 
28
26
#ifdef USE_MMAP
31
29
#  include <sys/stat.h>
32
30
#endif
33
31
 
34
 
#if defined(MSDOS) || defined(OS2) || defined(WIN32)
 
32
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
35
33
#  include <fcntl.h>
36
34
#  include <io.h>
37
35
#  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
112
110
    if (gz_compress_mmap(in, out) == Z_OK) return;
113
111
#endif
114
112
    for (;;) {
115
 
        len = fread(buf, 1, sizeof(buf), in);
 
113
        len = (int)fread(buf, 1, sizeof(buf), in);
116
114
        if (ferror(in)) {
117
115
            perror("fread");
118
116
            exit(1);
147
145
    if (buf_len <= 0) return Z_ERRNO;
148
146
 
149
147
    /* Now do the actual mmap: */
150
 
    buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0); 
 
148
    buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
151
149
    if (buf == (caddr_t)(-1)) return Z_ERRNO;
152
150
 
153
151
    /* Compress the whole file at once: */
179
177
        if (len == 0) break;
180
178
 
181
179
        if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
182
 
            error("failed fwrite");
183
 
        }
 
180
            error("failed fwrite");
 
181
        }
184
182
    }
185
183
    if (fclose(out)) error("failed fclose");
186
184
 
229
227
    char *infile, *outfile;
230
228
    FILE  *out;
231
229
    gzFile in;
232
 
    int len = strlen(file);
 
230
    uInt len = (uInt)strlen(file);
233
231
 
234
232
    strcpy(buf, file);
235
233
 
260
258
 
261
259
 
262
260
/* ===========================================================================
263
 
 * Usage:  minigzip [-d] [-f] [-h] [-1 to -9] [files...]
 
261
 * Usage:  minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...]
264
262
 *   -d : decompress
265
263
 *   -f : compress with Z_FILTERED
266
264
 *   -h : compress with Z_HUFFMAN_ONLY
 
265
 *   -r : compress with Z_RLE
267
266
 *   -1 to -9 : compression level
268
267
 */
269
268
 
282
281
 
283
282
    while (argc > 0) {
284
283
      if (strcmp(*argv, "-d") == 0)
285
 
        uncompr = 1;
 
284
        uncompr = 1;
286
285
      else if (strcmp(*argv, "-f") == 0)
287
 
        outmode[3] = 'f';
 
286
        outmode[3] = 'f';
288
287
      else if (strcmp(*argv, "-h") == 0)
289
 
        outmode[3] = 'h';
 
288
        outmode[3] = 'h';
 
289
      else if (strcmp(*argv, "-r") == 0)
 
290
        outmode[3] = 'R';
290
291
      else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
291
 
               (*argv)[2] == 0)
292
 
        outmode[2] = (*argv)[1];
 
292
               (*argv)[2] == 0)
 
293
        outmode[2] = (*argv)[1];
293
294
      else
294
 
        break;
 
295
        break;
295
296
      argc--, argv++;
296
297
    }
 
298
    if (outmode[3] == ' ')
 
299
        outmode[3] = 0;
297
300
    if (argc == 0) {
298
301
        SET_BINARY_MODE(stdin);
299
302
        SET_BINARY_MODE(stdout);
315
318
            }
316
319
        } while (argv++, --argc);
317
320
    }
318
 
    exit(0);
319
 
    return 0; /* to avoid warning */
 
321
    return 0;
320
322
}