[3365] | 1 | /* System dependent definitions for GNU tar.
|
---|
| 2 | Copyright (C) 1994 Free Software Foundation, Inc.
|
---|
| 3 |
|
---|
| 4 | This program is free software; you can redistribute it and/or modify
|
---|
| 5 | it under the terms of the GNU General Public License as published by
|
---|
| 6 | the Free Software Foundation; either version 2, or (at your option)
|
---|
| 7 | any later version.
|
---|
| 8 |
|
---|
| 9 | This program is distributed in the hope that it will be useful,
|
---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 12 | GNU General Public License for more details.
|
---|
| 13 |
|
---|
| 14 | You should have received a copy of the GNU General Public License
|
---|
| 15 | along with this program; if not, write to the Free Software
|
---|
| 16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | /*
|
---|
| 20 | * [TS:Aug/95]
|
---|
| 21 | * Based on code from system.h file in GNU's tar package
|
---|
| 22 | *
|
---|
| 23 | */
|
---|
| 24 |
|
---|
| 25 | #ifndef SYSFUNCS_H
|
---|
| 26 | #define SYSFUNCS_H
|
---|
| 27 |
|
---|
| 28 | #include <sys/stat.h>
|
---|
| 29 |
|
---|
| 30 | /* [RPAP - Feb 97: WIN32 Port] */
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | # ifdef __WIN32__
|
---|
[14910] | 33 | # include <win32cfg.h>
|
---|
[3365] | 34 | # else
|
---|
| 35 | # include <config.h>
|
---|
| 36 | # endif
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
| 39 | /* Declare alloca. AIX requires this to be the first thing in the file. */
|
---|
| 40 |
|
---|
| 41 | #ifdef __GNUC__
|
---|
| 42 | #ifndef alloca
|
---|
| 43 | #define alloca __builtin_alloca
|
---|
| 44 | #endif
|
---|
| 45 | #else
|
---|
| 46 | #if HAVE_ALLOCA_H
|
---|
| 47 | #include <alloca.h>
|
---|
| 48 | #else
|
---|
| 49 | #ifdef _AIX
|
---|
| 50 | #pragma alloca
|
---|
| 51 | #else
|
---|
| 52 | #ifndef alloca
|
---|
| 53 | char *alloca ();
|
---|
| 54 | #endif
|
---|
| 55 | #endif
|
---|
| 56 | #endif
|
---|
| 57 | #endif
|
---|
| 58 |
|
---|
| 59 | #include <sys/types.h>
|
---|
| 60 |
|
---|
| 61 | /* ------------------------------------------------- */
|
---|
| 62 | /* [TS:Aug/95]
|
---|
| 63 | * Some extra include files that mg needs
|
---|
| 64 | */
|
---|
| 65 | #include <stdlib.h>
|
---|
| 66 |
|
---|
[29055] | 67 | #if defined(GSDL_USE_IOS_H) || defined __unix__ || defined __APPLE__ || defined __MINGW32__
|
---|
[29051] | 68 | # include <math.h>
|
---|
| 69 | #else
|
---|
[29054] | 70 | /* Newer Visual Studio compilers (e.g., VS12) prefer the math's header file to be included this way */
|
---|
[29051] | 71 | # include <cmath>
|
---|
| 72 | #endif
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 |
|
---|
[3365] | 76 | #ifndef log2
|
---|
| 77 | # ifndef M_LN2
|
---|
| 78 | # define M_LN2 0.69314718055994530942
|
---|
| 79 | # endif
|
---|
| 80 | # define log2(x) (log(x)/M_LN2)
|
---|
| 81 | #endif
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | #ifndef HAVE_SETBUFFER
|
---|
| 85 | #ifdef __CYGWIN__
|
---|
| 86 | /* Cygwin has setbuffer in stdio.h, but can't link against it!! */
|
---|
| 87 | #include <stdio.h>
|
---|
| 88 | #endif
|
---|
| 89 | # define setbuffer(f, b, s) setvbuf(f, b, _IOFBF, s)
|
---|
| 90 | #endif
|
---|
| 91 |
|
---|
| 92 | /* [RPAP - Feb 97: WIN32 Port] */
|
---|
| 93 | #if defined(__MSDOS__) && !defined(__WIN32__)
|
---|
| 94 | # define SHORT_SUFFIX 1
|
---|
| 95 | #endif
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | #include <assert.h>
|
---|
| 100 |
|
---|
| 101 | /* ------------------------------------------------- */
|
---|
| 102 |
|
---|
| 103 | /* Declare a generic pointer type. */
|
---|
| 104 | #if __STDC__ || defined(__TURBOC__)
|
---|
| 105 | #define voidstar void *
|
---|
| 106 | #else
|
---|
| 107 | #define voidstar char *
|
---|
| 108 | #endif
|
---|
| 109 |
|
---|
| 110 | /* Declare ISASCII. */
|
---|
| 111 |
|
---|
| 112 | #include <ctype.h>
|
---|
| 113 |
|
---|
| 114 | #if STDC_HEADERS
|
---|
| 115 | #define ISASCII(Char) 1
|
---|
| 116 | #else
|
---|
| 117 | #ifdef isascii
|
---|
| 118 | #define ISASCII(Char) isascii (Char)
|
---|
| 119 | #else
|
---|
| 120 | #if HAVE_ISASCII
|
---|
| 121 | #define ISASCII(Char) isascii (Char)
|
---|
| 122 | #else
|
---|
| 123 | #define ISASCII(Char) 1
|
---|
| 124 | #endif
|
---|
| 125 | #endif
|
---|
| 126 | #endif
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | /* ------------------------------------------------- */
|
---|
| 130 | /* [TS:Aug/95]
|
---|
| 131 | * The following is copied from GNU Autoconf.Info (1.1)
|
---|
| 132 | * It sets up the approriate string and memory functions.
|
---|
| 133 | */
|
---|
| 134 |
|
---|
| 135 | #if STDC_HEADERS || HAVE_STRING_H
|
---|
| 136 | #include <string.h>
|
---|
| 137 | /* An ANSI string.h and pre-ANSI memory.h might conflict */
|
---|
| 138 | #if !STDC_HEADERS && HAVE_MEMORY_H
|
---|
| 139 | #include <memory.h>
|
---|
| 140 | #endif /* not STDC_HEADERS and HAVE_MEMORY_H */
|
---|
| 141 | #ifndef index
|
---|
| 142 | /*#define index strchr
|
---|
| 143 | *
|
---|
| 144 | * this is stuffing up our code so its commented out */
|
---|
| 145 | #endif
|
---|
| 146 | #ifndef rindex
|
---|
| 147 | #define rindex strrchr
|
---|
| 148 | #endif
|
---|
| 149 |
|
---|
| 150 | #ifdef __cplusplus /* compiling for C++ */
|
---|
| 151 | #include <stdlib.h>
|
---|
| 152 | #ifndef __bcopy
|
---|
| 153 | inline void *bcopy(void *s, void *d, int n)
|
---|
| 154 | { return memcpy(d, s, n);
|
---|
| 155 | }
|
---|
| 156 | #define __bcopy 1
|
---|
| 157 | #endif
|
---|
| 158 | #ifndef __bcmp
|
---|
| 159 | inline int bcmp(void *s1, void *s2, int n)
|
---|
| 160 | { return memcmp(s1, s2, n);
|
---|
| 161 | }
|
---|
| 162 | #define __bcmp 1
|
---|
| 163 | #endif
|
---|
| 164 | #ifndef __bzero
|
---|
| 165 | inline void bzero(void *m, int n)
|
---|
| 166 | { memset(m, 0, n);
|
---|
| 167 | }
|
---|
| 168 | #define __bzero 1
|
---|
| 169 | #endif
|
---|
| 170 | #else /* compiling for C */
|
---|
| 171 | #ifndef bcopy
|
---|
| 172 | #define bcopy(s, d, n) memcpy((d), (s), (n))
|
---|
| 173 | #endif
|
---|
| 174 | #ifndef bcmp
|
---|
| 175 | #define bcmp(s1, s2, n) memcmp((s1), (s2), (n))
|
---|
| 176 | #endif
|
---|
| 177 | #ifndef bzero
|
---|
| 178 | #define bzero(s, n) memset((s), 0, (n))
|
---|
| 179 | #endif
|
---|
| 180 | #endif
|
---|
| 181 |
|
---|
| 182 | #else /* not STDC_HEADERS and not HAVE_STRING_H */
|
---|
| 183 | #include <strings.h>
|
---|
| 184 | /* memory.h and strings.h conflict on some systems */
|
---|
| 185 | #endif
|
---|
| 186 | /* ------------------------------------------------- */
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | /* Declare errno. */
|
---|
| 190 |
|
---|
| 191 | #include <errno.h>
|
---|
| 192 | #ifndef errno
|
---|
| 193 | extern int errno;
|
---|
| 194 | #endif
|
---|
| 195 |
|
---|
| 196 | /* Declare open parameters. */
|
---|
| 197 |
|
---|
| 198 | #ifdef HAVE_FCNTL_H
|
---|
| 199 | #include <fcntl.h>
|
---|
| 200 | #else
|
---|
| 201 | #include <sys/file.h>
|
---|
| 202 | #endif
|
---|
| 203 |
|
---|
| 204 | #ifndef O_BINARY
|
---|
| 205 | #define O_BINARY 0
|
---|
| 206 | #endif
|
---|
| 207 | #ifndef O_CREAT
|
---|
| 208 | #define O_CREAT 0
|
---|
| 209 | #endif
|
---|
| 210 | #ifndef O_NDELAY
|
---|
| 211 | #define O_NDELAY 0
|
---|
| 212 | #endif
|
---|
| 213 | #ifndef O_RDONLY
|
---|
| 214 | #define O_RDONLY 0
|
---|
| 215 | #endif
|
---|
| 216 | #ifndef O_RDWR
|
---|
| 217 | #define O_RDWR 2
|
---|
| 218 | #endif
|
---|
| 219 |
|
---|
| 220 | /* Declare file status routines and bits. */
|
---|
| 221 |
|
---|
| 222 | #ifdef STAT_MACROS_BROKEN
|
---|
| 223 | #undef S_ISBLK
|
---|
| 224 | #undef S_ISCHR
|
---|
| 225 | #undef S_ISDIR
|
---|
| 226 | #undef S_ISFIFO
|
---|
| 227 | #undef S_ISLNK
|
---|
| 228 | #undef S_ISMPB
|
---|
| 229 | #undef S_ISMPC
|
---|
| 230 | #undef S_ISNWK
|
---|
| 231 | #undef S_ISREG
|
---|
| 232 | #undef S_ISSOCK
|
---|
| 233 | #endif
|
---|
| 234 |
|
---|
| 235 | /* On MSDOS, there are missing things from <sys/stat.h>. */
|
---|
| 236 | #ifdef __MSDOS__
|
---|
| 237 | #define S_ISUID 0
|
---|
| 238 | #define S_ISGID 0
|
---|
| 239 | #define S_ISVTX 0
|
---|
| 240 | #endif
|
---|
| 241 |
|
---|
| 242 | #ifndef S_ISREG /* POSIX.1 stat stuff missing */
|
---|
| 243 | #define mode_t unsigned short
|
---|
| 244 | #endif
|
---|
| 245 | #if !defined(S_ISBLK) && defined(S_IFBLK)
|
---|
| 246 | #define S_ISBLK(Mode) (((Mode) & S_IFMT) == S_IFBLK)
|
---|
| 247 | #endif
|
---|
| 248 | #if !defined(S_ISCHR) && defined(S_IFCHR)
|
---|
| 249 | #define S_ISCHR(Mode) (((Mode) & S_IFMT) == S_IFCHR)
|
---|
| 250 | #endif
|
---|
| 251 | #if !defined(S_ISDIR) && defined(S_IFDIR)
|
---|
| 252 | #define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
|
---|
| 253 | #endif
|
---|
| 254 | #if !defined(S_ISREG) && defined(S_IFREG)
|
---|
| 255 | #define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
|
---|
| 256 | #endif
|
---|
| 257 | #if !defined(S_ISFIFO) && defined(S_IFIFO)
|
---|
| 258 | #define S_ISFIFO(Mode) (((Mode) & S_IFMT) == S_IFIFO)
|
---|
| 259 | #endif
|
---|
| 260 | #if !defined(S_ISLNK) && defined(S_IFLNK)
|
---|
| 261 | #define S_ISLNK(Mode) (((Mode) & S_IFMT) == S_IFLNK)
|
---|
| 262 | #endif
|
---|
| 263 | #if !defined(S_ISSOCK) && defined(S_IFSOCK)
|
---|
| 264 | #define S_ISSOCK(Mode) (((Mode) & S_IFMT) == S_IFSOCK)
|
---|
| 265 | #endif
|
---|
| 266 | #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
|
---|
| 267 | #define S_ISMPB(Mode) (((Mode) & S_IFMT) == S_IFMPB)
|
---|
| 268 | #define S_ISMPC(Mode) (((Mode) & S_IFMT) == S_IFMPC)
|
---|
| 269 | #endif
|
---|
| 270 | #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
|
---|
| 271 | #define S_ISNWK(Mode) (((Mode) & S_IFMT) == S_IFNWK)
|
---|
| 272 | #endif
|
---|
| 273 |
|
---|
| 274 | #if !defined(S_ISCTG) && defined(S_IFCTG) /* contiguous file */
|
---|
| 275 | #define S_ISCTG(Mode) (((Mode) & S_IFMT) == S_IFCTG)
|
---|
| 276 | #endif
|
---|
| 277 | #if !defined(S_ISVTX)
|
---|
| 278 | #define S_ISVTX 0001000
|
---|
| 279 | #endif
|
---|
| 280 |
|
---|
| 281 | /* [RPAP - Feb 97: WIN32 Port] */
|
---|
| 282 | #if !defined(_POSIX_SOURCE) && !defined(__WIN32__)
|
---|
| 283 | #include <sys/param.h>
|
---|
| 284 | #endif
|
---|
| 285 |
|
---|
| 286 | /* Include <unistd.h> before any preprocessor test of _POSIX_VERSION. */
|
---|
| 287 | #ifdef HAVE_UNISTD_H
|
---|
| 288 | #include <unistd.h>
|
---|
| 289 | #endif
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | /* Declare standard functions. */
|
---|
| 293 |
|
---|
| 294 | #ifdef STDC_HEADERS
|
---|
| 295 | #include <stdlib.h>
|
---|
| 296 | #else
|
---|
| 297 | voidstar malloc ();
|
---|
| 298 | voidstar realloc ();
|
---|
| 299 | char *getenv ();
|
---|
| 300 | #endif
|
---|
| 301 |
|
---|
| 302 | #include <stdio.h>
|
---|
| 303 |
|
---|
| 304 | #ifndef _POSIX_VERSION
|
---|
| 305 | #ifdef __MSDOS__
|
---|
| 306 | #include <io.h>
|
---|
| 307 | #else
|
---|
| 308 | off_t lseek ();
|
---|
| 309 | #endif
|
---|
| 310 | #endif
|
---|
| 311 |
|
---|
| 312 | #ifndef __WIN32__
|
---|
| 313 | #include <pathmax.h>
|
---|
| 314 | #endif
|
---|
| 315 |
|
---|
| 316 | /* Until getoptold function is declared in getopt.h, we need this here for
|
---|
| 317 | struct option. */
|
---|
| 318 | /*#include <getopt.h>*/
|
---|
| 319 |
|
---|
| 320 | #ifdef WITH_DMALLOC
|
---|
| 321 | #undef HAVE_VALLOC
|
---|
| 322 | #define DMALLOC_FUNC_CHECK
|
---|
| 323 | #include <dmalloc.h>
|
---|
| 324 | #endif
|
---|
| 325 |
|
---|
| 326 | /* Prototypes for external functions. */
|
---|
| 327 |
|
---|
| 328 | #ifndef __P
|
---|
| 329 | #if PROTOTYPES
|
---|
| 330 | #define __P(Args) Args
|
---|
| 331 | #else
|
---|
| 332 | #define __P(Args) ()
|
---|
| 333 | #endif
|
---|
| 334 | #endif
|
---|
| 335 |
|
---|
| 336 | #if HAVE_LOCALE_H
|
---|
| 337 | #include <locale.h>
|
---|
| 338 | #endif
|
---|
| 339 | /*** setlocale is ansi and posix...(jrm21)
|
---|
| 340 | #if !HAVE_SETLOCALE
|
---|
| 341 | #define setlocale(Category, Locale)
|
---|
| 342 | #endif
|
---|
| 343 | ***/
|
---|
| 344 |
|
---|
| 345 | #if ENABLE_NLS
|
---|
| 346 | #include <libintl.h>
|
---|
| 347 | #define _(Text) gettext (Text)
|
---|
| 348 | #else
|
---|
| 349 | #define textdomain(Domain)
|
---|
| 350 | #define _(Text) Text
|
---|
| 351 | #endif
|
---|
| 352 |
|
---|
| 353 | /* Library modules. */
|
---|
| 354 |
|
---|
| 355 | #ifdef HAVE_VPRINTF
|
---|
| 356 | void error __P ((int, int, const char *,...));
|
---|
| 357 | #else
|
---|
| 358 | void error ();
|
---|
| 359 | #endif
|
---|
| 360 |
|
---|
| 361 | #ifndef HAVE_STRSTR
|
---|
| 362 | char *strstr __P ((const char *, const char *));
|
---|
| 363 | #endif
|
---|
| 364 |
|
---|
| 365 | /* [RB/TS:Oct/95] commented out. Used by lib/gmalloc.c - but it defines it anyway ???
|
---|
| 366 | *#ifndef HAVE_VALLOC
|
---|
| 367 | *#define valloc(Size) malloc (Size)
|
---|
| 368 | *#endif
|
---|
| 369 | */
|
---|
| 370 |
|
---|
| 371 | voidstar xmalloc __P ((size_t));
|
---|
| 372 | voidstar xrealloc __P ((voidstar, size_t));
|
---|
| 373 | char *xstrdup __P ((const char *));
|
---|
| 374 |
|
---|
| 375 | /* [TS:Aug/95]
|
---|
| 376 | * These were required by files which referred
|
---|
| 377 | * to these as function pointers.
|
---|
| 378 | * e.g. huffman.c - fread, mgfelics.c - fgetc
|
---|
| 379 | */
|
---|
| 380 | #ifndef HAVE_FREAD_DECL
|
---|
| 381 | extern size_t fread __P ((void *, size_t, size_t, FILE *));
|
---|
| 382 | #endif
|
---|
| 383 | #ifndef HAVE_FGETC_DECL
|
---|
| 384 | extern int fgetc __P ((FILE *));
|
---|
| 385 | #endif
|
---|
| 386 |
|
---|
[25147] | 387 | #include "mglong.h"
|
---|
| 388 |
|
---|
[3365] | 389 | #ifndef u_char
|
---|
[25147] | 390 | # define u_char uint8_t
|
---|
[3365] | 391 | #endif
|
---|
| 392 |
|
---|
| 393 | #endif /* SYSFUNCS_H */
|
---|