1/*
2  Copyright (c) 1990-1999 Info-ZIP.  All rights reserved.
3
4  See the accompanying file LICENSE, version 1999-Oct-05 or later
5  (the contents of which are also included in zip.h) for terms of use.
6  If, for some reason, both of these files are missing, the Info-ZIP license
7  also may be found at:  ftp://ftp.cdrom.com/pub/infozip/license.html
8*/
9/* The symbol DOS is used throughout the Zip source to identify code portions
10 * specific to the MSDOS port.
11 * Just to make sure, we check that it is set.
12 * (Currently, this should should not be neccessary, since currently it has
13 * to be set on the compiler command line to get this file read in.)
14 */
15#ifndef DOS
16#  define DOS
17#endif
18
19/* The symbol MSDOS is consistently used in the generic source files
20 * to identify code to support for MSDOS (and MSDOS related) stuff.
21 * e.g: FAT or (FAT like) file systems,
22 *      '\\' as directory separator in paths,
23 *      "\r\n" as record (line) terminator in text files, ...
24 *
25 * IMPORTANT Note:
26 *  This symbol is not unique for the MSDOS port !!!!!!
27 *  It is also defined by ports to some other OS which are (to some extend)
28 *  considered DOS compatible.
29 *  Examples are: OS/2 (OS2), Windows NT and Windows 95 (WIN32).
30 *
31 */
32#ifndef MSDOS
33#  define MSDOS
34#endif
35
36/* Power C is similar to Turbo C */
37#ifdef __POWERC
38#  define __TURBOC__
39#endif /* __POWERC */
40
41/* Automatic setting of the common Microsoft C idenfifier MSC.
42 * NOTE: Watcom also defines M_I*86 !
43 */
44#if defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__))
45#  ifndef MSC
46#    define MSC                 /* This should work for older MSC, too!  */
47#  endif
48#endif
49
50#if !defined(__GO32__) && !defined(__EMX__)
51#  define NO_UNISTD_H
52#endif
53
54#if defined(__WATCOMC__) && defined(__386__)
55#  define WATCOMC_386
56#endif
57
58#ifdef WINDLL
59#  define MSWIN
60#  define MEMORY16
61#endif
62
63
64#if !defined(__EMX__) && !defined(__GO32__) && !defined(WATCOMC_386)
65#if !defined(WINDLL)
66#  define MSDOS16 /* 16 bit MSDOS only */
67#  define MEMORY16
68#endif
69#endif
70
71#if !defined(NO_ASM) && !defined(ASMV)
72#  define ASMV
73#endif
74
75/* enable creation of UTC time fields unless explicitely suppressed */
76#if !defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME)
77#  define USE_EF_UT_TIME
78#endif
79
80/* check that TZ environment variable is defined before using UTC times */
81#if (!defined(NO_IZ_CHECK_TZ) && !defined(IZ_CHECK_TZ))
82#  define IZ_CHECK_TZ
83#endif
84
85#ifdef MEMORY16
86#  ifndef NO_ASM
87#    define ASM_CRC 1
88#  endif /* ?NO_ASM */
89#  ifdef __TURBOC__
90#    include <alloc.h>
91#    if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
92#      if defined(DYNAMIC_CRC_TABLE) && defined(DYNALLOC_CRCTAB)
93        error: No dynamic CRC table allocation with Borland C far data models.
94#      endif /* DYNAMIC_CRC_TABLE */
95#    endif /* Turbo/Borland C far data memory models */
96#    define nearmalloc malloc
97#    define nearfree   free
98#    define DYN_ALLOC
99#  else /* !__TURBOC__ */
100#    include <malloc.h>
101#    define nearmalloc _nmalloc
102#    define nearfree   _nfree
103#    define farmalloc  _fmalloc
104#    define farfree    _ffree
105#  endif /* ?__TURBOC__ */
106#  define MY_ZCALLOC 1
107#  ifdef SMALL_MEM
108#    define CBSZ 2048
109#    define ZBSZ 2048
110#  endif
111#  ifdef MEDIUM_MEM
112#    define CBSZ 4096
113#    define ZBSZ 4096
114#  endif
115#  ifndef CBSZ
116#    define CBSZ 8192
117#    define ZBSZ 8192
118#  endif
119#endif /* MEMORY16 */
120
121
122#ifdef MATCH
123#  undef MATCH
124#endif
125#define MATCH dosmatch          /* use DOS style wildcard matching */
126
127#define USE_CASE_MAP
128
129#define ROUNDED_TIME(time)  (((time) + 1) & (~1))
130#define PROCNAME(n) (action == ADD || action == UPDATE ? wild(n) : \
131                     procname(n, 1))
132
133#define FOPR "rb"
134#define FOPM "r+b"
135#define FOPW "wb"
136
137#include <sys/types.h>
138#include <sys/stat.h>
139#include <io.h>
140
141#ifdef ZCRYPT_INTERNAL
142#  ifdef WINDLL
143#    define ZCR_SEED2     (unsigned)3141592654L /* use PI as seed pattern */
144#  else
145#    ifndef __GO32__
146#      include <process.h>      /* getpid() declaration for srand seed */
147#    endif
148#  endif
149#endif
150
151/*
152 * djgpp 1.x did not declare these
153 */
154#if defined(__GO32__) && !defined(__DJGPP__)
155char *strlwr(char *);
156int setmode(int, int);
157#endif
158
159#ifdef __WATCOMC__
160#  define NO_MKTEMP
161#  define HAS_OPENDIR
162#  define SSTAT stat_bandaid
163   int stat_bandaid(const char *path, struct stat *buf);
164
165/* Get asm routines to link properly without using "__cdecl": */
166#  ifdef __386__
167#    ifdef ASMV
168#      pragma aux match_init    "_*" parm caller [] modify []
169#      pragma aux longest_match "_*" parm caller [] value [eax] \
170                                      modify [eax ecx edx]
171#    endif
172#    ifndef USE_ZLIB
173#      pragma aux crc32         "_*" parm caller [] value [eax] modify [eax]
174#      pragma aux get_crc_table "_*" parm caller [] value [eax] \
175                                      modify [eax ecx edx]
176#    endif /* !USE_ZLIB */
177#  else /* !__386__ */
178#    ifdef ASMV
179#      pragma aux match_init    "_*" parm caller [] loadds modify [ax bx]
180#      pragma aux longest_match "_*" parm caller [] loadds value [ax] \
181                                      modify [ax bx cx dx es]
182#    endif /* ASMV */
183#    ifndef USE_ZLIB
184#      pragma aux crc32         "_*" parm caller [] value [ax dx] \
185                                      modify [ax bx cx dx es]
186#      pragma aux get_crc_table "_*" parm caller [] value [ax] \
187                                      modify [ax bx cx dx]
188#    endif /* !USE_ZLIB */
189#  endif /* ?__386__ */
190#endif /* __WATCOMC__ */
191
192/*
193 * Wrapper function to get around the MSC7 00:00:00 31 Dec 1899 time base,
194 * see msdos.c for more info
195 */
196
197#if defined(_MSC_VER) && _MSC_VER == 700
198#  define localtime(t) msc7_localtime(t)
199#endif
200
201#if (defined(__TURBOC__) && !defined(__BORLANDC__) && __TURBOC__ <= 0x0201)
202#  ifndef NO_MKTIME
203#    define NO_MKTIME           /* TC 2.01 and earlier do not supply mktime() */
204#  endif
205#endif
206