1 /* 2 * system.h - system configuration header file 3 * 4 * This file is part of zsh, the Z shell. 5 * 6 * Copyright (c) 1992-1997 Paul Falstad 7 * All rights reserved. 8 * 9 * Permission is hereby granted, without written agreement and without 10 * license or royalty fees, to use, copy, modify, and distribute this 11 * software and to distribute modified versions of this software for any 12 * purpose, provided that the above copyright notice and the following 13 * two paragraphs appear in all copies of this software. 14 * 15 * In no event shall Paul Falstad or the Zsh Development Group be liable 16 * to any party for direct, indirect, special, incidental, or consequential 17 * damages arising out of the use of this software and its documentation, 18 * even if Paul Falstad and the Zsh Development Group have been advised of 19 * the possibility of such damage. 20 * 21 * Paul Falstad and the Zsh Development Group specifically disclaim any 22 * warranties, including, but not limited to, the implied warranties of 23 * merchantability and fitness for a particular purpose. The software 24 * provided hereunder is on an "as is" basis, and Paul Falstad and the 25 * Zsh Development Group have no obligation to provide maintenance, 26 * support, updates, enhancements, or modifications. 27 * 28 */ 29 30 #if 0 31 /* 32 * Setting _XPG_IV here is actually wrong and is not needed 33 * with currently supported versions (5.43C20 and above) 34 */ 35 #ifdef sinix 36 # define _XPG_IV 1 37 #endif 38 #endif 39 40 #if defined(__linux) || defined(__GNU__) || defined(__GLIBC__) || defined(LIBC_MUSL) || defined(__CYGWIN__) 41 /* 42 * Turn on numerous extensions. 43 * This is in order to get the functions for manipulating /dev/ptmx. 44 */ 45 #define _GNU_SOURCE 1 46 #endif 47 #ifdef LIBC_MUSL 48 #define _POSIX_C_SOURCE 200809L 49 #endif 50 51 /* NeXT has half-implemented POSIX support * 52 * which currently fools configure */ 53 #ifdef __NeXT__ 54 # undef HAVE_TERMIOS_H 55 # undef HAVE_SYS_UTSNAME_H 56 #endif 57 58 #ifndef ZSH_NO_XOPEN 59 # ifdef ZSH_CURSES_SOURCE 60 # define _XOPEN_SOURCE_EXTENDED 1 61 # else 62 # ifdef MULTIBYTE_SUPPORT 63 /* 64 * Needed for wcwidth() which is part of XSI. 65 * Various other uses of the interface mean we can't get away with just 66 * _XOPEN_SOURCE. 67 */ 68 # define _XOPEN_SOURCE_EXTENDED 1 69 # endif /* MULTIBYTE_SUPPORT */ 70 # endif /* ZSH_CURSES_SOURCE */ 71 #endif /* ZSH_NO_XOPEN */ 72 73 /* 74 * Solaris by default zeroes all elements of the tm structure in 75 * strptime(). Unfortunately that gives us no way of telling whether 76 * the tm_isdst element has been set from the input pattern. If it 77 * hasn't we want it to be -1 (undetermined) on input to mktime(). So 78 * we stop strptime() zeroing the struct tm and instead set all the 79 * elements ourselves. 80 * 81 * This is likely to be harmless everywhere else. 82 */ 83 #define _STRPTIME_DONTZERO 84 85 #ifdef PROTOTYPES 86 # define _(Args) Args 87 #else 88 # define _(Args) () 89 #endif 90 91 #ifndef HAVE_ALLOCA 92 # define alloca zhalloc 93 #else 94 # ifdef __GNUC__ 95 # define alloca __builtin_alloca 96 # else 97 # if HAVE_ALLOCA_H 98 # include <alloca.h> 99 # else 100 # ifdef _AIX 101 # pragma alloca 102 # else 103 # ifndef alloca 104 char *alloca _((size_t)); 105 # endif 106 # endif 107 # endif 108 # endif 109 #endif 110 111 /* 112 * libc.h in an optional package for Debian Linux is broken (it 113 * defines dup() as a synonym for dup2(), which has a different 114 * number of arguments), so just include it for next. 115 */ 116 #ifdef __NeXT__ 117 # ifdef HAVE_LIBC_H 118 # include <libc.h> 119 # endif 120 #endif 121 122 #ifdef HAVE_SYS_TYPES_H 123 # include <sys/types.h> 124 #endif 125 126 #ifdef HAVE_UNISTD_H 127 # include <unistd.h> 128 #endif 129 130 #ifdef HAVE_STDDEF_H 131 /* 132 * Seen on Solaris 8 with gcc: stddef defines offsetof, which clashes 133 * with system.h's definition of the symbol unless we include this 134 * first. Otherwise, this will be hooked in by wchar.h, too late 135 * for comfort. 136 */ 137 #include <stddef.h> 138 #endif 139 140 #ifdef HAVE_STDINT_H 141 # include <stdint.h> 142 #endif 143 144 #include <stdio.h> 145 #include <ctype.h> 146 #include <sys/stat.h> 147 #include <signal.h> 148 #include <setjmp.h> 149 150 #ifdef HAVE_PWD_H 151 # include <pwd.h> 152 #endif 153 154 #ifdef HAVE_GRP_H 155 # include <grp.h> 156 #endif 157 158 #ifdef HAVE_DIRENT_H 159 # include <dirent.h> 160 #else /* !HAVE_DIRENT_H */ 161 # ifdef HAVE_SYS_NDIR_H 162 # include <sys/ndir.h> 163 # endif 164 # ifdef HAVE_SYS_DIR_H 165 # include <sys/dir.h> 166 # endif 167 # ifdef HAVE_NDIR_H 168 # include <ndir.h> 169 # endif 170 # define dirent direct 171 # undef HAVE_STRUCT_DIRENT_D_INO 172 # undef HAVE_STRUCT_DIRENT_D_STAT 173 # ifdef HAVE_STRUCT_DIRECT_D_INO 174 # define HAVE_STRUCT_DIRENT_D_INO HAVE_STRUCT_DIRECT_D_INO 175 # endif 176 # ifdef HAVE_STRUCT_DIRECT_D_STAT 177 # define HAVE_STRUCT_DIRENT_D_STAT HAVE_STRUCT_DIRECT_D_STAT 178 # endif 179 #endif /* !HAVE_DIRENT_H */ 180 181 #ifdef HAVE_STDLIB_H 182 # ifdef ZSH_MEM 183 /* malloc and calloc are macros in GNU's stdlib.h unless the 184 * the __MALLOC_0_RETURNS_NULL macro is defined */ 185 # define __MALLOC_0_RETURNS_NULL 186 # endif 187 # include <stdlib.h> 188 #endif 189 190 /* 191 * Stuff with variable arguments. We use definitions to make the 192 * same code work with varargs (the original K&R-style, just to 193 * be maximally compatible) and stdarg (which all modern systems 194 * should have). 195 * 196 * Ideally this should somehow be merged with the tricks performed 197 * with "_" in makepro.awk, but I don't understand makepro.awk. 198 * Currently we simply rely on the fact that makepro.awk has been 199 * hacked to leave alone argument lists that already contains VA_ALIST 200 * except for removing the VA_DCL and turning VA_ALIST into VA_ALIST_PROTO. 201 */ 202 #ifdef HAVE_STDARG_H 203 # include <stdarg.h> 204 # define VA_ALIST1(x) x, ... 205 # define VA_ALIST2(x,y) x, y, ... 206 # define VA_ALIST_PROTO1(x) VA_ALIST1(x) 207 # define VA_ALIST_PROTO2(x,y) VA_ALIST2(x,y) 208 # define VA_DCL 209 # define VA_DEF_ARG(x) 210 # define VA_START(ap,x) va_start(ap, x) 211 # define VA_GET_ARG(ap,x,t) 212 #else 213 # if HAVE_VARARGS_H 214 # include <varargs.h> 215 # define VA_ALIST1(x) va_alist 216 # define VA_ALIST2(x,y) va_alist 217 /* 218 * In prototypes, assume K&R form and remove the variable list. 219 * This is about the best we can do without second-guessing the way 220 * varargs works on this system. The _ trick should be able to 221 * do this for us but we've turned it off here. 222 */ 223 # define VA_ALIST_PROTO1(x) 224 # define VA_ALIST_PROTO2(x,y) 225 # define VA_DCL va_dcl 226 # define VA_DEF_ARG(x) x 227 # define VA_START(ap,x) va_start(ap); 228 # define VA_GET_ARG(ap,x,t) (x = va_arg(ap, t)) 229 # else 230 # error "Your system has neither stdarg.h or varargs.h." 231 # endif 232 #endif 233 234 #ifdef HAVE_ERRNO_H 235 # include <errno.h> 236 #endif 237 238 #ifdef TIME_WITH_SYS_TIME 239 # include <sys/time.h> 240 # include <time.h> 241 #else 242 # ifdef HAVE_SYS_TIME_H 243 # include <sys/time.h> 244 # else 245 # include <time.h> 246 # endif 247 #endif 248 249 /* This is needed by some old SCO unices */ 250 #if !defined(HAVE_STRUCT_TIMEZONE) && !defined(ZSH_OOT_MODULE) 251 struct timezone { 252 int tz_minuteswest; 253 int tz_dsttime; 254 }; 255 #endif 256 257 /* Used to provide compatibility with clock_gettime() */ 258 #if !defined(HAVE_STRUCT_TIMESPEC) && !defined(ZSH_OOT_MODULE) 259 struct timespec { 260 time_t tv_sec; 261 long tv_nsec; 262 }; 263 #endif 264 265 /* There's more than one non-standard way to get at this data */ 266 #if !defined(HAVE_STRUCT_DIRENT_D_INO) && defined(HAVE_STRUCT_DIRENT_D_STAT) 267 # define d_ino d_stat.st_ino 268 # define HAVE_STRUCT_DIRENT_D_INO HAVE_STRUCT_DIRENT_D_STAT 269 #endif /* !HAVE_STRUCT_DIRENT_D_INO && HAVE_STRUCT_DIRENT_D_STAT */ 270 271 /* Sco needs the following include for struct utimbuf * 272 * which is strange considering we do not use that * 273 * anywhere in the code */ 274 #ifdef __sco 275 # include <utime.h> 276 #endif 277 278 #ifdef HAVE_SYS_TIMES_H 279 # include <sys/times.h> 280 #endif 281 282 #if STDC_HEADERS || HAVE_STRING_H 283 # include <string.h> 284 /* An ANSI string.h and pre-ANSI memory.h might conflict. */ 285 # if !STDC_HEADERS && HAVE_MEMORY_H 286 # include <memory.h> 287 # endif /* not STDC_HEADERS and HAVE_MEMORY_H */ 288 #else /* not STDC_HEADERS and not HAVE_STRING_H */ 289 # include <strings.h> 290 /* memory.h and strings.h conflict on some systems. */ 291 #endif /* not STDC_HEADERS and not HAVE_STRING_H */ 292 293 #ifdef HAVE_LOCALE_H 294 # include <locale.h> 295 #endif 296 297 #ifdef HAVE_LIMITS_H 298 # include <limits.h> 299 #endif 300 301 #ifdef USE_STACK_ALLOCATION 302 #ifdef HAVE_VARIABLE_LENGTH_ARRAYS 303 # define VARARR(X,Y,Z) X (Y)[Z] 304 #else 305 # define VARARR(X,Y,Z) X *(Y) = (X *) alloca(sizeof(X) * (Z)) 306 #endif 307 #else 308 # define VARARR(X,Y,Z) X *(Y) = (X *) zhalloc(sizeof(X) * (Z)) 309 #endif 310 311 /* we should handle unlimited sizes from pathconf(_PC_PATH_MAX) */ 312 /* but this is too much trouble */ 313 #ifndef PATH_MAX 314 # ifdef MAXPATHLEN 315 # define PATH_MAX MAXPATHLEN 316 # else 317 # ifdef _POSIX_PATH_MAX 318 # define PATH_MAX _POSIX_PATH_MAX 319 # else 320 /* so we will just pick something */ 321 # define PATH_MAX 1024 322 # endif 323 # endif 324 #endif 325 326 /* 327 * The number of file descriptors we'll allocate initially. 328 * We will reallocate later if necessary. 329 */ 330 #define ZSH_INITIAL_OPEN_MAX 64 331 #ifndef OPEN_MAX 332 # ifdef NOFILE 333 # define OPEN_MAX NOFILE 334 # else 335 /* so we will just pick something */ 336 # define OPEN_MAX ZSH_INITIAL_OPEN_MAX 337 # endif 338 #endif 339 #ifndef HAVE_SYSCONF 340 # define zopenmax() ((long) (OPEN_MAX > ZSH_INITIAL_OPEN_MAX ? \ 341 ZSH_INITIAL_OPEN_MAX : OPEN_MAX)) 342 #endif 343 344 #ifdef HAVE_FCNTL_H 345 # include <fcntl.h> 346 #else 347 # include <sys/file.h> 348 #endif 349 350 /* The following will only be defined if <sys/wait.h> is POSIX. * 351 * So we don't have to worry about union wait. But some machines * 352 * (NeXT) include <sys/wait.h> from other include files, so we * 353 * need to undef and then redefine the wait macros if <sys/wait.h> * 354 * is not POSIX. */ 355 356 #ifdef HAVE_SYS_WAIT_H 357 # include <sys/wait.h> 358 #else 359 # undef WIFEXITED 360 # undef WEXITSTATUS 361 # undef WIFSIGNALED 362 # undef WTERMSIG 363 # undef WCOREDUMP 364 # undef WIFSTOPPED 365 # undef WSTOPSIG 366 #endif 367 368 /* missing macros for wait/waitpid/wait3 */ 369 #ifndef WIFEXITED 370 # define WIFEXITED(X) (((X)&0377)==0) 371 #endif 372 #ifndef WEXITSTATUS 373 # define WEXITSTATUS(X) (((X)>>8)&0377) 374 #endif 375 #ifndef WIFSIGNALED 376 # define WIFSIGNALED(X) (((X)&0377)!=0&&((X)&0377)!=0177) 377 #endif 378 #ifndef WTERMSIG 379 # define WTERMSIG(X) ((X)&0177) 380 #endif 381 #ifndef WCOREDUMP 382 # define WCOREDUMP(X) ((X)&0200) 383 #endif 384 #ifndef WIFSTOPPED 385 # define WIFSTOPPED(X) (((X)&0377)==0177) 386 #endif 387 #ifndef WSTOPSIG 388 # define WSTOPSIG(X) (((X)>>8)&0377) 389 #endif 390 391 #ifdef HAVE_SYS_SELECT_H 392 # ifndef TIME_H_SELECT_H_CONFLICTS 393 # include <sys/select.h> 394 # endif 395 #elif defined(SELECT_IN_SYS_SOCKET_H) 396 # include <sys/socket.h> 397 #endif 398 399 #if defined(__APPLE__) && defined(HAVE_SELECT) 400 /* 401 * Prefer select() to poll() on MacOS X since poll() is known 402 * to be problematic in 10.4 403 */ 404 #undef HAVE_POLL 405 #undef HAVE_POLL_H 406 #endif 407 408 #ifdef HAVE_SYS_FILIO_H 409 # include <sys/filio.h> 410 #endif 411 412 #ifdef HAVE_TERMIOS_H 413 # ifdef __sco 414 /* termios.h includes sys/termio.h instead of sys/termios.h; * 415 * hence the declaration for struct termios is missing */ 416 # include <sys/termios.h> 417 # else 418 # include <termios.h> 419 # endif 420 # ifdef _POSIX_VDISABLE 421 # define VDISABLEVAL _POSIX_VDISABLE 422 # else 423 # define VDISABLEVAL 0 424 # endif 425 # define HAS_TIO 1 426 #else /* not TERMIOS */ 427 # ifdef HAVE_TERMIO_H 428 # include <termio.h> 429 # define VDISABLEVAL -1 430 # define HAS_TIO 1 431 # else /* not TERMIOS and TERMIO */ 432 # include <sgtty.h> 433 # endif /* HAVE_TERMIO_H */ 434 #endif /* HAVE_TERMIOS_H */ 435 436 #if defined(GWINSZ_IN_SYS_IOCTL) || defined(IOCTL_IN_SYS_IOCTL) 437 # include <sys/ioctl.h> 438 #endif 439 #ifdef WINSIZE_IN_PTEM 440 # include <sys/stream.h> 441 # include <sys/ptem.h> 442 #endif 443 444 #ifdef HAVE_SYS_PARAM_H 445 # include <sys/param.h> 446 #endif 447 448 #ifdef HAVE_SYS_UTSNAME_H 449 # include <sys/utsname.h> 450 #endif 451 452 #define DEFAULT_WORDCHARS "*?_-.[]~=/&;!#$%^(){}<>" 453 #define DEFAULT_TIMEFMT "%J %U user %S system %P cpu %*E total" 454 455 /* Posix getpgrp takes no argument, while the BSD version * 456 * takes the process ID as an argument */ 457 #ifdef GETPGRP_VOID 458 # define GETPGRP() getpgrp() 459 #else 460 # define GETPGRP() getpgrp(0) 461 #endif 462 463 #ifndef HAVE_GETLOGIN 464 # define getlogin() cuserid(NULL) 465 #endif 466 467 #ifdef HAVE_SETPGID 468 # define setpgrp setpgid 469 #endif 470 471 /* compatibility wrappers */ 472 473 /* Our strategy is as follows: 474 * 475 * - Ensure that either setre[ug]id() or set{e,}[ug]id() is available. 476 * - If setres[ug]id() are missing, provide them in terms of either 477 * setre[ug]id() or set{e,}[ug]id(), whichever is available. 478 * - Provide replacement setre[ug]id() or set{e,}[ug]id() if they are not 479 * available natively. 480 * 481 * There isn't a circular dependency because, right off the bat, we check that 482 * there's an end condition, and #error out otherwise. 483 */ 484 #if !defined(HAVE_SETREUID) && !(defined(HAVE_SETEUID) && defined(HAVE_SETUID)) 485 /* 486 * If you run into this error, you have two options: 487 * - Teach zsh how to do the equivalent of setreuid() on your system 488 * - Remove support for PRIVILEGED option, and then remove the #error. 489 */ 490 # error "Don't know how to change UID" 491 #endif 492 #if !defined(HAVE_SETREGID) && !(defined(HAVE_SETEGID) && defined(HAVE_SETGID)) 493 /* See above comment. */ 494 # error "Don't know how to change GID" 495 #endif 496 497 /* Provide setresuid(). */ 498 #ifndef HAVE_SETRESUID 499 int setresuid(uid_t, uid_t, uid_t); 500 # define HAVE_SETRESUID 501 # define ZSH_IMPLEMENT_SETRESUID 502 # ifdef HAVE_SETREUID 503 # define ZSH_HAVE_NATIVE_SETREUID 504 # endif 505 #endif 506 507 /* Provide setresgid(). */ 508 #ifndef HAVE_SETRESGID 509 int setresgid(gid_t, gid_t, gid_t); 510 # define HAVE_SETRESGID 511 # define ZSH_IMPLEMENT_SETRESGID 512 # ifdef HAVE_SETREGID 513 # define ZSH_HAVE_NATIVE_SETREGID 514 # endif 515 #endif 516 517 /* Provide setreuid(). */ 518 #ifndef HAVE_SETREUID 519 # define setreuid(X, Y) setresuid((X), (Y), -1) 520 # define HAVE_SETREUID 521 #endif 522 523 /* Provide setregid(). */ 524 #ifndef HAVE_SETREGID 525 # define setregid(X, Y) setresgid((X), (Y), -1) 526 # define HAVE_SETREGID 527 #endif 528 529 /* Provide setuid(). */ 530 /* ### TODO: Either remove this (this function has been standard since 1985), 531 * ### or rewrite this without multiply-evaluating the argument */ 532 #ifndef HAVE_SETUID 533 # define setuid(X) setreuid((X), (X)) 534 # define HAVE_SETUID 535 #endif 536 537 /* Provide setgid(). */ 538 #ifndef HAVE_SETGID 539 /* ### TODO: Either remove this (this function has been standard since 1985), 540 * ### or rewrite this without multiply-evaluating the argument */ 541 # define setgid(X) setregid((X), (X)) 542 # define HAVE_SETGID 543 #endif 544 545 /* Provide seteuid(). */ 546 #ifndef HAVE_SETEUID 547 # define seteuid(X) setreuid(-1, (X)) 548 # define HAVE_SETEUID 549 #endif 550 551 /* Provide setegid(). */ 552 #ifndef HAVE_SETEGID 553 # define setegid(X) setregid(-1, (X)) 554 # define HAVE_SETEGID 555 #endif 556 557 #ifdef HAVE_SYS_RESOURCE_H 558 # include <sys/resource.h> 559 # if defined(__hpux) && !defined(RLIMIT_CPU) 560 /* HPUX does have the BSD rlimits in the kernel. Officially they are * 561 * unsupported but quite a few of them like RLIMIT_CORE seem to work. * 562 * All the following are in the <sys/resource.h> but made visible * 563 * only for the kernel. */ 564 # define RLIMIT_CPU 0 565 # define RLIMIT_FSIZE 1 566 # define RLIMIT_DATA 2 567 # define RLIMIT_STACK 3 568 # define RLIMIT_CORE 4 569 # define RLIMIT_RSS 5 570 # define RLIMIT_NOFILE 6 571 # define RLIMIT_OPEN_MAX RLIMIT_NOFILE 572 # define RLIM_NLIMITS 7 573 # define RLIM_INFINITY 0x7fffffff 574 # endif 575 #endif 576 577 /* we use the SVR4 constant instead of the BSD one */ 578 #if !defined(RLIMIT_NOFILE) && defined(RLIMIT_OFILE) 579 # define RLIMIT_NOFILE RLIMIT_OFILE 580 #endif 581 #if !defined(RLIMIT_VMEM) && defined(RLIMIT_AS) 582 # define RLIMIT_VMEM RLIMIT_AS 583 #endif 584 585 #if defined(HAVE_SYS_CAPABILITY_H) && defined(HAVE_CAP_GET_PROC) 586 # include <sys/capability.h> 587 #endif 588 589 /* DIGBUFSIZ is the length of a buffer which can hold the -LONG_MAX-1 * 590 * (or with ZSH_64_BIT_TYPE maybe -LONG_LONG_MAX-1) * 591 * converted to printable decimal form including the sign and the * 592 * terminating null character. Below 0.30103 > lg 2. * 593 * BDIGBUFSIZE is for a number converted to printable binary form. */ 594 #define DIGBUFSIZE ((int)(((sizeof(zlong) * 8) - 1) * 30103/100000) + 3) 595 #define BDIGBUFSIZE ((int)((sizeof(zlong) * 8) + 4)) 596 597 /* If your stat macros are broken, we will * 598 * just undefine them. */ 599 600 #ifdef STAT_MACROS_BROKEN 601 # undef S_ISBLK 602 # undef S_ISCHR 603 # undef S_ISDIR 604 # undef S_ISDOOR 605 # undef S_ISFIFO 606 # undef S_ISLNK 607 # undef S_ISMPB 608 # undef S_ISMPC 609 # undef S_ISNWK 610 # undef S_ISOFD 611 # undef S_ISOFL 612 # undef S_ISREG 613 # undef S_ISSOCK 614 #endif /* STAT_MACROS_BROKEN. */ 615 616 /* If you are missing the stat macros, we * 617 * define our own */ 618 619 #ifndef S_IFMT 620 # define S_IFMT 0170000 621 #endif 622 623 #if !defined(S_ISBLK) && defined(S_IFBLK) 624 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 625 #endif 626 #if !defined(S_ISCHR) && defined(S_IFCHR) 627 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 628 #endif 629 #if !defined(S_ISDIR) && defined(S_IFDIR) 630 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 631 #endif 632 #if !defined(S_ISDOOR) && defined(S_IFDOOR) /* Solaris */ 633 # define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR) 634 #endif 635 #if !defined(S_ISFIFO) && defined(S_IFIFO) 636 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 637 #endif 638 #if !defined(S_ISLNK) && defined(S_IFLNK) 639 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) 640 #endif 641 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */ 642 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) 643 #endif 644 #if !defined(S_ISMPC) && defined(S_IFMPC) /* V7 */ 645 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) 646 #endif 647 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */ 648 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) 649 #endif 650 #if !defined(S_ISOFD) && defined(S_IFOFD) /* Cray */ 651 # define S_ISOFD(m) (((m) & S_IFMT) == S_IFOFD) 652 #endif 653 #if !defined(S_ISOFL) && defined(S_IFOFL) /* Cray */ 654 # define S_ISOFL(m) (((m) & S_IFMT) == S_IFOFL) 655 #endif 656 #if !defined(S_ISREG) && defined(S_IFREG) 657 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 658 #endif 659 #if !defined(S_ISSOCK) && defined(S_IFSOCK) 660 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) 661 #endif 662 663 /* We will pretend to have all file types on any system. */ 664 665 #ifndef S_ISBLK 666 # define S_ISBLK(m) ((void)(m), 0) 667 #endif 668 #ifndef S_ISCHR 669 # define S_ISCHR(m) ((void)(m), 0) 670 #endif 671 #ifndef S_ISDIR 672 # define S_ISDIR(m) ((void)(m), 0) 673 #endif 674 #ifndef S_ISDOOR 675 # define S_ISDOOR(m) ((void)(m), 0) 676 #endif 677 #ifndef S_ISFIFO 678 # define S_ISFIFO(m) ((void)(m), 0) 679 #endif 680 #ifndef S_ISLNK 681 # define S_ISLNK(m) ((void)(m), 0) 682 #endif 683 #ifndef S_ISMPB 684 # define S_ISMPB(m) ((void)(m), 0) 685 #endif 686 #ifndef S_ISMPC 687 # define S_ISMPC(m) ((void)(m), 0) 688 #endif 689 #ifndef S_ISNWK 690 # define S_ISNWK(m) ((void)(m), 0) 691 #endif 692 #ifndef S_ISOFD 693 # define S_ISOFD(m) ((void)(m), 0) 694 #endif 695 #ifndef S_ISOFL 696 # define S_ISOFL(m) ((void)(m), 0) 697 #endif 698 #ifndef S_ISREG 699 # define S_ISREG(m) ((void)(m), 0) 700 #endif 701 #ifndef S_ISSOCK 702 # define S_ISSOCK(m) ((void)(m), 0) 703 #endif 704 705 /* file mode permission bits */ 706 707 #ifndef S_ISUID 708 # define S_ISUID 04000 709 #endif 710 #ifndef S_ISGID 711 # define S_ISGID 02000 712 #endif 713 #ifndef S_ISVTX 714 # define S_ISVTX 01000 715 #endif 716 #ifndef S_IRUSR 717 # define S_IRUSR 00400 718 #endif 719 #ifndef S_IWUSR 720 # define S_IWUSR 00200 721 #endif 722 #ifndef S_IXUSR 723 # define S_IXUSR 00100 724 #endif 725 #ifndef S_IRGRP 726 # define S_IRGRP 00040 727 #endif 728 #ifndef S_IWGRP 729 # define S_IWGRP 00020 730 #endif 731 #ifndef S_IXGRP 732 # define S_IXGRP 00010 733 #endif 734 #ifndef S_IROTH 735 # define S_IROTH 00004 736 #endif 737 #ifndef S_IWOTH 738 # define S_IWOTH 00002 739 #endif 740 #ifndef S_IXOTH 741 # define S_IXOTH 00001 742 #endif 743 #ifndef S_IRWXU 744 # define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) 745 #endif 746 #ifndef S_IRWXG 747 # define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP) 748 #endif 749 #ifndef S_IRWXO 750 # define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH) 751 #endif 752 #ifndef S_IRUGO 753 # define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH) 754 #endif 755 #ifndef S_IWUGO 756 # define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH) 757 #endif 758 #ifndef S_IXUGO 759 # define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH) 760 #endif 761 762 #ifndef HAVE_LSTAT 763 # define lstat stat 764 #endif 765 766 #ifndef HAVE_READLINK 767 # define readlink(PATH, BUF, BUFSZ) \ 768 ((void)(PATH), (void)(BUF), (void)(BUFSZ), errno = ENOSYS, -1) 769 #endif 770 771 #ifndef F_OK /* missing macros for access() */ 772 # define F_OK 0 773 # define X_OK 1 774 # define W_OK 2 775 # define R_OK 4 776 #endif 777 778 #ifndef HAVE_LCHOWN 779 # define lchown chown 780 #endif 781 782 #ifndef HAVE_MEMCPY 783 # define memcpy memmove 784 #endif 785 786 #ifndef HAVE_MEMMOVE 787 # ifndef memmove 788 static char *zmmv; 789 # define memmove(dest, src, len) (bcopy((src), zmmv = (dest), (len)), zmmv) 790 # endif 791 #endif 792 793 #ifndef offsetof 794 # define offsetof(TYPE, MEM) ((char *)&((TYPE *)0)->MEM - (char *)(TYPE *)0) 795 #endif 796 797 extern char **environ; 798 799 /* 800 * We always need setenv and unsetenv in pairs, because 801 * we don't know how to do memory management on the values set. 802 */ 803 #if defined(HAVE_SETENV) && defined(HAVE_UNSETENV) && !defined(__APPLE__) 804 # define USE_SET_UNSET_ENV 805 #endif 806 807 808 /* These variables are sometimes defined in, * 809 * and needed by, the termcap library. */ 810 #if MUST_DEFINE_OSPEED 811 extern char PC, *BC, *UP; 812 extern short ospeed; 813 #endif 814 815 #ifndef O_NOCTTY 816 # define O_NOCTTY 0 817 #endif 818 819 #ifdef _LARGEFILE_SOURCE 820 #ifdef HAVE_FSEEKO 821 #define fseek fseeko 822 #endif 823 #ifdef HAVE_FTELLO 824 #define ftell ftello 825 #endif 826 #endif 827 828 /* Can't support job control without working tcsetgrp() */ 829 #ifdef BROKEN_TCSETPGRP 830 #undef JOB_CONTROL 831 #endif /* BROKEN_TCSETPGRP */ 832 833 #ifdef BROKEN_KILL_ESRCH 834 #undef ESRCH 835 #define ESRCH EINVAL 836 #endif /* BROKEN_KILL_ESRCH */ 837 838 /* Can we do locale stuff? */ 839 #undef USE_LOCALE 840 #if defined(CONFIG_LOCALE) && defined(HAVE_SETLOCALE) && defined(LC_ALL) 841 # define USE_LOCALE 1 842 #endif /* CONFIG_LOCALE && HAVE_SETLOCALE && LC_ALL */ 843 844 #ifndef MAILDIR_SUPPORT 845 #define mailstat(X,Y) stat(X,Y) 846 #endif 847 848 #ifdef __CYGWIN__ 849 # include <sys/cygwin.h> 850 # define IS_DIRSEP(c) ((c) == '/' || (c) == '\\') 851 #else 852 # define IS_DIRSEP(c) ((c) == '/') 853 #endif 854 855 #if defined(__GNUC__) && (!defined(__APPLE__) || defined(__clang__)) 856 /* Does the OS X port of gcc still gag on __attribute__? */ 857 #define UNUSED(x) x __attribute__((__unused__)) 858 #else 859 #define UNUSED(x) x 860 #endif 861 862 /* 863 * The MULTIBYTE_SUPPORT configure-define specifies that we want to enable 864 * complete Unicode conversion between wide characters and multibyte strings. 865 */ 866 #if defined MULTIBYTE_SUPPORT \ 867 || (defined HAVE_WCHAR_H && defined HAVE_WCTOMB && defined __STDC_ISO_10646__) 868 /* 869 * If MULTIBYTE_SUPPORT is not defined, these includes provide a subset of 870 * Unicode support that makes the \u and \U printf escape sequences work. 871 */ 872 873 #if defined(__hpux) && !defined(_INCLUDE__STDC_A1_SOURCE) 874 #define _INCLUDE__STDC_A1_SOURCE 875 #endif 876 877 # include <wchar.h> 878 # include <wctype.h> 879 #endif 880 #ifdef HAVE_LANGINFO_H 881 # include <langinfo.h> 882 # ifdef HAVE_ICONV 883 # include <iconv.h> 884 # endif 885 #endif 886 887 #if defined(HAVE_INITGROUPS) && !defined(DISABLE_DYNAMIC_NSS) 888 # define USE_INITGROUPS 889 #endif 890 891 #if defined(HAVE_GETGRGID) && !defined(DISABLE_DYNAMIC_NSS) 892 # define USE_GETGRGID 893 #endif 894 895 #if defined(HAVE_GETGRNAM) && !defined(DISABLE_DYNAMIC_NSS) 896 # define USE_GETGRNAM 897 #endif 898 899 #if defined(HAVE_GETPWENT) && !defined(DISABLE_DYNAMIC_NSS) 900 # define USE_GETPWENT 901 #endif 902 903 #if defined(HAVE_GETPWNAM) && !defined(DISABLE_DYNAMIC_NSS) 904 # define USE_GETPWNAM 905 #endif 906 907 #if defined(HAVE_GETPWUID) && !defined(DISABLE_DYNAMIC_NSS) 908 # define USE_GETPWUID 909 #endif 910 911 #ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC 912 # define GET_ST_ATIME_NSEC(st) (st).st_atim.tv_nsec 913 #elif HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC 914 # define GET_ST_ATIME_NSEC(st) (st).st_atimespec.tv_nsec 915 #elif HAVE_STRUCT_STAT_ST_ATIMENSEC 916 # define GET_ST_ATIME_NSEC(st) (st).st_atimensec 917 #endif 918 #ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 919 # define GET_ST_MTIME_NSEC(st) (st).st_mtim.tv_nsec 920 #elif HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 921 # define GET_ST_MTIME_NSEC(st) (st).st_mtimespec.tv_nsec 922 #elif HAVE_STRUCT_STAT_ST_MTIMENSEC 923 # define GET_ST_MTIME_NSEC(st) (st).st_mtimensec 924 #endif 925 #ifdef HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC 926 # define GET_ST_CTIME_NSEC(st) (st).st_ctim.tv_nsec 927 #elif HAVE_STRUCT_STAT_ST_CTIMESPEC_TV_NSEC 928 # define GET_ST_CTIME_NSEC(st) (st).st_ctimespec.tv_nsec 929 #elif HAVE_STRUCT_STAT_ST_CTIMENSEC 930 # define GET_ST_CTIME_NSEC(st) (st).st_ctimensec 931 #endif 932 933 #if defined(HAVE_TGETENT) && !defined(ZSH_NO_TERM_HANDLING) 934 # if defined(ZSH_HAVE_CURSES_H) && defined(ZSH_HAVE_TERM_H) 935 # define USES_TERM_H 1 936 # else 937 # ifdef HAVE_TERMCAP_H 938 # define USES_TERMCAP_H 1 939 # endif 940 # endif 941 942 # ifdef USES_TERM_H 943 # ifdef HAVE_TERMIO_H 944 # include <termio.h> 945 # endif 946 # ifdef ZSH_HAVE_CURSES_H 947 # include "zshcurses.h" 948 # endif 949 # include "zshterm.h" 950 # else 951 # ifdef USES_TERMCAP_H 952 # include <termcap.h> 953 # endif 954 # endif 955 #endif 956 957 #ifdef HAVE_SRAND_DETERMINISTIC 958 # define srand srand_deterministic 959 #endif 960 961 #ifdef ZSH_VALGRIND 962 # include "valgrind/valgrind.h" 963 # include "valgrind/memcheck.h" 964 #endif 965