Changeset f7d9aea2 in rtems
- Timestamp:
- 03/18/11 10:11:20 (13 years ago)
- Branches:
- 4.11, 5, master
- Children:
- 5a7aa10
- Parents:
- df7764c3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/zlib/minigzip.c
rdf7764c3 rf7d9aea2 1 1 /* minigzip.c -- simulate gzip using the zlib compression library 2 * Copyright (C) 1995-200 5Jean-loup Gailly.2 * Copyright (C) 1995-2006, 2010 Jean-loup Gailly. 3 3 * For conditions of distribution and use, see copyright notice in zlib.h 4 4 */ … … 16 16 /* @(#) $Id$ */ 17 17 18 #include "zlib.h" 18 19 #include <stdio.h> 19 #include "zlib.h"20 20 21 21 #ifdef STDC … … 55 55 #endif 56 56 57 #if defined(UNDER_CE) && defined(NO_ERRNO_H) 58 # include <windows.h> 59 # define perror(s) pwinerror(s) 60 61 /* Map the Windows error number in ERROR to a locale-dependent error 62 message string and return a pointer to it. Typically, the values 63 for ERROR come from GetLastError. 64 65 The string pointed to shall not be modified by the application, 66 but may be overwritten by a subsequent call to strwinerror 67 68 The strwinerror function does not change the current setting 69 of GetLastError. */ 70 71 static char *strwinerror (error) 72 DWORD error; 73 { 74 static char buf[1024]; 75 76 wchar_t *msgbuf; 77 DWORD lasterr = GetLastError(); 78 DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM 79 | FORMAT_MESSAGE_ALLOCATE_BUFFER, 80 NULL, 81 error, 82 0, /* Default language */ 83 (LPVOID)&msgbuf, 84 0, 85 NULL); 86 if (chars != 0) { 87 /* If there is an \r\n appended, zap it. */ 88 if (chars >= 2 89 && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { 90 chars -= 2; 91 msgbuf[chars] = 0; 92 } 93 94 if (chars > sizeof (buf) - 1) { 95 chars = sizeof (buf) - 1; 96 msgbuf[chars] = 0; 97 } 98 99 wcstombs(buf, msgbuf, chars + 1); 100 LocalFree(msgbuf); 101 } 102 else { 103 sprintf(buf, "unknown win32 error (%ld)", error); 104 } 105 106 SetLastError(lasterr); 107 return buf; 108 } 109 110 static void pwinerror (s) 111 const char *s; 112 { 113 if (s && *s) 114 fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ())); 115 else 116 fprintf(stderr, "%s\n", strwinerror(GetLastError ())); 117 } 118 119 #endif /* UNDER_CE && NO_ERRNO_H */ 120 57 121 #ifndef GZ_SUFFIX 58 122 # define GZ_SUFFIX ".gz" … … 199 263 gzFile out; 200 264 265 if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) { 266 fprintf(stderr, "%s: filename too long\n", prog); 267 exit(1); 268 } 269 201 270 strcpy(outfile, file); 202 271 strcat(outfile, GZ_SUFFIX); … … 228 297 FILE *out; 229 298 gzFile in; 230 uInt len = (uInt)strlen(file); 299 size_t len = strlen(file); 300 301 if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { 302 fprintf(stderr, "%s: filename too long\n", prog); 303 exit(1); 304 } 231 305 232 306 strcpy(buf, file); … … 259 333 260 334 /* =========================================================================== 261 * Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...] 335 * Usage: minigzip [-c] [-d] [-f] [-h] [-r] [-1 to -9] [files...] 336 * -c : write to standard output 262 337 * -d : decompress 263 338 * -f : compress with Z_FILTERED … … 271 346 char *argv[]; 272 347 { 348 int copyout = 0; 273 349 int uncompr = 0; 274 350 gzFile file; 275 char outmode[20];351 char *bname, outmode[20]; 276 352 277 353 strcpy(outmode, "wb6 "); 278 354 279 355 prog = argv[0]; 356 bname = strrchr(argv[0], '/'); 357 if (bname) 358 bname++; 359 else 360 bname = argv[0]; 280 361 argc--, argv++; 281 362 363 if (!strcmp(bname, "gunzip")) 364 uncompr = 1; 365 else if (!strcmp(bname, "zcat")) 366 copyout = uncompr = 1; 367 282 368 while (argc > 0) { 283 if (strcmp(*argv, "-d") == 0) 369 if (strcmp(*argv, "-c") == 0) 370 copyout = 1; 371 else if (strcmp(*argv, "-d") == 0) 284 372 uncompr = 1; 285 373 else if (strcmp(*argv, "-f") == 0) … … 311 399 } 312 400 } else { 401 if (copyout) { 402 SET_BINARY_MODE(stdout); 403 } 313 404 do { 314 405 if (uncompr) { 315 file_uncompress(*argv); 406 if (copyout) { 407 file = gzopen(*argv, "rb"); 408 if (file == NULL) 409 fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv); 410 else 411 gz_uncompress(file, stdout); 412 } else { 413 file_uncompress(*argv); 414 } 316 415 } else { 317 file_compress(*argv, outmode); 416 if (copyout) { 417 FILE * in = fopen(*argv, "rb"); 418 419 if (in == NULL) { 420 perror(*argv); 421 } else { 422 file = gzdopen(fileno(stdout), outmode); 423 if (file == NULL) error("can't gzdopen stdout"); 424 425 gz_compress(in, file); 426 } 427 428 } else { 429 file_compress(*argv, outmode); 430 } 318 431 } 319 432 } while (argv++, --argc);
Note: See TracChangeset
for help on using the changeset viewer.