diff options
Diffstat (limited to 'minigzip.c')
-rw-r--r-- | minigzip.c | 66 |
1 files changed, 65 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* minigzip.c -- simulate gzip using the zlib compression library | 1 | /* minigzip.c -- simulate gzip using the zlib compression library |
2 | * Copyright (C) 1995-2006 Jean-loup Gailly. | 2 | * Copyright (C) 1995-2006, 2010 Jean-loup Gailly. |
3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -54,6 +54,70 @@ | |||
54 | extern int unlink OF((const char *)); | 54 | extern int unlink OF((const char *)); |
55 | #endif | 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 | #ifndef GZ_SUFFIX | 121 | #ifndef GZ_SUFFIX |
58 | # define GZ_SUFFIX ".gz" | 122 | # define GZ_SUFFIX ".gz" |
59 | #endif | 123 | #endif |