tc.os.h revision 231990
1/* $Header: /p/tcsh/cvsroot/tcsh/tc.os.h,v 3.105 2011/02/04 18:00:26 christos Exp $ */ 2/* 3 * tc.os.h: Shell os dependent defines 4 */ 5/*- 6 * Copyright (c) 1980, 1991 The Regents of the University of California. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33#ifndef _h_tc_os 34#define _h_tc_os 35 36#ifdef notdef 37/* 38 * for SVR4 and linux we used to fork pipelines backwards. 39 * This should not be needed any more. 40 * more info in sh.sem.c 41 */ 42# define BACKPIPE 43#endif /* notdef */ 44 45#ifdef __CYGWIN__ 46# undef NOFILE 47# define NOFILE sysconf(_SC_OPEN_MAX) 48#endif 49 50#ifdef _VMS_POSIX 51# ifndef NOFILE 52# define NOFILE 64 53# endif /* NOFILE */ 54# define nice(a) setprio((getpid()),a) 55# include <sys/time.h> /* for time stuff in tc.prompt.c */ 56# include <limits.h> 57#endif /* atp vmsposix */ 58 59#if defined(DECOSF1) || defined(HPUXVERSION) 60# include <sys/signal.h> 61#endif /* DECOSF1 || HPUXVERSION */ 62 63#ifdef DECOSF1 64# include <sys/ioctl.h> 65#endif /* DECOSF1 */ 66 67#if defined(OPEN_MAX) && !defined(NOFILE) 68# define NOFILE OPEN_MAX 69#endif /* OPEN_MAX && !NOFILE */ 70 71#if defined(USR_NFDS) && !defined(NOFILE) 72# define NOFILE USR_NFDS 73#endif /* USR_NFDS && !NOFILE */ 74 75#ifndef NOFILE 76# define NOFILE 256 77#endif /* NOFILE */ 78 79#ifdef OREO 80# include <sys/time.h> 81# ifdef notdef 82 /* Don't include it, because it defines things we don't really have */ 83# include <sys/resource.h> 84# endif /* notdef */ 85# ifdef POSIX 86# include <sys/tty.h> 87# include <termios.h> 88# endif /* POSIX */ 89#endif /* OREO */ 90 91#ifdef __QNXNTO__ 92#include <sys/resource.h> 93#include <fcntl.h> 94#undef O_TEXT 95#undef O_BINARY 96#endif 97 98#ifdef convex 99# include <sys/dmon.h> 100#endif /* convex */ 101 102#ifdef titan 103extern int end; 104#endif /* titan */ 105 106#ifdef hpux 107# ifdef lint 108/* 109 * Hpux defines struct ucred, in <sys/user.h>, but if I include that 110 * then I need to include the *world* 111 * [all this to pass lint cleanly!!!] 112 * so I define struct ucred here... 113 */ 114struct ucred { 115 int foo; 116}; 117# endif /* lint */ 118 119/* 120 * hpux 7.0 does not define it 121 */ 122# ifndef CSUSP 123# define CSUSP 032 124# endif /* CSUSP */ 125 126# include <signal.h> 127# if !defined(hp9000s500) && !(defined(SIGRTMAX) || defined(SIGRTMIN)) 128/* 129 * hpux < 7 130 */ 131# include <sys/bsdtty.h> 132# endif /* !hp9000s500 && !(SIGRTMAX || SIGRTMIN) */ 133 134# ifndef TIOCSTI 135# include <sys/strtio.h> 136# endif 137#endif /* hpux */ 138 139/* 140 * ISC does not define CSUSP 141 */ 142#ifdef ISC 143# ifndef CSUSP 144# define CSUSP 032 145# endif /* CSUSP */ 146# if defined(POSIX) && !defined(TIOCGWINSZ) 147/* 148 * ISC defines this only in termio.h. If we are using POSIX and include 149 * termios.h, then we define it ourselves so that window resizing works. 150 */ 151# define TIOCGWINSZ (('T'<<8)|104) 152# endif /* POSIX && !TIOCGWINSZ */ 153#endif /* ISC */ 154 155#ifdef ISC202 156# undef TIOCGWINSZ 157#endif /* ISC202 */ 158 159/* 160 * XXX: This will be changed soon to 161 * #if (SYSVREL > 0) && defined(TIOCGWINSZ) 162 * If that breaks on your machine, let me know. 163 * 164 * It would break on glibc, where all this is 165 * defined in <termios.h>. Wrapper added. 166 */ 167#if !defined(__linux__) && !defined(__GNU__) && !defined(__GLIBC__) && !defined(_VMS_POSIX) 168# if defined(INTEL) || defined(u3b2) || defined (u3b5) || defined(ub15) || defined(u3b20d) || defined(ISC) || defined(SCO) || defined(tower32) 169# ifdef TIOCGWINSZ 170/* 171 * for struct winsiz 172 */ 173# include <sys/stream.h> 174# include <sys/ptem.h> 175# endif /* TIOCGWINSZ */ 176# endif /* INTEL || u3b2 || u3b5 || ub15 || u3b20d || ISC || SCO || tower32 */ 177#endif /* !glibc && !_VMS_POSIX */ 178 179#ifdef IRIS4D 180# include <sys/time.h> 181# include <sys/resource.h> 182#endif /* IRIS4D */ 183 184/* 185 * For some versions of system V software, specially ones that use the 186 * Wollongong Software TCP/IP, the FIOCLEX, FIONCLEX, FIONBIO calls 187 * might not work correctly for file descriptors [they work only for 188 * sockets]. So we try to use first the fcntl() and we only use the 189 * ioctl() form, only if we don't have the fcntl() one. 190 * 191 * From: scott@craycos.com (Scott Bolte) 192 */ 193#ifndef WINNT_NATIVE 194# ifdef F_SETFD 195# ifndef FD_CLOEXEC 196# define FD_CLOEXEC 1 197# endif 198# define close_on_exec(fd, v) fcntl((fd), F_SETFD, ((v) ? FD_CLOEXEC : 0)) 199# else /* !F_SETFD */ 200# ifdef FIOCLEX 201# define close_on_exec(fd, v) ioctl((fd), ((v) ? FIOCLEX : FIONCLEX), NULL) 202# else /* !FIOCLEX */ 203# define close_on_exec(fd, v) /* Nothing */ 204# endif /* FIOCLEX */ 205# endif /* F_SETFD */ 206#else /* WINNT_NATIVE */ 207# define close_on_exec(fd, v) nt_close_on_exec((fd),(v)) 208#endif /* !WINNT_NATIVE */ 209 210/* 211 * Stat 212 */ 213#ifdef ISC 214/* these are not defined for _POSIX_SOURCE under ISC 2.2 */ 215# ifndef S_IFMT 216# define S_IFMT 0170000 /* type of file */ 217# define S_IFDIR 0040000 /* directory */ 218# define S_IFCHR 0020000 /* character special */ 219# define S_IFBLK 0060000 /* block special */ 220# define S_IFREG 0100000 /* regular */ 221# define S_IFIFO 0010000 /* fifo */ 222# define S_IFNAM 0050000 /* special named file */ 223# ifndef ISC202 224# define S_IFLNK 0120000 /* symbolic link */ 225# endif /* ISC202 */ 226# endif /* S_IFMT */ 227#endif /* ISC */ 228 229#ifdef STAT_MACROS_BROKEN 230# undef S_ISDIR 231# undef S_ISCHR 232# undef S_ISBLK 233# undef S_ISREG 234# undef S_ISFIFO 235# undef S_ISNAM 236# undef S_ISLNK 237# undef S_ISSOCK 238#endif /* STAT_MACROS_BROKEN */ 239 240#ifdef S_IFMT 241# if !defined(S_ISDIR) && defined(S_IFDIR) 242# define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR) 243# endif /* ! S_ISDIR && S_IFDIR */ 244# if !defined(S_ISCHR) && defined(S_IFCHR) 245# define S_ISCHR(a) (((a) & S_IFMT) == S_IFCHR) 246# endif /* ! S_ISCHR && S_IFCHR */ 247# if !defined(S_ISBLK) && defined(S_IFBLK) 248# define S_ISBLK(a) (((a) & S_IFMT) == S_IFBLK) 249# endif /* ! S_ISBLK && S_IFBLK */ 250# if !defined(S_ISREG) && defined(S_IFREG) 251# define S_ISREG(a) (((a) & S_IFMT) == S_IFREG) 252# endif /* ! S_ISREG && S_IFREG */ 253# if !defined(S_ISFIFO) && defined(S_IFIFO) 254# define S_ISFIFO(a) (((a) & S_IFMT) == S_IFIFO) 255# endif /* ! S_ISFIFO && S_IFIFO */ 256# if !defined(S_ISNAM) && defined(S_IFNAM) 257# define S_ISNAM(a) (((a) & S_IFMT) == S_IFNAM) 258# endif /* ! S_ISNAM && S_IFNAM */ 259# if !defined(S_ISLNK) && defined(S_IFLNK) 260# define S_ISLNK(a) (((a) & S_IFMT) == S_IFLNK) 261# endif /* ! S_ISLNK && S_IFLNK */ 262# if !defined(S_ISSOCK) && defined(S_IFSOCK) 263# define S_ISSOCK(a) (((a) & S_IFMT) == S_IFSOCK) 264# endif /* ! S_ISSOCK && S_IFSOCK */ 265#endif /* S_IFMT */ 266 267#ifdef tower32 268/* The header files lie; we really don't have symlinks */ 269# undef S_ISLNK 270# undef S_IFLNK 271#endif /* tower32 */ 272 273#ifndef S_IREAD 274# define S_IREAD 0000400 275#endif /* S_IREAD */ 276#ifndef S_IROTH 277# define S_IROTH (S_IREAD >> 6) 278#endif /* S_IROTH */ 279#ifndef S_IRGRP 280# define S_IRGRP (S_IREAD >> 3) 281#endif /* S_IRGRP */ 282#ifndef S_IRUSR 283# define S_IRUSR S_IREAD 284#endif /* S_IRUSR */ 285 286#ifndef S_IWRITE 287# define S_IWRITE 0000200 288#endif /* S_IWRITE */ 289#ifndef S_IWOTH 290# define S_IWOTH (S_IWRITE >> 6) 291#endif /* S_IWOTH */ 292#ifndef S_IWGRP 293# define S_IWGRP (S_IWRITE >> 3) 294#endif /* S_IWGRP */ 295#ifndef S_IWUSR 296# define S_IWUSR S_IWRITE 297#endif /* S_IWUSR */ 298 299#ifndef S_IEXEC 300# define S_IEXEC 0000100 301#endif /* S_IEXEC */ 302#ifndef S_IXOTH 303# define S_IXOTH (S_IEXEC >> 6) 304#endif /* S_IXOTH */ 305#ifndef S_IXGRP 306# define S_IXGRP (S_IEXEC >> 3) 307#endif /* S_IXGRP */ 308#ifndef S_IXUSR 309# define S_IXUSR S_IEXEC 310#endif /* S_IXUSR */ 311 312#ifndef S_ISUID 313# define S_ISUID 0004000 /* setuid */ 314#endif /* S_ISUID */ 315#ifndef S_ISGID 316# define S_ISGID 0002000 /* setgid */ 317#endif /* S_ISGID */ 318#ifndef S_ISVTX 319# define S_ISVTX 0001000 /* sticky */ 320#endif /* S_ISVTX */ 321#ifndef S_ENFMT 322# define S_ENFMT S_ISGID /* record locking enforcement flag */ 323#endif /* S_ENFMT */ 324 325/* the following macros are for POSIX conformance */ 326#ifndef S_IRWXU 327# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) 328#endif /* S_IRWXU */ 329#ifndef S_IRWXG 330# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) 331#endif /* S_IRWXG */ 332#ifndef S_IRWXO 333# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) 334#endif /* S_IRWXO */ 335 336/* 337 * Access() 338 */ 339#ifndef F_OK 340# define F_OK 0 341#endif /* F_OK */ 342#ifndef X_OK 343# define X_OK 1 344#endif /* X_OK */ 345#ifndef W_OK 346# define W_OK 2 347#endif /* W_OK */ 348#ifndef R_OK 349# define R_OK 4 350#endif /* R_OK */ 351 352/* 353 * Open() 354 */ 355#ifndef O_RDONLY 356# define O_RDONLY 0 357#endif /* O_RDONLY */ 358#ifndef O_WRONLY 359# define O_WRONLY 1 360#endif /* O_WRONLY */ 361#ifndef O_RDWR 362# define O_RDWR 2 363#endif /* O_RDWR */ 364#ifndef O_TEMPORARY 365# define O_TEMPORARY 0 366#endif /* O_TEMPORARY */ 367#ifndef O_EXCL 368# define O_EXCL 0 369#endif /* O_EXCL */ 370#ifndef O_LARGEFILE 371# define O_LARGEFILE 0 372#endif /* O_LARGEFILE */ 373#ifndef O_CREAT 374# define O_CREAT 0 375#endif /* O_CREAT */ 376 377/* 378 * Lseek() 379 */ 380#ifndef L_SET 381# ifdef SEEK_SET 382# define L_SET SEEK_SET 383# else /* !SEEK_SET */ 384# define L_SET 0 385# endif /* SEEK_SET */ 386#endif /* L_SET */ 387#ifndef L_INCR 388# ifdef SEEK_CUR 389# define L_INCR SEEK_CUR 390# else /* !SEEK_CUR */ 391# define L_INCR 1 392# endif /* SEEK_CUR */ 393#endif /* L_INCR */ 394#ifndef L_XTND 395# ifdef SEEK_END 396# define L_XTND SEEK_END 397# else /* !SEEK_END */ 398# define L_XTND 2 399# endif /* SEEK_END */ 400#endif /* L_XTND */ 401 402#if !defined (HAVE_SETPGID) && !defined (SETPGRP_VOID) 403# define setpgid(pid, pgrp) setpgrp(pid, pgrp) 404#endif 405 406#if defined(BSDJOBS) && !(defined(POSIX) && defined(POSIXJOBS)) 407# define NEEDtcgetpgrp 408#endif /* BSDJOBS && !(POSIX && POSIXJOBS) */ 409 410#ifdef RENO 411/* 412 * RENO has this broken. It is fixed on 4.4BSD 413 */ 414# define NEEDtcgetpgrp 415#endif /* RENO */ 416 417#ifdef SXA 418# ifndef _BSDX_ 419/* 420 * Only needed in the system V environment. 421 */ 422# define setrlimit bsd_setrlimit 423# define getrlimit bsd_getrlimit 424# endif /* _BSDX_ */ 425#endif /* SXA */ 426 427#if defined(_MINIX) || defined(__EMX__) 428# define HAVENOLIMIT 429/* 430 * Minix does not have these, so... 431 */ 432# define getpgrp getpid 433#endif /* _MINIX || __EMX__ */ 434 435#ifdef __EMX__ 436/* XXX: How can we get the tty name in emx? */ 437# define ttyname(fd) (isatty(fd) ? "/dev/tty" : NULL) 438#endif /* __EMX__ */ 439 440#ifndef S_IFLNK 441# define lstat stat 442#endif /* S_IFLNK */ 443 444 445#if defined(BSDTIMES) && !defined(_SEQUENT_) 446typedef struct timeval timeval_t; 447#endif /* BSDTIMES && ! _SEQUENT_ */ 448 449#ifdef NeXT 450/* 451 * From Tony_Mason@transarc.com, override NeXT's malloc stuff. 452 */ 453# define malloc tcsh_malloc 454# define calloc tcsh_calloc 455# define realloc tcsh_realloc 456# define free tcsh_free 457#endif /* NeXT */ 458 459#if defined(HAVE_GETHOSTNAME) && !HAVE_DECL_GETHOSTNAME 460extern int gethostname (char *, int); 461#endif 462 463#ifndef GETPGRP_VOID 464# define mygetpgrp() getpgrp(0) 465#else 466# define mygetpgrp() getpgrp() 467#endif 468 469#if !defined(POSIX) || defined(SUNOS4) || defined(UTekV) || defined(sysV88) 470extern time_t time(); 471extern char *getenv(); 472extern int atoi(); 473# ifndef __EMX__ 474extern char *ttyname(); 475# endif /* __EMX__ */ 476 477 478# if defined(SUNOS4) 479# ifndef toupper 480extern int toupper (int); 481# endif /* toupper */ 482# ifndef tolower 483extern int tolower (int); 484# endif /* tolower */ 485extern caddr_t sbrk (int); 486# else /* !SUNOS4 */ 487# ifndef WINNT_NATIVE 488# ifdef hpux 489extern void abort(); 490extern void qsort(); 491# endif /* hpux */ 492# endif /* !WINNT_NATIVE */ 493# endif /* SUNOS4 */ 494#ifndef _CX_UX 495extern void perror(); 496#endif 497 498# ifdef BSD 499extern uid_t getuid(), geteuid(); 500extern gid_t getgid(), getegid(); 501# endif /* BSD */ 502 503# ifdef SYSMALLOC 504extern memalign_t malloc(); 505extern memalign_t realloc(); 506extern memalign_t calloc(); 507extern void free(); 508# endif /* SYSMALLOC */ 509 510# ifdef BSDJOBS 511# ifdef BSDTIMES 512# ifdef __MACHTEN__ 513extern pid_t wait3(); 514# endif /* __MACHTEN__ */ 515# endif /* BSDTIMES */ 516# endif /* BSDJOBS */ 517 518# if (!defined(fps500) && !defined(apollo) && !defined(__lucid) && !defined(HPBSD) && !defined(DECOSF1)) 519extern void setpwent(); 520extern void endpwent(); 521# endif /* !fps500 && !apollo && !__lucid && !HPBSD && !DECOSF1 */ 522 523# ifndef __STDC__ 524extern struct passwd *getpwuid(), *getpwnam(), *getpwent(); 525# ifdef HAVE_SHADOW_H 526extern struct spwd *getspnam(), *getspent(); 527# endif /* HAVE_SHADOW_H */ 528# if defined(HAVE_AUTH_H) && defined(HAVE_GETAUTHUID) 529extern struct authorization *getauthuid(); 530# endif /* HAVE_AUTH_H && HAVE_GETAUTHUID */ 531# endif /* __STDC__ */ 532 533# ifndef getcwd 534extern char *getcwd(); 535# endif /* getcwd */ 536 537#else /* POSIX || !SUNOS4 || !UTekV || !sysV88 */ 538 539# if (defined(SUNOS4) && !defined(__GNUC__)) || defined(_IBMR2) || defined(_IBMESA) 540extern char *getvwd(); 541# endif /* (SUNOS4 && ! __GNUC__) || _IBMR2 || _IBMESA */ 542 543# ifdef SCO 544extern char *ttyname(); 545# endif /* SCO */ 546 547# ifdef __clipper__ 548extern char *ttyname(); 549# endif /* __clipper__ */ 550 551#endif /* !POSIX || SUNOS4 || UTekV || sysV88 */ 552 553#if defined(SUNOS4) && __GNUC__ == 2 554/* 555 * Somehow these are missing 556 */ 557extern int ioctl (int, int, ...); 558extern int readlink (const char *, char *, size_t); 559extern void setgrent (void); 560extern void endgrent (void); 561# ifdef REMOTEHOST 562# ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */ 563struct sockaddr; 564extern int getpeername (int, struct sockaddr *, int *); 565# endif /* _SOCKLEN_T */ 566# endif /* REMOTEHOST */ 567#endif /* SUNOS4 && __GNUC__ == 2 */ 568 569#if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4) 570# if defined(__alpha) && defined(__osf__) && DECOSF1 < 200 571extern void bcopy (const void *, void *, size_t); 572# define memmove(a, b, c) (bcopy((char *) (b), (char *) (a), (int) (c)), a) 573# endif /* __alpha && __osf__ && DECOSF1 < 200 */ 574#endif /* (BSD && !BSD4_4) || SUNOS4 */ 575 576#ifdef SUNOS4 577# include <memory.h> /* memset should be declared in <string.h> but isn't */ 578#endif /* SUNOS4 */ 579 580#if SYSVREL == 4 581# ifdef REMOTEHOST 582/* Irix6 defines getpeername(int, void *, int *) which conflicts with 583 the definition below. */ 584# if !defined(__sgi) && !defined(_OSD_POSIX) && !defined(__MVS__) 585# ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */ 586struct sockaddr; 587extern int getpeername (int, struct sockaddr *, int *); 588# endif /* _SOCKLEN_T */ 589# endif /* !__sgi && !_OSD_POSIX && !__MVS__ */ 590# endif /* REMOTEHOST */ 591# ifndef BSDTIMES 592extern int getrlimit (int, struct rlimit *); 593extern int setrlimit (int, const struct rlimit *); 594# endif /* !BSDTIMES */ 595# if defined(SOLARIS2) 596extern char *strerror (int); 597# endif /* SOLARIS2 */ 598#endif /* SYSVREL == 4 */ 599 600#if defined(__alpha) && defined(__osf__) && DECOSF1 < 200 601/* These are ok for 1.3, but conflict with the header files for 2.0 */ 602extern char *sbrk (ssize_t); 603extern int ioctl (int, unsigned long, char *); 604extern pid_t vfork (void); 605extern int killpg (pid_t, int); 606#endif /* __osf__ && __alpha && DECOSF1 < 200 */ 607 608#ifndef va_copy 609# ifdef __va_copy 610# define va_copy(DEST, SRC) __va_copy(DEST, SRC) 611# else 612# define va_copy(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(va_list)) 613# endif 614#endif 615 616#if defined(__CYGWIN__) && !defined(NO_CRYPT) 617extern char *cygwin_xcrypt(struct passwd *, const char *, const char *); 618#endif /* __CYGWIN__ && !NO_CRYPT */ 619 620#endif /* _h_tc_os */ 621