1/*
2  Copyright (c) 1990-2009 Info-ZIP.  All rights reserved.
3
4  See the accompanying file LICENSE, version 2009-Jan-02 or later
5  (the contents of which are also included in unzip.h) for terms of use.
6  If, for some reason, all these files are missing, the Info-ZIP license
7  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
8*/
9/*---------------------------------------------------------------------------
10    Win32 specific configuration section:
11  ---------------------------------------------------------------------------*/
12
13#ifndef __w32cfg_h
14#define __w32cfg_h
15
16#ifdef __CYGWIN__
17/* We treat the file system underneath the Cygwin Unix emulator environment
18 * as "native VFAT/NTFS" and use the WIN32 API for its special attributes...
19 */
20#  ifdef UNIX
21#    undef UNIX
22#  endif
23#endif
24
25#if (defined(_MSC_VER) && !defined(MSC))
26#  define MSC
27#endif
28
29/* enable multibyte character set support by default */
30#if (!defined(_MBCS) && !defined(NO_MBCS))
31#  define _MBCS
32#endif
33#if (defined(_MBCS) && defined(NO_MBCS))
34#  undef _MBCS
35#endif
36#if (defined(__CYGWIN__) && defined(_MBCS))
37#  undef _MBCS                  /* Cygwin RTL lacks support for __mb_cur_max */
38#endif
39#if (defined(__DJGPP__) && !defined(__EMX__) && defined(_MBCS))
40#  undef _MBCS                  /* __mb_cur_max missing for RSXNTdj 1.6 beta */
41#endif
42
43#include <sys/types.h>          /* off_t, time_t, dev_t, ... */
44#include <sys/stat.h>
45#include <io.h>                 /* read(), open(), etc. */
46#include <time.h>
47#if ((defined(__RSXNT__) || defined(__EMX__)) && !defined(tzset))
48#  define tzset _tzset
49#endif
50#if (defined(__LCC__) && !defined(tzset))
51#  define tzset _tzset
52#endif
53#ifdef __MINGW32__
54   extern void _tzset(void);    /* this is missing in <time.h> */
55#  ifndef tzset
56#    define tzset _tzset
57#  endif
58#endif
59#ifdef W32_USE_IZ_TIMEZONE
60#  ifdef __BORLANDC__
61#    define tzname tzname
62#    define IZTZ_DEFINESTDGLOBALS
63#  endif
64#  ifdef __WATCOMC__
65#    define IZTZ_DEFINESTDGLOBALS
66#  endif
67#  ifndef tzset
68#    define tzset _tzset
69#  endif
70#  ifndef timezone
71#    define timezone _timezone
72#  endif
73#  ifndef daylight
74#    define daylight _daylight
75#  endif
76#  ifndef tzname
77#    define tzname _tzname
78#  endif
79#  if (!defined(NEED__ISINDST) && !defined(__BORLANDC__))
80#    define NEED__ISINDST
81#  endif
82#  ifdef IZTZ_GETLOCALETZINFO
83#    undef IZTZ_GETLOCALETZINFO
84#  endif
85#  define IZTZ_GETLOCALETZINFO GetPlatformLocalTimezone
86#endif /* W32_USE_IZ_TIMEZONE */
87#include <memory.h>
88#if (!defined(__RSXNT__) && !defined(__CYGWIN__))
89#  include <direct.h>           /* mkdir() */
90#endif
91#include <fcntl.h>
92#ifdef __CYGWIN__
93#  include <unistd.h>
94   extern int setmode(int, int);        /* this is missing in <fcntl.h> */
95#endif
96#if (defined(MSC) || defined(__WATCOMC__) || defined(__MINGW32__))
97#  include <sys/utime.h>
98#else
99#  include <utime.h>
100#endif
101#define GOT_UTIMBUF
102
103#ifdef _MBCS
104#  if (!defined(__EMX__) && !defined(__DJGPP__) && !defined(__CYGWIN__))
105#  if (!defined(__MINGW32__) || defined(__MSVCRT__))
106#    include <stdlib.h>
107#    include <mbstring.h>
108     /* for MSC (and compatible compilers), use routines supplied by RTL */
109#    define CLEN(ptr) _mbclen((const uch *)(ptr))
110#    define PREINCSTR(ptr) (ptr = (char *)_mbsinc((const uch *)(ptr)))
111#    define MBSCHR(str, c) (char *)_mbschr((const uch *)(str), (c))
112#    define MBSRCHR(str, c) (char *)_mbsrchr((const uch *)(str), (c))
113#  endif
114#  endif
115#  if (defined(__MINGW32__) && !defined(MB_CUR_MAX))
116#    ifdef __MSVCRT__
117       extern int *__p___mb_cur_max(void);
118#      define MB_CUR_MAX (*__p___mb_cur_max())
119#    else
120       extern int *_imp____mb_cur_max_dll;
121#      define MB_CUR_MAX (*_imp____mb_cur_max_dll)
122#    endif
123#  endif
124#  if (defined(__LCC__) && !defined(MB_CUR_MAX))
125     extern int *_imp____mb_cur_max;
126#    define MB_CUR_MAX (*_imp____mb_cur_max)
127#  endif
128#  if (defined(__DJGPP__) && !defined(__EMX__) && !defined(MB_CUR_MAX))
129     extern int *_imp____mb_cur_max;
130#    define MB_CUR_MAX (*_imp____mb_cur_max)
131#  endif
132#endif
133
134/* for UnZip, the "basic" part of the win32 api is sufficient */
135#ifndef WIN32_LEAN_AND_MEAN
136#  define WIN32_LEAN_AND_MEAN
137#endif
138
139#if defined(__FILEIO_C)
140#  ifndef __CYGWIN__
141#    include <conio.h>
142#  endif
143#  include <windows.h>
144#  ifdef __RSXNT__
145#    include "../win32/rsxntwin.h"
146#  endif
147#  ifndef TIME_ZONE_ID_INVALID
148#    define TIME_ZONE_ID_INVALID  (DWORD)0xFFFFFFFFL
149#  endif
150#endif
151#if (defined(__ENVARGS_C) || defined(__EXTRACT_C) || defined(__UNZIP_C) || \
152     defined(ZCRYPT_INTERNAL))
153#  include <windows.h>
154#  ifdef __RSXNT__
155#    include "../win32/rsxntwin.h"
156#  endif
157#  ifndef TIME_ZONE_ID_INVALID
158#    define TIME_ZONE_ID_INVALID  (DWORD)0xFFFFFFFFL
159#  endif
160#endif
161
162#ifndef Cdecl
163#  define Cdecl __cdecl
164#endif
165
166/* the following definitions are considered as "obsolete" by Microsoft and
167 * might be missing in some versions of <windows.h>
168 */
169#ifndef AnsiToOem
170#  define AnsiToOem CharToOemA
171#endif
172#ifndef OemToAnsi
173#  define OemToAnsi OemToCharA
174#endif
175
176#define DIR_END       '\\'      /* OS uses '\\' as directory separator */
177#define DIR_END2      '/'       /* also check for '/' (RTL may convert) */
178#ifdef DATE_FORMAT
179#  undef DATE_FORMAT
180#endif
181#define DATE_FORMAT   dateformat()
182#ifdef DATE_SEPCHAR
183#  undef DATE_SEPCHAR
184#endif
185#define DATE_SEPCHAR  dateseparator()
186#define lenEOL        2
187#define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
188
189#if (defined(__RSXNT__) && !defined(HAVE_MKTIME))
190#  define HAVE_MKTIME           /* use mktime() in time conversion routines */
191#endif
192#if (defined(MSC) && !defined(HAVE_MKTIME))
193#  define HAVE_MKTIME           /* use mktime() in time conversion routines */
194#endif
195#if (defined(__CYGWIN__) && defined(HAVE_MKTIME))
196#  undef HAVE_MKTIME            /* Cygnus' mktime() implementation is buggy */
197#endif
198#if (defined(W32_USE_IZ_TIMEZONE) && !defined(HAVE_MKTIME))
199#  define HAVE_MKTIME           /* use mktime() in time conversion routines */
200#endif
201#if (!defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME))
202#  define USE_EF_UT_TIME
203#endif
204#if (!defined(NO_DIR_ATTRIB) && !defined(SET_DIR_ATTRIB))
205#  define SET_DIR_ATTRIB
206#endif
207#if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
208#  define TIMESTAMP
209#endif
210#if (!defined(NO_NTSD_EAS) && !defined(NTSD_EAS))
211#  define NTSD_EAS      /* enable NTSD support unless explicitly suppressed */
212#endif
213#if (defined(NTSD_EAS) && !defined(RESTORE_ACL))
214#  define RESTORE_ACL   /* "restore ACLs" only needed when NTSD_EAS active */
215#endif
216#if (!defined(NO_UNICODE_SUPPORT) && !defined(UNICODE_SUPPORT))
217#  define UNICODE_SUPPORT       /* enable UTF-8 filename support by default */
218#endif
219#if (defined(UNICODE_SUPPORT) && !defined(UNICODE_WCHAR))
220#  define UNICODE_WCHAR         /* wchar_t is UTF-16 encoded on WIN32 */
221#endif
222#ifdef UTF8_MAYBE_NATIVE
223#  undef UTF8_MAYBE_NATIVE      /* UTF-8 cannot be system charset on WIN32 */
224#endif
225
226/* The following compiler systems provide or use a runtime library with a
227 * locale-aware isprint() implementation.  For these systems, the "enhanced"
228 * unprintable charcode detection in fnfilter() gets enabled.
229 */
230#if (!defined(HAVE_WORKING_ISPRINT) && !defined(NO_WORKING_ISPRINT))
231#  if defined(MSC) || defined(__BORLANDC__)
232#    define HAVE_WORKING_ISPRINT
233#  endif
234#  if defined(__MINGW32__) && defined(__MSVCRT__)
235#    define HAVE_WORKING_ISPRINT
236#  endif
237#endif
238
239/* WIN32 runs solely on little-endian processors; enable support
240 * for the 32-bit optimized CRC-32 C code by default.
241 */
242#ifdef IZ_CRC_BE_OPTIMIZ
243#  undef IZ_CRC_BE_OPTIMIZ
244#endif
245#if !defined(IZ_CRC_LE_OPTIMIZ) && !defined(NO_CRC_OPTIMIZ)
246#  define IZ_CRC_LE_OPTIMIZ
247#endif
248
249/* handlers for OEM <--> ANSI string conversions */
250#ifdef __RSXNT__
251   /* RSXNT uses OEM coded strings in functions supplied by C RTL */
252#  ifdef CRTL_CP_IS_ISO
253#    undef CRTL_CP_IS_ISO
254#  endif
255#  ifndef CRTL_CP_IS_OEM
256#    define CRTL_CP_IS_OEM
257#  endif
258#else
259   /* "real" native WIN32 compilers use ANSI coded strings in C RTL calls */
260#  ifndef CRTL_CP_IS_ISO
261#    define CRTL_CP_IS_ISO
262#  endif
263#  ifdef CRTL_CP_IS_OEM
264#    undef CRTL_CP_IS_OEM
265#  endif
266#endif
267
268#ifdef CRTL_CP_IS_ISO
269   /* C RTL's file system support assumes ANSI coded strings */
270#  define ISO_TO_INTERN(src, dst)  {if ((src) != (dst)) strcpy((dst), (src));}
271#  define OEM_TO_INTERN(src, dst)  OemToAnsi(src, dst)
272#  define INTERN_TO_ISO(src, dst)  {if ((src) != (dst)) strcpy((dst), (src));}
273#  define INTERN_TO_OEM(src, dst)  AnsiToOem(src, dst)
274#endif /* CRTL_CP_IS_ISO */
275#ifdef CRTL_CP_IS_OEM
276   /* C RTL's file system support assumes OEM coded strings */
277#  define ISO_TO_INTERN(src, dst)  AnsiToOem(src, dst)
278#  define OEM_TO_INTERN(src, dst)  {if ((src) != (dst)) strcpy((dst), (src));}
279#  define INTERN_TO_ISO(src, dst)  OemToAnsi(src, dst)
280#  define INTERN_TO_OEM(src, dst)  {if ((src) != (dst)) strcpy((dst), (src));}
281#endif /* CRTL_CP_IS_OEM */
282#define _OEM_INTERN(str1) OEM_TO_INTERN(str1, str1)
283#define _ISO_INTERN(str1) ISO_TO_INTERN(str1, str1)
284#ifndef WINDLL
285   /* Despite best intentions, for the command-line version UzpPassword()
286    * could return either character set, depending on whether running under
287    * Win95 (DOS-session) or WinNT (native WinNT command interpreter)! */
288#  define STR_TO_CP2(dst, src)  (AnsiToOem(src, dst), dst)
289#  define STR_TO_CP3(dst, src)  (OemToAnsi(src, dst), dst)
290#else
291   /* The WINDLL front end is known to supply ISO/ANSI-coded passwords! */
292#  define STR_TO_CP2(dst, src)  (AnsiToOem(src, dst), dst)
293#endif
294/* dummy defines to disable these functions, they are not needed */
295#define STR_TO_OEM
296#define STR_TO_ISO
297
298/* Static variables that we have to add to Uz_Globs: */
299#define SYSTEM_SPECIFIC_GLOBALS \
300    int created_dir, renamed_fullpath, fnlen;\
301    unsigned nLabelDrive;\
302    char lastRootPath[4];\
303    int lastVolOldFAT, lastVolLocTim;\
304    char *rootpath, *buildpathHPFS, *buildpathFAT, *endHPFS, *endFAT;\
305    ZCONST char *wildname;\
306    char *dirname, matchname[FILNAMSIZ];\
307    int rootlen, have_dirname, dirnamelen, notfirstcall;\
308    zvoid *wild_dir;
309
310/* created_dir, renamed_fullpath, fnlen, and nLabelDrive are used by   */
311/*    both mapname() and checkdir().                                   */
312/* lastRootPath, lastVolOldFAT and lastVolLocTim are used by           */
313/*    IsVolumeOldFAT() and NTQueryVolInfo().                           */
314/* rootlen, rootpath, buildpathHPFS, buildpathFAT, endHPFS, and endFAT */
315/*    are used by checkdir().                                          */
316/* wild_dir, dirname, wildname, matchname[], dirnamelen, have_dirname, */
317/*    and notfirstcall are used by do_wild().                          */
318
319/* This replacement for C-RTL-supplied getch() (or similar) functionality
320 * avoids leaving unabsorbed LFs in the keyboard buffer under Windows95,
321 * and supports the <ALT>+[0]<digit><digit><digit> feature.
322 */
323int getch_win32  OF((void));
324
325/* Up to now, all versions of Microsoft C runtime libraries lack the support
326 * for customized (non-US) switching rules between daylight saving time and
327 * standard time in the TZ environment variable string.
328 * But non-US timezone rules are correctly supported when timezone information
329 * is read from the OS system settings in the Win32 registry.
330 * The following work-around deletes any TZ environment setting from
331 * the process environment.  This results in a fallback of the RTL time
332 * handling code to the (correctly interpretable) OS system settings, read
333 * from the registry.
334 */
335#ifdef USE_EF_UT_TIME
336# if (defined(__WATCOMC__) || defined(__CYGWIN__) || \
337      defined(W32_USE_IZ_TIMEZONE))
338#   define iz_w32_prepareTZenv()
339# else
340#   define iz_w32_prepareTZenv()        putenv("TZ=")
341# endif
342#endif
343
344/* This patch of stat() is useful for at least two compilers.  It is   */
345/* difficult to take a stat() of a root directory under Windows95, so  */
346/* zstat_win32() detects that case and fills in suitable values.       */
347#ifndef __RSXNT__
348#  ifndef W32_STATROOT_FIX
349#    define W32_STATROOT_FIX
350#  endif
351#endif /* !__RSXNT__ */
352
353#define W32_STAT_BANDAID
354#if defined(REENTRANT)
355#  define __W32STAT_GLOBALS__       Uz_Globs *pG,
356#  define __W32STAT_G__             pG,
357#else
358#  define __W32STAT_GLOBALS__
359#  define __W32STAT_G__
360#endif
361#ifdef SSTAT
362#  undef SSTAT
363#endif
364#ifdef WILD_STAT_BUG
365#  define SSTAT(path, pbuf) (iswild(path) || zstat_win32(__W32STAT_G__ path, pbuf))
366#else
367#  define SSTAT(path, pbuf) zstat_win32(__W32STAT_G__ path, pbuf)
368#endif
369
370#ifdef __WATCOMC__
371#  ifdef __386__
372#    ifndef WATCOMC_386
373#      define WATCOMC_386
374#    endif
375#    define __32BIT__
376#    undef far
377#    define far
378#    undef near
379#    define near
380#    undef Cdecl
381#    define Cdecl
382
383/* gaah -- Watcom's docs claim that _get_osfhandle exists, but it doesn't.  */
384#    define _get_osfhandle _os_handle
385
386/* Get asm routines to link properly without using "__cdecl": */
387#    ifndef USE_ZLIB
388#      pragma aux crc32         "_*" parm caller [] value [eax] modify [eax]
389#      pragma aux get_crc_table "_*" parm caller [] value [eax] \
390                                      modify [eax ecx edx]
391#    endif /* !USE_ZLIB */
392#  endif /* __386__ */
393#endif /* __WATCOMC__ */
394
395#define SCREENWIDTH 80
396#define SCREENSIZE(scrrows, scrcols)  screensize(scrrows, scrcols)
397int screensize(int *tt_rows, int *tt_cols);
398
399/* on the DOS or NT console screen, line-wraps are always enabled */
400#define SCREENLWRAP 1
401#define TABSIZE 8
402
403
404/* 64-bit-Integers & Large File Support
405 * (pasted here from Zip 3b, osdep.h - Myles Bennett 7-jun-2004)
406 * (updated from Zip 3.0d - Ed Gordon 6-oct-2004)
407 *
408 *  If this is set it is assumed that the port
409 *  supports 64-bit file calls.  The types are
410 *  defined here.  Any local implementations are
411 *  in w32i64.c and the prototypes for the calls are
412 *  in unzip.h.  Note that a port must support
413 *  these calls fully or should not set
414 *  LARGE_FILE_SUPPORT.
415 */
416
417/* Automatically set ZIP64_SUPPORT if supported */
418
419#ifndef NO_ZIP64_SUPPORT
420# ifndef ZIP64_SUPPORT
421#   if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
422#     define ZIP64_SUPPORT
423#   elif defined(__LCC__)
424      /* LCC links against crtdll.dll -> no support of 64-bit offsets :( */
425#   elif (defined(__WATCOMC__) && (__WATCOMC__ >= 1100))
426#     define ZIP64_SUPPORT
427#   elif (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0520))
428      /* Borland C RTL lacks any support to get/set 64-bit file pointer :( */
429#   endif
430# endif
431#endif
432
433#ifdef ZIP64_SUPPORT
434  /* base type for file offsets and file sizes */
435# if (defined(__GNUC__) || defined(ULONG_LONG_MAX))
436    typedef long long    zoff_t;
437# else
438    /* all other compilers use this as intrinsic 64-bit type */
439    typedef __int64      zoff_t;
440# endif
441# define ZOFF_T_DEFINED
442
443  /* user-defined types and format strings for 64-bit numbers and
444   * file pointer functions  (these depend on the rtl library and library
445   * headers used; they are NOT compiler-specific)
446   */
447# if defined(_MSC_VER) || defined(__MINGW32__) || defined(__LCC__)
448    /* MS C and VC, MinGW32, lcc32 */
449    /* these systems use the Microsoft C RTL */
450
451    /* 64-bit stat struct */
452    typedef struct _stati64 z_stat;
453#   define Z_STAT_DEFINED
454
455#   ifdef __LCC__
456      /* The LCC headers lack these declarations of MSC rtl functions in
457         sys/stat.h. */
458      struct _stati64 {
459        unsigned int st_dev;
460        unsigned short st_ino;
461        unsigned short st_mode;
462        short st_nlink;
463        short st_uid;
464        short st_gid;
465        unsigned int st_rdev;
466        __int64 st_size;
467        time_t st_atime;
468        time_t st_mtime;
469        time_t st_ctime;
470      };
471      int _stati64(const char *, struct _stati64 *);
472      int _fstati64(int, struct _stati64 *);
473       __int64 _lseeki64(int, __int64, int);
474#   endif /* __LCC__ */
475
476    /* printf format size prefix for zoff_t values */
477#   define FZOFFT_FMT "I64"
478#   define FZOFFT_HEX_WID_VALUE "16"
479
480#   define SHORTHDRSTATS "%9I64u  %02u%c%02u%c%02u %02u:%02u  %c"
481#   define SHORTFILETRAILER " --------                   -------\n%9I64u                   %9lu file%s\n"
482
483# elif (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0520))
484    /* Borland C 5.2 or newer */
485
486    /* 64-bit stat struct */
487    typedef struct stati64 z_stat;
488#   define Z_STAT_DEFINED
489
490    /* Borland C does not provide a 64-bit-capable _lseeki64(), so we
491       need to use the stdio.h stream functions instead. */
492#   ifndef USE_STRM_INPUT
493#     define USE_STRM_INPUT
494#   endif
495
496    /* printf format size prefix for zoff_t values */
497#   define FZOFFT_FMT "L"
498#   define FZOFFT_HEX_WID_VALUE "16"
499
500#   define SHORTHDRSTATS "%9Lu  %02u%c%02u%c%02u %02u:%02u  %c"
501#   define SHORTFILETRAILER " --------                   -------\n%9Lu                   %9lu file%s\n"
502
503# elif (defined(__WATCOMC__) && (__WATCOMC__ >= 1100))
504    /* WATCOM C */
505
506    /* 64-bit stat struct */
507    typedef struct _stati64 z_stat;
508#   define Z_STAT_DEFINED
509
510    /* printf format size prefix for zoff_t values */
511#   define FZOFFT_FMT "ll"
512#   define FZOFFT_HEX_WID_VALUE "16"
513
514#   define SHORTHDRSTATS "%9llu  %02u%c%02u%c%02u %02u:%02u  %c"
515#   define SHORTFILETRAILER " --------                   -------\n%9llu                   %9lu file%s\n"
516
517# elif (defined(__IBMC__) && (__IBMC__ >= 350))
518    /* IBM C */
519
520    /* 64-bit stat struct */
521
522    /* printf format size prefix for zoff_t values */
523#   define FZOFFT_FMT "I64"
524#   define FZOFFT_HEX_WID_VALUE "16"
525
526#   define SHORTHDRSTATS "%9I64u  %02u%c%02u%c%02u %02u:%02u  %c"
527#   define SHORTFILETRAILER " --------                   -------\n%9I64u                   %9lu file%s\n"
528
529# endif
530
531#endif
532
533/* If port has LARGE_FILE_SUPPORT then define here
534   to make automatic unless overridden */
535
536#ifndef LARGE_FILE_SUPPORT
537# ifndef NO_LARGE_FILE_SUPPORT
538#   if defined(_MSC_VER) || defined(__MINGW32__)
539#     define LARGE_FILE_SUPPORT
540#   elif defined(__LCC__)
541      /* LCC links against crtdll.dll -> no support of 64-bit offsets :( */
542#   elif defined(__CYGWIN__)
543#     define LARGE_FILE_SUPPORT
544#   elif (defined(__WATCOMC__) && (__WATCOMC__ >= 1100))
545#     define LARGE_FILE_SUPPORT
546#   elif (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0520))
547      /* Borland C RTL lacks any support to get/set 64-bit file pointer :( */
548#   endif
549# endif
550#endif
551
552
553#ifndef LARGE_FILE_SUPPORT
554  /* No Large File Support */
555
556  /* base type for file offsets and file sizes */
557  typedef long zoff_t;
558# define ZOFF_T_DEFINED
559
560  /* stat struct */
561  typedef struct stat z_stat;
562# define Z_STAT_DEFINED
563
564#  define FZOFFT_FMT "l"
565#  define FZOFFT_HEX_WID_VALUE "8"
566
567
568#  define SHORTHDRSTATS "%9lu  %02u%c%02u%c%02u %02u:%02u  %c"
569#  define SHORTFILETRAILER " --------                   -------\n%9lu                   %9lu file%s\n"
570
571#endif /* LARGE_FILE_SUPPORT */
572
573#endif /* !__w32cfg_h */
574