1 /*
2  * $Id: environ.h,v 1.15 2005/06/21 19:53:14 andrew_belov Exp $
3  * ---------------------------------------------------------------------------
4  * All environment-specific declarations are held here.
5  *
6  */
7 
8 #ifndef ENVIRON_INCLUDED
9 #define ENVIRON_INCLUDED
10 
11 /* First of all, let's try to guess what kind of compiler we're using. The
12    COMPILER macro will lead us all the way */
13 
14 #ifndef C_DEFS_INCLUDED                 /* All-time definitions */
15  #include "c_defs.h"
16 #endif
17 
18 #define GENERIC                    0
19 
20 #define BCC                        1
21 #define MSC                        2
22 #define ICC                        3
23 #define GCC                        4
24 #define HIGHC                      5
25 #define WCC                        6
26 #define MSVC                       7
27 
28 #if defined(__TURBOC__)||defined(__BORLANDC__)
29  #define COMPILER BCC
30 #elif defined(_MSC_VER)||defined(_QC)
31   #ifdef _WIN32
32    #define COMPILER MSVC
33   #else
34    #define COMPILER MSC
35    #ifdef MSC_VER
36     #error BUG
37    #endif
38    #if (defined(_MSC_VER)&&_MSC_VER<600)||(!defined(_MSC_VER)&&defined(_QC))
39     #define MSC_ANCIENT                   /* Old-style Microsoft compiler */
40    #endif
41  #endif
42 #elif defined(__IBMC__)||defined(__IBMCPP__)
43  #define COMPILER ICC
44 #elif defined(__GNUC__)
45  #define COMPILER GCC
46 #elif defined(__WATCOMC__)
47  #define COMPILER WCC
48  #ifdef M_I386
49   #define __32BIT__
50  #endif
51 #elif defined(__HIGHC__)||defined(__HIGHC_ANSI__)||defined(_OS2)
52  #define COMPILER HIGHC
53  #define __32BIT__
54 #else
55  #define COMPILER GENERIC
56 #endif
57 
58 /* Now, make it clear about target OS */
59 
60 #define DOS                        1
61 #define OS2                        2    /* OS/2-32 is OS2+__32BIT__ */
62 #ifdef UNIX
63  #undef UNIX
64 #endif
65 #define UNIX                       3
66 #define WIN32                      4
67 
68 #if defined(_OS2)||defined(__OS2__)||defined(__EMX__)
69  #define TARGET                  OS2
70 #elif defined(_WIN32)
71  #define TARGET                WIN32
72 #elif defined(_UNIX)
73  #define TARGET                 UNIX
74 #else
75  #define TARGET                  DOS
76 #endif
77 
78 #if TARGET==DOS||TARGET==OS2&&!defined(__32BIT__)
79  #define TILED
80 #endif
81 
82 #if TARGET!=UNIX
83  #define HAVE_DRIVES
84  #define HAVE_VOL_LABELS
85 #endif
86 
87 #if TARGET==OS2||TARGET==WIN32
88  #define HAVE_EAS
89 #endif
90 
91 #include <ctype.h>
92 
93 #if COMPILER==BCC
94  #include <alloc.h>
95 #elif COMPILER==MSC||COMPILER==MSVC
96  #include <malloc.h>
97 #endif
98  #include <errno.h>
99  #include <string.h>
100  #include <stdarg.h>
101  #include <stdio.h>
102  #if COMPILER==ICC&&defined(DEBUG)
103   #define __DEBUG_ALLOC__               /* For heap checking */
104  #endif
105  #include <stdlib.h>
106  #include <time.h>
107 #if COMPILER==BCC
108  #include <values.h>
109 #else
110  #include <limits.h>
111 #endif
112 #if TARGET!=UNIX
113  #include <io.h>
114 #endif
115 #if COMPILER==BCC
116  #include <dir.h>
117 #elif COMPILER!=GCC && !defined(SUNOS)
118  #include <direct.h>
119 #endif
120 
121 /* OS-dependent headers */
122 
123 #if TARGET==DOS
124  #include <dos.h>
125 #elif TARGET==OS2
126  #define INCL_BASE
127  #include <os2.h>
128 #elif TARGET==WIN32
129  #include <windows.h>
130 #elif TARGET==UNIX
131  #include <dirent.h>
132  #include <sys/types.h>
133  #include <sys/stat.h>                  /* For dev_t, chmod(), etc. */
134 #endif
135 
136 /* Keywords remapping */
137 
138 #if !defined(TILED)
139  #ifndef _WIN32
140   #define FAR
141   #define NEAR
142  #endif
143  #define S_NEAR
144 #elif COMPILER==BCC
145  #define FAR                     far
146  #define NEAR                   near
147  #define S_NEAR                 NEAR
148 #elif COMPILER==MSC
149  #if TARGET==DOS
150   #ifdef MSC_ANCIENT
151    #define FAR                   far
152    #define NEAR                 near
153   #else
154    #define FAR                  _far
155    #define NEAR                _near
156   #endif
157  #endif
158  #ifndef MSC_ANCIENT
159   #define asm                   _asm
160  #endif
161  #define S_NEAR                 NEAR
162 #else
163  #error *** A FAR/NEAR translation must be defined for this compiler!
164 #endif
165 
166 /* Special functions enablement */
167 
168 #if COMPILER==MSC
169  #define FINETUNE_BUFSIZ                /* Alternate adjustment method */
170 #endif
171 
172 #if defined(TILED)&&!defined(MSC_ANCIENT)
173  #define ASM8086                        /* Enable assembly routines */
174 #endif
175 
176 /* Library functions/equates remapping */
177 
178 #if !defined(TILED)
179  #define farfree                free
180  #define farmalloc            malloc
181  #define farrealloc          realloc
182  #define farcalloc            calloc
183  #define coreleft()          1048576    /* Don't know/care about it */
184 #elif COMPILER==MSC
185  #define farfree              _ffree
186  #define farmalloc(s) _fmalloc((size_t)s)
187  #define farrealloc(p, s)  _frealloc(p, (size_t)s)
188  #define farcalloc(n, s) _fcalloc((size_t)(n), (size_t)(s))
189  #define coreleft            _memmax    /* Size of largest unallocated block */
190 #endif
191 
192 #if COMPILER==MSC
193  #define findfirst    _dos_findfirst
194  #define findnext      _dos_findnext
195  #define getvect        _dos_getvect
196  #define setvect        _dos_setvect
197  #ifdef MSC_ANCIENT
198   #define _far                   far
199  #endif
200  #if _MSC_VER>=0x0700
201   #define diskfree_t     _diskfree_t
202   #define dosdate_t       _dosdate_t
203   #define dostime_t       _dostime_t
204   #define _far                 __far
205   #define find_t             _find_t
206   #define _interrupt     __interrupt
207   #define rccoord          __rccoord
208   #define stackavail     _stackavail
209   #define strlwr             _strlwr
210   #define strupr             _strupr
211   #define videoconfig  __videoconfig
212  #else
213   #define _close               close
214   #define _chmod               chmod
215   #define _creat               creat
216   #define _open                 open
217   #define _read                 read
218   #define _write               write
219  #endif
220  #if _MSC_VER<600
221   #define _fcalloc           fcalloc
222   #define _fmemcmp           fmemcmp
223   #define _fmemset           fmemset
224   #define _frealloc         frealloc
225   #define _fstrcat           fstrcat
226   #define _fstrchr           fstrchr
227   #define _fstrcmp           fstrcmp
228   #define _fstrcpy           fstrcpy
229   #define _fstrlen           fstrlen
230  #endif
231 #endif
232 #if (COMPILER==MSC&&_MSC_VER>=0x0700)||COMPILER==IBMC||COMPILER==HIGHC||TARGET==OS2&&defined(LIBC)
233  #define filelength      _filelength
234  #define fcloseall        _fcloseall
235 #endif
236 #if COMPILER==BCC||COMPILER==MSC
237  #define _lseek                lseek
238 #endif
239 #if COMPILER==ICC||COMPILER==HIGHC
240  #define mkdir                _mkdir
241 #endif
242 #if TARGET==UNIX
243  #ifndef __QNXNTO__
244     #define O_BINARY                  0    /* N/A under UNIX */
245  #endif /* __QNXNTO__ */
246  #define _lseek                lseek
247  #define _open                  open
248  #define _write                write
249  #define _read                  read
250  #define _close                close
251 #endif
252 /* BSD 4.3 LIBC forwarders */
253 #ifdef HAVE_STRCASECMP
254  #define stricmp          strcasecmp
255  #define strnicmp        strncasecmp
256 #endif
257 
258 /* Watcom variables remapping: the "-5r" convention requires this */
259 
260 #if TARGET==OS2&&COMPILER==WCC&&defined(LIBC)
261  #pragma aux stdin "*"
262  #pragma aux stdout "*"
263  #pragma aux stderr "*"
264  #pragma aux stdaux "*"
265  #pragma aux stdprn "*"
266  #pragma aux _timezone "*"
267  #pragma aux _daylight "*"
268  #pragma aux errno "*"
269 #endif
270 
271 /* MetaWare High C/C++, GCC, etc. add-ons */
272 
273 #if !defined(HAVE_MIN)&&!defined(min)
274  #define min(a, b) ((a)<(b)?(a):(b))
275 #endif
276 
277 #if !defined(HAVE_MAX)&&!defined(max)
278  #define max(a, b) ((a)>(b)?(a):(b))
279 #endif
280 
281 /* Structures that are already present in Borland C but missing from MS C */
282 
283 #if COMPILER!=BCC
284 
285 /* DOS FCB */
286 
287 struct fcb
288 {
289  char fcb_drive;
290  char fcb_name[8];
291  char fcb_ext[3];
292  short fcb_curblk;
293  short fcb_recsize;
294  long fcb_filsize;
295  short fcb_date;
296  char fcb_resv[10];
297  char fcb_currec;
298  long fcb_random;
299 };
300 
301 /* DOS Extended FCB */
302 
303 struct xfcb
304 {
305  char xfcb_flag;
306  char xfcb_resv[5];
307  char xfcb_attr;
308  struct fcb xfcb_fcb;
309 };
310 
311 /* Time structure */
312 
313 struct time
314 {
315  unsigned char ti_min;
316  unsigned char ti_hour;
317  unsigned char ti_hund;
318  unsigned char ti_sec;
319 };
320 
321 /* Date structure */
322 
323 struct date
324 {
325  int da_year;
326  char da_day;
327  char da_mon;
328 };
329 
330 
331 #endif
332 
333 /* Far pointer creation macro */
334 
335 #ifndef MK_FP
336  #define MK_FP(seg,ofs)  ((void FAR *)(((unsigned long)seg<<16)+(unsigned long)ofs))
337 #endif
338 
339 /* Far memory comparison macro/function */
340 
341 #if !defined(TILED)
342  #define far_memcmp           memcmp
343 #elif COMPILER==BCC
344  #include "fmemcmp.h"
345 #elif COMPILER==MSC
346  #define far_memcmp         _fmemcmp
347 #endif
348 
349 /* Error message output */
350 
351 #if COMPILER==BCC
352  #define error_report() msg_cprintf(H_ERR, M_ERROR_CODE, errno, strerror(errno))
353  #define error_freport() msg_cprintf(H_ERR, M_ERROR_CODE, errno, strerror(errno))
354 #else
355  /* LIBCS.DLL complains about missing message resources */
356  #if defined(LIBC)&&TARGET==OS2
357   #define error_report()
358  #else
359   #define error_report() \
360           { \
361            msg_cprintf(H_ERR, M_ERROR_CODE, errno, strerror(errno)); \
362            msg_cprintf(H_ERR, (FMSG *)lf); \
363           }
364  #endif
365 #endif
366 
367 /* Signal handler parameter set */
368 
369 #if COMPILER==BCC
370  #define SIGHDLPARAMS
371 #else
372  #define SIGHDLPARAMS        int sig
373 #endif
374 
375 /* Host operating system. Note that OS codes are defined separately in
376    DEFINES.H, so this macro has no effect until DEFINES.H is included. */
377 
378 #if TARGET==DOS
379  #define OS                   OS_DOS
380 #elif TARGET==OS2
381  #define OS                   OS_OS2
382 #elif TARGET==UNIX
383  #define OS                  OS_UNIX
384 #elif TARGET==WIN32
385  #define OS                 OS_WIN32
386 #endif
387 
388 /* Fixed-bit quantities. Atomic integer types comprising no less than the
389    designated number of bits */
390 
391 #define UINT32         unsigned long
392 #define INT32          unsigned long
393 
394 /* Case sensitivity (under OS/2, this actually depends on the IFS used!) */
395 
396 #if TARGET!=UNIX
397  #define CASE_INSENSITIVE
398 #endif
399 
400 /* Maximum size of path/path component */
401 
402 #if TARGET==OS2||defined(__TILED__)
403  #define CCHMAXPATH              260
404  #define CCHMAXPATHCOMP          256
405 #else
406  #define CCHMAXPATH              512
407  #define CCHMAXPATHCOMP   CCHMAXPATH
408 #endif
409 #define MAXWILDAST               128    /* Maximum # of asterisks in wildcards */
410 
411 /* Our own archive filename storage */
412 
413 #ifdef FILENAME_MAX
414  #undef FILENAME_MAX                    /* Already defined in some compilers */
415 #endif
416 #if TARGET==DOS
417  #define FILENAME_MAX            500
418 #else
419  #define FILENAME_MAX            512
420 #endif
421 
422 /* Wildcard equates */
423 
424 #define WC_RESERVE                10    /* Number of bytes to reserve for w/c */
425 
426 /* Length of screen-wide strings */
427 
428 #define INPUT_LENGTH              80    /* Used in various queries */
429 #define TXTD_LENGTH               78    /* Used when displaying found text */
430 
431 /* Length of command lines */
432 
433 #if TARGET==DOS
434  #define CMDLINE_LENGTH          160
435 #elif TARGET==OS2
436  #define CMDLINE_LENGTH          264
437 #else
438  #define CMDLINE_LENGTH          512    /* ASR fix: applies to Unices too!
439                                            15/01/2003 -- Win32 preparations */
440 #endif
441 
442 /* Number of command-line parameters. It must NOT be too high since some arrays
443    are based on its value */
444 
445 #if TARGET==DOS
446  #define PARAMS_MAX               64    /* parameters+spaces: 64*2=128 */
447  #define SFLIST_MAX               64    /* ARJSFX filelist array limit */
448 #elif TARGET==OS2
449  #define PARAMS_MAX              131    /* ~262 */
450  #define SFLIST_MAX              131
451 #else
452  #define PARAMS_MAX             1024    /* May be less on some platforms */
453  #define SFLIST_MAX             1024
454 #endif
455 
456 /* FAR memory block size limit */
457 
458 #ifdef TILED
459  #if COMPILER==BCC
460   #define FAR_BLK_MAX           65535
461  #elif COMPILER==MSC
462   #define FAR_BLK_MAX           65512
463  #else
464   #define FAR_BLK_MAX           65535
465  #endif
466  #define FLIST_ALLOC_MAX  FAR_BLK_MAX
467 #elif TARGET==OS2
468  #define FAR_BLK_MAX        469762048   /* Unless it's Aurora */
469  #define FLIST_ALLOC_MAX        65535
470 #else
471  #define FAR_BLK_MAX        524288000   /* ASR fix 27/10/2002: larger
472                                            values overflow the 2G limit in
473                                            FILELIST.C, leading to
474                                            ARJSFXV/Linux failure */
475  #define FLIST_ALLOC_MAX        65535
476 #endif
477 
478 /* CFA block increments. It will be wise to keep them proportional to the
479    page size under OS/2, and memory-conserving under DOS. As a sidenote, this
480    significantly reduces the memory requirements for ARJ under DOS. */
481 
482 #if TARGET==OS2
483  #define CFA_BLOCK_SIZE        16384
484 #elif defined(TILED)
485  #define CFA_BLOCK_SIZE         4096
486 #else
487  #define CFA_BLOCK_SIZE        16384    /* Presume i386 paged RAM */
488 #endif
489 
490 /* Maximum # of files in the filelist. No longer an environment limit but
491    a marketing logic! */
492 
493 #define FILELIST_INCREMENT       256    /* Increment count for order blocks */
494 /* In original ARJ, there was a "commercial" filelist capacity (EXT LIC). The
495    shareware/ordinary license limit was FLIST_ALLOC_MAX-1. */
496 #define EXT_FILELIST_CAPACITY ((unsigned long)FAR_BLK_MAX*4-5)
497 #define FILELIST_CAPACITY (FLIST_ALLOC_MAX-1)
498 #define FLIST_SPEC_BASE FILELIST_CAPACITY /* Special entries start here */
499 
500 /* Implicit filelist limits */
501 
502 #define FCLIM_DELETION  FILELIST_CAPACITY /* Limit for deletion */
503 #define FCLIM_ARCHIVE   EXT_FILELIST_CAPACITY /* Archive filelist size */
504 #define FCLIM_EXCLUSION FILELIST_CAPACITY /* Limit for exclusion */
505 #define FCLIM_EA        FILELIST_CAPACITY /* Limit for EA [in/ex]clusion */
506 
507 /* Console settings */
508 
509 #ifdef CR
510  #undef CR
511 #endif
512 #define CR                      0x0D    /* CR */
513 
514 #ifdef LF
515  #undef LF
516 #endif
517 #define LF                      0x0A    /* LF */
518 
519 #ifdef BEL
520  #undef BEL
521 #endif
522 #define BEL                     0x07    /* Bell */
523 
524 #ifdef TAB
525  #undef TAB
526 #endif
527 #define TAB                     0x09    /* Tab */
528 #define TAB_POS                    8    /* Tab stops spacing */
529 
530 #define CON_LBOUND                32    /* Lowest displayable character */
531 #define CON_UBOUND               126    /* Highest displayable character */
532 
533 #if TARGET==UNIX||COMPILER==ICC||COMPILER==HIGHC||TARGET==OS2&&defined(LIBC)
534  #define STDOUT_SETBUF_FIX              /* XPG.4 libraries (namely, IBM LIBC
535                                            and GLIBC) do excessive stdout
536                                            buffering */
537 #endif
538 
539 #if TARGET==UNIX||TARGET==OS2
540  #define DIRECT_TO_ANSI                 /* Means to reimplement screen commands
541                                            via ANSI */
542 #endif
543 
544 /* UNIX and DOS-style path separators */
545 
546 #if TARGET==UNIX
547  #define PATH_SEPARATORS         "/"
548 #else
549  #define PATH_SEPARATORS      "\\:/"    /* Path separators allowed by target
550                                            OS */
551 #endif
552 #if TARGET==UNIX
553  #define PATHSEP_DEFAULT          '/'
554  #define PATHSEP_DEFSTR           "/"
555 #else
556  #define PATHSEP_DEFAULT         '\\'
557  #define PATHSEP_DEFSTR          "\\"
558 #endif
559 
560 /* File buffering equates (defining NO_CACHING will disable buffering) */
561 
562 #define CACHE_SIZE              4096    /* Allocate this amount for buffer */
563 #define CACHE_SIZE_SFXJR        8192    /* ARJSFXJR incoming data cache size */
564 #define PROC_BLOCK_SIZE        27648    /* Size of sequential processing block */
565 #if TARGET==DOS
566  #define VBUF_ADD               4096    /* Old archive stream */
567  #define VBUF_EXTRACT           8192    /* Input archive stream */
568  #define TBUF_ARJ               4096    /* Output archive stream */
569  #if COMPILER==BCC
570   #define VBUF_SFX              4096
571  #else
572   #define VBUF_SFX              2048
573  #endif
574 #elif TARGET==OS2||TARGET==WIN32
575  /* Microsoft C constraints (fragmented heap, and so on...) */
576  #ifdef TILED
577   #define VBUF_ADD              1024
578   #define VBUF_EXTRACT          1024
579   #define TBUF_ARJ              1024
580   #define VBUF_SFX              1024
581  #else
582   #define VBUF_ADD              8192
583   #define VBUF_EXTRACT         16384
584   #define TBUF_ARJ              8192
585   #define VBUF_SFX              8192
586  #endif
587 #elif TARGET==UNIX
588  #define VBUF_ADD               8192
589  #define VBUF_EXTRACT           8192
590  #define VBUF_ARJ               8192
591  #define TBUF_ARJ               8192
592  #define VBUF_SFX               8192
593 #else
594  #error *** Buffering limits must be defined for the target platform!
595 #endif
596 #define TBUF_MINFREE          42000U    /* If less memory left, tbuf>>=1 */
597 #define VBUF_MINFREE          40000U    /* If less memory left, vbuf>>=1 */
598 
599 /*
600  * Error handling capabilities:
601  *
602  *   NO_TERM_HDL        disables termination handler
603  *   NO_FATAL_ERROR_HDL disables fatal error handler
604  *
605  */
606 
607 #if TARGET==DOS
608  #define NO_TERM_HDL                    /* Disable termination handler */
609 #endif
610 #if TARGET==WIN32
611  #define HAVE_BREAK_HANDLER
612 #endif
613 
614 /* File attribute mapping */
615 
616 /* DOS-way */
617 #define FATTR_HIDDEN          0x0002
618 #define FATTR_SYSTEM          0x0004
619 #define FATTR_RDONLY          0x0001
620 #define FATTR_ARCH            0x0020
621 #define FATTR_NOARCH          0x0000
622 #define FATTR_DIREC           0x0010
623 #define FATTR_LABEL           0x0008
624 /* UNIX-way */
625 #define FATTR_IROTH           0x0004
626 #define FATTR_IWOTH           0x0002
627 #define FATTR_IXOTH           0x0001
628 #define FATTR_IRGRP (FATTR_IROTH<<3)
629 #define FATTR_IWGRP (FATTR_IWOTH<<3)
630 #define FATTR_IXGRP (FATTR_IXOTH<<3)
631 #define FATTR_IRUSR (FATTR_IRGRP<<3)
632 #define FATTR_IWUSR (FATTR_IWGRP<<3)
633 #define FATTR_IXUSR (FATTR_IXGRP<<3)
634 #define FATTR_SVTX            0x0200    /* Sticky bit */
635 #define FATTR_SGID            0x0400    /* Set GID on exec */
636 #define FATTR_SUID            0x0800    /* Set UID on exec */
637 #define FATTR_UFMASK          0x0FFF    /* UID/GID/VTX + rwxrwxrwx */
638 #define ufattr(a) ((a)&FATTR_UFMASK)
639 /* Internal mapping for wild_list(), etc. */
640 #define FATTR_DT_ANY          0x0000    /* Default */
641 #define FATTR_DT_REG          0x1000    /* Regular files */
642 #define FATTR_DT_DIR          0x2000    /* Directories */
643 #define FATTR_DT_UXSPECIAL    0x4000    /* Links, pipes, etc. */
644 #define uftype(a)  ((a)&~FATTR_UFMASK)
645 
646 /* Certain capabilities of non-UNIX operating systems aren't supported at all
647    or are heavily modified */
648 
649 #if TARGET==UNIX
650  #define MAP_UNIX_ATTRS                 /* Convert to DOS representation */
651 #endif
652 
653 #if TARGET!=UNIX
654  #define STD_ATTRS              0x27    /* Borland compatibility mask */
655  /* The following is for fileinfo searches */
656  #define STD_FI_ATTRS (FATTR_DIREC|FATTR_HIDDEN|FATTR_SYSTEM|FATTR_RDONLY)
657  #define STD_DIR_ATTR    FATTR_DIREC
658  #define STD_FATTR_NOARCH FATTR_NOARCH
659 #else
660  #define STD_FI_ATTRS (FATTR_DT_REG|FATTR_DT_DIR|FATTR_DT_UXSPECIAL)
661  #define STD_DIR_ATTR   FATTR_DT_DIR
662  #define STD_FATTR_NOARCH       0644
663 #endif
664 
665 /* Priority classes */
666 
667 #if TARGET==OS2||TARGET==WIN32
668  #define PRIORITY_CLASSES               4       /* 1...4 */
669 #elif TARGET==UNIX
670  #define PRIORITY_CLASSES              41       /* -20...20 -> 1...41 */
671 #else
672  #define PRIORITY_CLASSES             100       /* For compatibility */
673 #endif
674 
675 /* OS-specific options */
676 
677 #if TARGET==DOS||TARGET==OS2||TARGET==WIN32
678  #if TARGET==DOS
679   #define EXE_EXTENSION            ".EXE"
680   #define MOD_EXTENSION            ".COM"
681  #else
682   #define EXE_EXTENSION            ".exe"
683   #define MOD_EXTENSION            ".dll"
684  #endif
685 #else
686  #define EXE_EXTENSION                 ""
687  #define NULL_EXE_EXTENSION             /* For ARJ_USER to construct SFX names */
688  #define MOD_EXTENSION              ".so"
689 #endif
690 
691 /* OS-dependent types */
692 
693 typedef unsigned short ATTRIB;          /* Attributes in internal structures */
694 
695 /* File count type */
696 
697 #define FILE_COUNT     unsigned long
698 
699 
700 /* Hard link search structure in ffblks and properties */
701 
702 #if TARGET==UNIX
703 struct l_search
704 {
705  dev_t dev;
706  ino_t inode;
707  nlink_t refcount;
708  FILE_COUNT ref;
709 };
710 #endif
711 
712 /* lfn_findfirst/findnext customized structure */
713 
714 struct new_ffblk
715 {
716  /* To stay compatible with findfirst/findnext functions that rely on DOS
717     block format: */
718  #if TARGET==DOS
719   char ff_reserved[21];
720  #endif
721  #if TARGET!=UNIX
722   char ff_attrib;
723  #else
724   int ff_attrib;
725   int ff_ftype;                         /* Wild UNIX representation - for
726                                            circular symlink treatment */
727  #endif
728  unsigned long ff_ftime;
729  unsigned long ff_fsize;
730  char ff_name[CCHMAXPATH];
731  #if TARGET==DOS
732   short ff_handle;
733  #elif TARGET==OS2
734   HDIR ff_handle;
735  #elif TARGET==WIN32
736   HANDLE ff_handle;
737  #elif TARGET==UNIX
738   DIR *ff_handle;
739   char dir[CCHMAXPATH];                 /* dirent doesn't hold it */
740   char wildcard[CCHMAXPATH];            /* dirent doesn't hold it */
741   int attrs;                            /* dirent doesn't hold it */
742   struct l_search l_search;
743  #endif
744  unsigned long ff_atime;
745  unsigned long ff_ctime;
746 };
747 
748 /* File information structure (used in file_find and so on) */
749 
750 struct file_properties
751 {
752  unsigned long fsize;
753  unsigned long ftime;
754  unsigned long atime;
755  unsigned long ctime;
756  ATTRIB attrib;
757  char type;                             /* One of ARJT_* */
758  char isarchive;
759  /* For hardlink detection */
760  #if TARGET==UNIX
761   struct l_search l_search;
762   char islink;
763  #endif
764 };
765 
766 /* Priority structure */
767 
768 struct priority
769 {
770  int class;
771  int delta;
772 };
773 
774 /* After defining all OS-dependent types, we may include additional files */
775 
776 #include "filelist.h"                   /* For flist_root structure */
777 
778 /* Exported from ENVIRON.C */
779 
780 extern int friendly_systems[];
781 extern char dev_null[];
782 extern char dev_con[];
783 extern char cur_dir_spec[];
784 extern char up_dir_spec[];
785 extern char pathsep_str[];
786 extern char all_wildcard[];
787 extern char root_wildcard[];
788 
789 /*
790  * Macro section
791  */
792 
793 /* A substitution of kbhit() */
794 
795 #if COMPILER==BCC||COMPILER==MSC||COMPILER==MSVC
796  #define flush_kbd() kbhit()
797 #else
798  #define flush_kbd() fetch_keystrokes()
799 #endif
800 
801 /* OS-dependent strcmp() used for comparing filenames */
802 
803 #ifdef HAVE_STRCASECMP
804  #define stricmp strcasecmp
805 #endif
806 
807 #ifdef CASE_INSENSITIVE
808  #define strcmp_os(s1, s2) stricmp(s1, s2)
809  #define strncmp_os(s1, s2, l) strnicmp(s1, s2, l)
810 #else
811  #define strcmp_os(s1, s2) strcmp(s1, s2)
812  #define strncmp_os(s1, s2, l) strncmp(s1, s2, l)
813 #endif
814 
815 /* "Year 2038" workaround. */
816 
817 #if (defined(LIBC)&&TARGET==OS2)||TARGET==WIN32
818  /* Certain LIBC runtimes fail to do localtime() properly when the time
819     argument exceeds 0x80000000 (a "year 2038" problem). So there is a
820     workaround routine, arj_localtime(), to help with this. */
821  #define USE_TZSET                      /* Req'd at least by LIBC on OS/2 */
822  #define LOCALTIME_WORKAROUND           /* Substitute our routine */
823  struct tm *arj_localtime(const time_t *tt);
824 #else
825  /* No workaround required */
826  #define arj_localtime localtime
827 #endif
828 
829 /* fchmod() to make SFX'es executable and other archives non-executable */
830 
831 #if TARGET==UNIX
832  int file_acc(FILE *stream);
833  void make_executable(FILE *stream);
834  #define make_nonexecutable(stream) fchmod(fileno(stream), file_acc(stream)&~0111)
835 #else
836  #define make_executable(stream)
837  #define make_nonexecutable(stream)
838 #endif
839 
840 /* Block optimizers in insane compilers. __LINE__ is for the compiler to be unable
841    to optimize the function arguments if called more than once. */
842 
843 #if COMPILER==HIGHC||COMPILER==ICC
844  #define stop_optimizer() nullsub(__LINE__)
845 #else                                   /* Others are considered sane */
846  #define stop_optimizer()
847 #endif
848 
849 /*
850  * Exported function prototypes - see ENVIRON.C for details
851  */
852 
853 #if TARGET==UNIX
854 #define SKIP_GET_EXE_NAME
855 void get_exe_name(char *dest, char *arg);
856 #else
857 void get_exe_name(char *dest);
858 #endif
859 #if TARGET==OS2&&SFX_LEVEL>=ARJSFX
860  char *malloc_env_str(char *t);
861  #define free_env_str(str) free(str)
862  int system_cmd(char *cmd);
863 #else
864  #define malloc_env_str(t) getenv(t)
865  #define free_env_str(str)
866  #define system_cmd(cmd) system(cmd)
867 #endif
868 
869 #if SFX_LEVEL!=ARJSFXJR
870 
871 int verify_heap();
872 int verify_far_heap();
873 #if SFX_LEVEL>=ARJSFXV&&COMPILER!=BCC
874 long farcoreleft();
875 #endif
876 #if COMPILER!=BCC
877  #ifndef SUNOS
878   int getdisk();
879   int setdisk(int drive);
880  #endif
881  void arj_gettime(struct time *ts);
882  void arj_getdate(struct date *ds);
883 #else
884  #define arj_gettime(x) gettime(x)
885  #define arj_getdate(x) getdate(x)
886 #endif
887 #if TARGET==OS2&&defined(TILED)
888  void FAR *farcalloc_based(unsigned long num, unsigned long size);
889  void farfree_based(void FAR *ptr);
890 #else
891  #define farcalloc_based farcalloc
892  #define farfree_based farfree
893 #endif
894 void set_priority(struct priority *priority);
895 int test_for_winnt();
896 int file_chmod(char *name, int action, int attrs);
897 int lfn_findfirst(char *path, struct new_ffblk *new_ffblk, int attrib);
898 int lfn_findnext(struct new_ffblk *new_ffblk);
899 void lfn_findclose(struct new_ffblk *new_ffblk);
900 void toupper_loc(unsigned char *ptr, int length);
901 time_t sum_time(time_t t1, time_t t2);
902 time_t sub_time(time_t t1, time_t t2);
903 void case_path(char *s);
904 int find_dupl_drivespecs(char **argtable, int args);
905 int file_test_access(char *name);
906 int detect_lfns();
907 int detect_eas();
908 void fix_ansi_name(char *name);
909 void nullsub(int arg, ...);
910 /* IN ARJ32, it fixes filename to comply with OEM/ANSI codepage issues */
911 #define fix_ansi_name(name)
912 void arj_delay(unsigned int seconds);
913 void mem_stats();
914 int file_exists(char *name);
915 FILE *file_open(char *name, char *mode);
916 void default_case_path(char *dest, char *src);
917 int uni_getch();
918 unsigned long get_ticks();
919 unsigned long file_getfree(char *name);
920 int file_find(char *name, struct file_properties *properties);
921 #if SFX_LEVEL>=ARJ||defined(REARJ)
922  long file_getfsize(char *name);
923 #endif
924 unsigned long file_getftime(char *name);
925 int file_getlabel(char *label, char drive, ATTRIB *attrib, unsigned long *ftime);
926 int read_line(char *buf, int size);
927 void get_mode_str(char *str, unsigned int mode);
928 int exec_pgm(char *cmdline);
929 #if TARGET==OS2&&SFX_LEVEL>=ARJSFX
930  char *malloc_env_str(char *t);
931  #define free_env_str(str) free(str)
932  int system_cmd(char *cmd);
933 #else
934  #define malloc_env_str(t) getenv(t)
935  #define free_env_str(str)
936  #define system_cmd(cmd) system(cmd)
937 #endif
938 int read_line_noecho(char *buf, int size);
939 unsigned int get_bytes_per_cluster(char *name);
940 void get_canonical_longname(char *cname, char *name);
941 void get_canonical_shortname(char *cname, char *name);
942 void install_smart_handler();
943 int is_file(FILE *stream);
944 int file_is_removable(char *name);
945 int is_tty(FILE *stream);
946 int file_mkdir(char *name);
947 int match_wildcard(char *name, char *wcard);
948 int file_rmdir(char *name);
949 int file_unlink(char *name);
950 int file_rename(char *oldname, char *newname);
951 int dos_clear_arch_attr(char *name);
952 int reset_drive(char *name);
953 int fetch_keystrokes();
954 int dos_chmod(char *name, int attrib);
955 int file_chsize(FILE *stream, unsigned long size);
956 int file_setftime_on_stream(FILE *stream, unsigned long ftime);
957 int file_setatime(char *name, unsigned long ftime);
958 int file_setctime(char *name, unsigned long ftime);
959 int file_setftime(char *name, unsigned long ftime);
960 int file_setlabel(char *label, char drive, ATTRIB attrib, unsigned long ftime);
961 int file_settype(FILE *stream, int istext);
962 void set_file_apis(int is_ansi);
963 #if SFX_LEVEL>=ARJSFXV
964  int create_subdir_tree(char *path, int qmode, int datatype);
965 #else
966  int create_subdir_tree(char *path, int datatype);
967 #endif
968 int is_filename_valid(char *name);
969 int is_directory(char *name);
970 char *malloc_subdir_wc(char *name);
971 int file_copy(char *dest, char *src, int chk);
972 #ifndef REARJ
973  int wild_list(struct flist_root *root, struct flist_root *search_flist, char *name, int expand_wildcards, int recurse_subdirs, int file_type, FILE_COUNT *count);
974 #else
975  int wild_list(struct flist_root *root, char *name, int file_type, int expand_wildcards, int recurse_subdirs, FILE_COUNT *count);
976 #endif
977 
978 #if SFX_LEVEL>=ARJSFX&&SFX_LEVEL<=ARJSFXV
979  void file_getcwd(char *buf, int len);
980  void file_chdir(char *dir);
981 #endif
982 
983 #ifdef REARJ
984  char *file_getcwd(char *buf);
985  int file_chdir(char *dir);
986  char get_sw_char();
987 #endif
988 
989 #endif /* !ARJSFXJR */
990 
991 int file_setftime_on_hf(int hf, unsigned long ftime);
992 
993 #endif
994