1/* $Header: /p/tcsh/cvsroot/tcsh/tc.os.h,v 3.102 2007/07/05 14:13:06 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 365/* 366 * Lseek() 367 */ 368#ifndef L_SET 369# ifdef SEEK_SET 370# define L_SET SEEK_SET 371# else /* !SEEK_SET */ 372# define L_SET 0 373# endif /* SEEK_SET */ 374#endif /* L_SET */ 375#ifndef L_INCR 376# ifdef SEEK_CUR 377# define L_INCR SEEK_CUR 378# else /* !SEEK_CUR */ 379# define L_INCR 1 380# endif /* SEEK_CUR */ 381#endif /* L_INCR */ 382#ifndef L_XTND 383# ifdef SEEK_END 384# define L_XTND SEEK_END 385# else /* !SEEK_END */ 386# define L_XTND 2 387# endif /* SEEK_END */ 388#endif /* L_XTND */ 389 390#if !defined (HAVE_SETPGID) && !defined (SETPGRP_VOID) 391# define setpgid(pid, pgrp) setpgrp(pid, pgrp) 392#endif 393 394#if defined(BSDJOBS) && !(defined(POSIX) && defined(POSIXJOBS)) 395# define NEEDtcgetpgrp 396#endif /* BSDJOBS && !(POSIX && POSIXJOBS) */ 397 398#ifdef RENO 399/* 400 * RENO has this broken. It is fixed on 4.4BSD 401 */ 402# define NEEDtcgetpgrp 403#endif /* RENO */ 404 405#ifdef SXA 406# ifndef _BSDX_ 407/* 408 * Only needed in the system V environment. 409 */ 410# define setrlimit bsd_setrlimit 411# define getrlimit bsd_getrlimit 412# endif /* _BSDX_ */ 413#endif /* SXA */ 414 415#if defined(_MINIX) || defined(__EMX__) 416# define HAVENOLIMIT 417/* 418 * Minix does not have these, so... 419 */ 420# define getpgrp getpid 421#endif /* _MINIX || __EMX__ */ 422 423#ifdef __EMX__ 424/* XXX: How can we get the tty name in emx? */ 425# define ttyname(fd) (isatty(fd) ? "/dev/tty" : NULL) 426#endif /* __EMX__ */ 427 428#ifndef S_IFLNK 429# define lstat stat 430#endif /* S_IFLNK */ 431 432 433#if defined(BSDTIMES) && !defined(_SEQUENT_) 434typedef struct timeval timeval_t; 435#endif /* BSDTIMES && ! _SEQUENT_ */ 436 437#ifdef NeXT 438/* 439 * From Tony_Mason@transarc.com, override NeXT's malloc stuff. 440 */ 441# define malloc tcsh_malloc 442# define calloc tcsh_calloc 443# define realloc tcsh_realloc 444# define free tcsh_free 445#endif /* NeXT */ 446 447#if defined(HAVE_GETHOSTNAME) && !HAVE_DECL_GETHOSTNAME 448extern int gethostname (char *, int); 449#endif 450 451#ifndef GETPGRP_VOID 452# define mygetpgrp() getpgrp(0) 453#else 454# define mygetpgrp() getpgrp() 455#endif 456 457#if !defined(POSIX) || defined(SUNOS4) || defined(UTekV) || defined(sysV88) 458extern time_t time(); 459extern char *getenv(); 460extern int atoi(); 461# ifndef __EMX__ 462extern char *ttyname(); 463# endif /* __EMX__ */ 464 465 466# if defined(SUNOS4) 467# ifndef toupper 468extern int toupper (int); 469# endif /* toupper */ 470# ifndef tolower 471extern int tolower (int); 472# endif /* tolower */ 473extern caddr_t sbrk (int); 474# else /* !SUNOS4 */ 475# ifndef WINNT_NATIVE 476# ifdef hpux 477extern void abort(); 478extern void qsort(); 479# endif /* hpux */ 480# endif /* !WINNT_NATIVE */ 481# endif /* SUNOS4 */ 482#ifndef _CX_UX 483extern void perror(); 484#endif 485 486# ifdef BSD 487extern uid_t getuid(), geteuid(); 488extern gid_t getgid(), getegid(); 489# endif /* BSD */ 490 491# ifdef SYSMALLOC 492extern memalign_t malloc(); 493extern memalign_t realloc(); 494extern memalign_t calloc(); 495extern void free(); 496# endif /* SYSMALLOC */ 497 498# ifdef BSDJOBS 499# ifdef BSDTIMES 500# ifdef __MACHTEN__ 501extern pid_t wait3(); 502# endif /* __MACHTEN__ */ 503# endif /* BSDTIMES */ 504# endif /* BSDJOBS */ 505 506# if (!defined(fps500) && !defined(apollo) && !defined(__lucid) && !defined(HPBSD) && !defined(DECOSF1)) 507extern void setpwent(); 508extern void endpwent(); 509# endif /* !fps500 && !apollo && !__lucid && !HPBSD && !DECOSF1 */ 510 511# ifndef __STDC__ 512extern struct passwd *getpwuid(), *getpwnam(), *getpwent(); 513# ifdef HAVE_SHADOW_H 514extern struct spwd *getspnam(), *getspent(); 515# endif /* HAVE_SHADOW_H */ 516# if defined(HAVE_AUTH_H) && defined(HAVE_GETAUTHUID) 517extern struct authorization *getauthuid(); 518# endif /* HAVE_AUTH_H && HAVE_GETAUTHUID */ 519# endif /* __STDC__ */ 520 521# ifndef getcwd 522extern char *getcwd(); 523# endif /* getcwd */ 524 525#else /* POSIX || !SUNOS4 || !UTekV || !sysV88 */ 526 527# if (defined(SUNOS4) && !defined(__GNUC__)) || defined(_IBMR2) || defined(_IBMESA) 528extern char *getvwd(); 529# endif /* (SUNOS4 && ! __GNUC__) || _IBMR2 || _IBMESA */ 530 531# ifdef SCO 532extern char *ttyname(); 533# endif /* SCO */ 534 535# ifdef __clipper__ 536extern char *ttyname(); 537# endif /* __clipper__ */ 538 539#endif /* !POSIX || SUNOS4 || UTekV || sysV88 */ 540 541#if defined(SUNOS4) && __GNUC__ == 2 542/* 543 * Somehow these are missing 544 */ 545extern int ioctl (int, int, ...); 546extern int readlink (const char *, char *, size_t); 547extern void setgrent (void); 548extern void endgrent (void); 549# ifdef REMOTEHOST 550# ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */ 551struct sockaddr; 552extern int getpeername (int, struct sockaddr *, int *); 553# endif /* _SOCKLEN_T */ 554# endif /* REMOTEHOST */ 555#endif /* SUNOS4 && __GNUC__ == 2 */ 556 557#if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4) 558# if defined(__alpha) && defined(__osf__) && DECOSF1 < 200 559extern void bcopy (const void *, void *, size_t); 560# define memmove(a, b, c) (bcopy((char *) (b), (char *) (a), (int) (c)), a) 561# endif /* __alpha && __osf__ && DECOSF1 < 200 */ 562#endif /* (BSD && !BSD4_4) || SUNOS4 */ 563 564#ifdef SUNOS4 565# include <memory.h> /* memset should be declared in <string.h> but isn't */ 566#endif /* SUNOS4 */ 567 568#if SYSVREL == 4 569# ifdef REMOTEHOST 570/* Irix6 defines getpeername(int, void *, int *) which conflicts with 571 the definition below. */ 572# if !defined(__sgi) && !defined(_OSD_POSIX) && !defined(__MVS__) 573# ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */ 574struct sockaddr; 575extern int getpeername (int, struct sockaddr *, int *); 576# endif /* _SOCKLEN_T */ 577# endif /* !__sgi && !_OSD_POSIX && !__MVS__ */ 578# endif /* REMOTEHOST */ 579# ifndef BSDTIMES 580extern int getrlimit (int, struct rlimit *); 581extern int setrlimit (int, const struct rlimit *); 582# endif /* !BSDTIMES */ 583# if defined(SOLARIS2) 584extern char *strerror (int); 585# endif /* SOLARIS2 */ 586#endif /* SYSVREL == 4 */ 587 588#if defined(__alpha) && defined(__osf__) && DECOSF1 < 200 589/* These are ok for 1.3, but conflict with the header files for 2.0 */ 590extern char *sbrk (ssize_t); 591extern int ioctl (int, unsigned long, char *); 592extern pid_t vfork (void); 593extern int killpg (pid_t, int); 594#endif /* __osf__ && __alpha && DECOSF1 < 200 */ 595 596#ifndef va_copy 597# ifdef __va_copy 598# define va_copy(DEST, SRC) __va_copy(DEST, SRC) 599# else 600# define va_copy(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(va_list)) 601# endif 602#endif 603 604#endif /* _h_tc_os */ 605