summaryrefslogtreecommitdiffstats
path: root/lib/libz/minigzip.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2010-03-22 21:11:55 +0000
committerdelphij <delphij@FreeBSD.org>2010-03-22 21:11:55 +0000
commit242fa9b7553b2ba79e6c24d9c970b87803969664 (patch)
tree1bab41b7473c7f820d5017fd4e0f8b6bccf0fdd3 /lib/libz/minigzip.c
parenta40c3ddf5af024b9de0a6be58ebdc15e29974cd0 (diff)
parentf956321dcebbe74ca501db23263b30d1c3443b77 (diff)
downloadFreeBSD-src-242fa9b7553b2ba79e6c24d9c970b87803969664.zip
FreeBSD-src-242fa9b7553b2ba79e6c24d9c970b87803969664.tar.gz
Update to zlib 1.2.4 and add versioned symbols to the
library. Sponsored by: iXsystems, Inc.
Diffstat (limited to 'lib/libz/minigzip.c')
-rw-r--r--lib/libz/minigzip.c135
1 files changed, 99 insertions, 36 deletions
diff --git a/lib/libz/minigzip.c b/lib/libz/minigzip.c
index b29d14a..84d823b 100644
--- a/lib/libz/minigzip.c
+++ b/lib/libz/minigzip.c
@@ -1,5 +1,5 @@
/* minigzip.c -- simulate gzip using the zlib compression library
- * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * Copyright (C) 1995-2006, 2010 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -13,11 +13,10 @@
* or in pipe mode.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+/* @(#) $Id$ */
-#include <stdio.h>
#include "zlib.h"
+#include <stdio.h>
#ifdef STDC
# include <string.h>
@@ -55,6 +54,70 @@ __FBSDID("$FreeBSD$");
extern int unlink OF((const char *));
#endif
+#if defined(UNDER_CE) && defined(NO_ERRNO_H)
+# include <windows.h>
+# define perror(s) pwinerror(s)
+
+/* Map the Windows error number in ERROR to a locale-dependent error
+ message string and return a pointer to it. Typically, the values
+ for ERROR come from GetLastError.
+
+ The string pointed to shall not be modified by the application,
+ but may be overwritten by a subsequent call to strwinerror
+
+ The strwinerror function does not change the current setting
+ of GetLastError. */
+
+static char *strwinerror (error)
+ DWORD error;
+{
+ static char buf[1024];
+
+ wchar_t *msgbuf;
+ DWORD lasterr = GetLastError();
+ DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ NULL,
+ error,
+ 0, /* Default language */
+ (LPVOID)&msgbuf,
+ 0,
+ NULL);
+ if (chars != 0) {
+ /* If there is an \r\n appended, zap it. */
+ if (chars >= 2
+ && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
+ chars -= 2;
+ msgbuf[chars] = 0;
+ }
+
+ if (chars > sizeof (buf) - 1) {
+ chars = sizeof (buf) - 1;
+ msgbuf[chars] = 0;
+ }
+
+ wcstombs(buf, msgbuf, chars + 1);
+ LocalFree(msgbuf);
+ }
+ else {
+ sprintf(buf, "unknown win32 error (%ld)", error);
+ }
+
+ SetLastError(lasterr);
+ return buf;
+}
+
+static void pwinerror (s)
+ const char *s;
+{
+ if (s && *s)
+ fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ()));
+ else
+ fprintf(stderr, "%s\n", strwinerror(GetLastError ()));
+}
+
+#endif /* UNDER_CE && NO_ERRNO_H */
+
#ifndef GZ_SUFFIX
# define GZ_SUFFIX ".gz"
#endif
@@ -201,9 +264,9 @@ void file_compress(file, mode)
if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
fprintf(stderr, "%s: filename too long\n", prog);
- exit(1);
+ exit(1);
}
-
+
strcpy(outfile, file);
strcat(outfile, GZ_SUFFIX);
@@ -237,7 +300,7 @@ void file_uncompress(file)
if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) {
fprintf(stderr, "%s: filename too long\n", prog);
- exit(1);
+ exit(1);
}
strcpy(buf, file);
@@ -304,9 +367,9 @@ int main(argc, argv)
while (argc > 0) {
if (strcmp(*argv, "-c") == 0)
- copyout = 1;
+ copyout = 1;
else if (strcmp(*argv, "-d") == 0)
- uncompr = 1;
+ uncompr = 1;
else if (strcmp(*argv, "-f") == 0)
outmode[3] = 'f';
else if (strcmp(*argv, "-h") == 0)
@@ -335,36 +398,36 @@ int main(argc, argv)
gz_compress(stdin, file);
}
} else {
- if (copyout) {
- SET_BINARY_MODE(stdout);
- }
+ if (copyout) {
+ SET_BINARY_MODE(stdout);
+ }
do {
if (uncompr) {
- if (copyout) {
- file = gzopen(*argv, "rb");
- if (file == NULL)
- fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv);
- else
- gz_uncompress(file, stdout);
- } else {
- file_uncompress(*argv);
- }
+ if (copyout) {
+ file = gzopen(*argv, "rb");
+ if (file == NULL)
+ fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv);
+ else
+ gz_uncompress(file, stdout);
+ } else {
+ file_uncompress(*argv);
+ }
} else {
- if (copyout) {
- FILE * in = fopen(*argv, "rb");
-
- if (in == NULL) {
- perror(*argv);
- } else {
- file = gzdopen(fileno(stdout), outmode);
- if (file == NULL) error("can't gzdopen stdout");
-
- gz_compress(in, file);
- }
-
- } else {
- file_compress(*argv, outmode);
- }
+ if (copyout) {
+ FILE * in = fopen(*argv, "rb");
+
+ if (in == NULL) {
+ perror(*argv);
+ } else {
+ file = gzdopen(fileno(stdout), outmode);
+ if (file == NULL) error("can't gzdopen stdout");
+
+ gz_compress(in, file);
+ }
+
+ } else {
+ file_compress(*argv, outmode);
+ }
}
} while (argv++, --argc);
}
OpenPOWER on IntegriCloud