1 /* $Header: /p/tcsh/cvsroot/tcsh/tc.os.h,v 3.101 2006/02/14 00:52:52 christos Exp $ */
3 * tc.os.h: Shell os dependent defines
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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
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
47 # define NOFILE sysconf(_SC_OPEN_MAX)
54 # define nice(a) setprio((getpid()),a)
55 # include <sys/time.h> /* for time stuff in tc.prompt.c */
57 #endif /* atp vmsposix */
59 #if defined(DECOSF1) || defined(HPUXVERSION)
60 # include <sys/signal.h>
61 #endif /* DECOSF1 || HPUXVERSION */
64 # include <sys/ioctl.h>
67 #if defined(OPEN_MAX) && !defined(NOFILE)
68 # define NOFILE OPEN_MAX
69 #endif /* OPEN_MAX && !NOFILE */
71 #if defined(USR_NFDS) && !defined(NOFILE)
72 # define NOFILE USR_NFDS
73 #endif /* USR_NFDS && !NOFILE */
80 # include <sys/time.h>
82 /* Don't include it, because it defines things we don't really have */
83 # include <sys/resource.h>
92 # include <sys/dmon.h>
102 * Hpux defines struct ucred, in <sys/user.h>, but if I include that
103 * then I need to include the *world*
104 * [all this to pass lint cleanly!!!]
105 * so I define struct ucred here...
113 * hpux 7.0 does not define it
120 # if !defined(hp9000s500) && !(defined(SIGRTMAX) || defined(SIGRTMIN))
124 # include <sys/bsdtty.h>
125 # endif /* !hp9000s500 && !(SIGRTMAX || SIGRTMIN) */
128 # include <sys/strtio.h>
133 * ISC does not define CSUSP
139 # if defined(POSIX) && !defined(TIOCGWINSZ)
141 * ISC defines this only in termio.h. If we are using POSIX and include
142 * termios.h, then we define it ourselves so that window resizing works.
144 # define TIOCGWINSZ (('T'<<8)|104)
145 # endif /* POSIX && !TIOCGWINSZ */
153 * XXX: This will be changed soon to
154 * #if (SYSVREL > 0) && defined(TIOCGWINSZ)
155 * If that breaks on your machine, let me know.
157 * It would break on glibc, where all this is
158 * defined in <termios.h>. Wrapper added.
160 #if !defined(linux) && !defined(__GNU__) && !defined(__GLIBC__) && !defined(_VMS_POSIX)
161 # if defined(INTEL) || defined(u3b2) || defined (u3b5) || defined(ub15) || defined(u3b20d) || defined(ISC) || defined(SCO) || defined(tower32)
166 # include <sys/stream.h>
167 # include <sys/ptem.h>
168 # endif /* TIOCGWINSZ */
169 # endif /* INTEL || u3b2 || u3b5 || ub15 || u3b20d || ISC || SCO || tower32 */
170 #endif /* !glibc && !_VMS_POSIX */
173 # include <sys/time.h>
174 # include <sys/resource.h>
178 * For some versions of system V software, specially ones that use the
179 * Wollongong Software TCP/IP, the FIOCLEX, FIONCLEX, FIONBIO calls
180 * might not work correctly for file descriptors [they work only for
181 * sockets]. So we try to use first the fcntl() and we only use the
182 * ioctl() form, only if we don't have the fcntl() one.
184 * From: scott@craycos.com (Scott Bolte)
189 # define FD_CLOEXEC 1
191 # define close_on_exec(fd, v) fcntl((fd), F_SETFD, ((v) ? FD_CLOEXEC : 0))
192 # else /* !F_SETFD */
194 # define close_on_exec(fd, v) ioctl((fd), ((v) ? FIOCLEX : FIONCLEX), NULL)
195 # else /* !FIOCLEX */
196 # define close_on_exec(fd, v) /* Nothing */
197 # endif /* FIOCLEX */
198 # endif /* F_SETFD */
199 #else /* WINNT_NATIVE */
200 # define close_on_exec(fd, v) nt_close_on_exec((fd),(v))
201 #endif /* !WINNT_NATIVE */
207 /* these are not defined for _POSIX_SOURCE under ISC 2.2 */
209 # define S_IFMT 0170000 /* type of file */
210 # define S_IFDIR 0040000 /* directory */
211 # define S_IFCHR 0020000 /* character special */
212 # define S_IFBLK 0060000 /* block special */
213 # define S_IFREG 0100000 /* regular */
214 # define S_IFIFO 0010000 /* fifo */
215 # define S_IFNAM 0050000 /* special named file */
217 # define S_IFLNK 0120000 /* symbolic link */
222 #ifdef STAT_MACROS_BROKEN
231 #endif /* STAT_MACROS_BROKEN */
234 # if !defined(S_ISDIR) && defined(S_IFDIR)
235 # define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR)
236 # endif /* ! S_ISDIR && S_IFDIR */
237 # if !defined(S_ISCHR) && defined(S_IFCHR)
238 # define S_ISCHR(a) (((a) & S_IFMT) == S_IFCHR)
239 # endif /* ! S_ISCHR && S_IFCHR */
240 # if !defined(S_ISBLK) && defined(S_IFBLK)
241 # define S_ISBLK(a) (((a) & S_IFMT) == S_IFBLK)
242 # endif /* ! S_ISBLK && S_IFBLK */
243 # if !defined(S_ISREG) && defined(S_IFREG)
244 # define S_ISREG(a) (((a) & S_IFMT) == S_IFREG)
245 # endif /* ! S_ISREG && S_IFREG */
246 # if !defined(S_ISFIFO) && defined(S_IFIFO)
247 # define S_ISFIFO(a) (((a) & S_IFMT) == S_IFIFO)
248 # endif /* ! S_ISFIFO && S_IFIFO */
249 # if !defined(S_ISNAM) && defined(S_IFNAM)
250 # define S_ISNAM(a) (((a) & S_IFMT) == S_IFNAM)
251 # endif /* ! S_ISNAM && S_IFNAM */
252 # if !defined(S_ISLNK) && defined(S_IFLNK)
253 # define S_ISLNK(a) (((a) & S_IFMT) == S_IFLNK)
254 # endif /* ! S_ISLNK && S_IFLNK */
255 # if !defined(S_ISSOCK) && defined(S_IFSOCK)
256 # define S_ISSOCK(a) (((a) & S_IFMT) == S_IFSOCK)
257 # endif /* ! S_ISSOCK && S_IFSOCK */
261 /* The header files lie; we really don't have symlinks */
267 # define S_IREAD 0000400
270 # define S_IROTH (S_IREAD >> 6)
273 # define S_IRGRP (S_IREAD >> 3)
276 # define S_IRUSR S_IREAD
280 # define S_IWRITE 0000200
281 #endif /* S_IWRITE */
283 # define S_IWOTH (S_IWRITE >> 6)
286 # define S_IWGRP (S_IWRITE >> 3)
289 # define S_IWUSR S_IWRITE
293 # define S_IEXEC 0000100
296 # define S_IXOTH (S_IEXEC >> 6)
299 # define S_IXGRP (S_IEXEC >> 3)
302 # define S_IXUSR S_IEXEC
306 # define S_ISUID 0004000 /* setuid */
309 # define S_ISGID 0002000 /* setgid */
312 # define S_ISVTX 0001000 /* sticky */
315 # define S_ENFMT S_ISGID /* record locking enforcement flag */
318 /* the following macros are for POSIX conformance */
320 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
323 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
326 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
350 #endif /* O_RDONLY */
353 #endif /* O_WRONLY */
363 # define L_SET SEEK_SET
364 # else /* !SEEK_SET */
366 # endif /* SEEK_SET */
370 # define L_INCR SEEK_CUR
371 # else /* !SEEK_CUR */
373 # endif /* SEEK_CUR */
377 # define L_XTND SEEK_END
378 # else /* !SEEK_END */
380 # endif /* SEEK_END */
383 #if !defined (HAVE_SETPGID) && !defined (SETPGRP_VOID)
384 # define setpgid(pid, pgrp) setpgrp(pid, pgrp)
387 #if defined(BSDJOBS) && !(defined(POSIX) && defined(POSIXJOBS))
388 # define NEEDtcgetpgrp
389 #endif /* BSDJOBS && !(POSIX && POSIXJOBS) */
393 * RENO has this broken. It is fixed on 4.4BSD
395 # define NEEDtcgetpgrp
401 * Only needed in the system V environment.
403 # define setrlimit bsd_setrlimit
404 # define getrlimit bsd_getrlimit
408 #if defined(_MINIX) || defined(__EMX__)
411 * Minix does not have these, so...
413 # define getpgrp getpid
414 #endif /* _MINIX || __EMX__ */
417 /* XXX: How can we get the tty name in emx? */
418 # define ttyname(fd) (isatty(fd) ? "/dev/tty" : NULL)
426 #if defined(BSDTIMES) && !defined(_SEQUENT_)
427 typedef struct timeval timeval_t
;
428 #endif /* BSDTIMES && ! _SEQUENT_ */
432 * From Tony_Mason@transarc.com, override NeXT's malloc stuff.
434 # define malloc tcsh_malloc
435 # define calloc tcsh_calloc
436 # define realloc tcsh_realloc
437 # define free tcsh_free
440 #if defined(HAVE_GETHOSTNAME) && !HAVE_DECL_GETHOSTNAME
441 extern int gethostname (char *, int);
445 # define mygetpgrp() getpgrp(0)
447 # define mygetpgrp() getpgrp()
450 #if !defined(POSIX) || defined(SUNOS4) || defined(UTekV) || defined(sysV88)
451 extern time_t time();
452 extern char *getenv();
455 extern char *ttyname();
456 # endif /* __EMX__ */
461 extern int toupper (int);
462 # endif /* toupper */
464 extern int tolower (int);
465 # endif /* tolower */
466 extern caddr_t
sbrk (int);
468 # ifndef WINNT_NATIVE
473 # endif /* !WINNT_NATIVE */
476 extern void perror();
480 extern uid_t
getuid(), geteuid();
481 extern gid_t
getgid(), getegid();
485 extern memalign_t
malloc();
486 extern memalign_t
realloc();
487 extern memalign_t
calloc();
489 # endif /* SYSMALLOC */
494 extern pid_t
wait3();
495 # endif /* __MACHTEN__ */
496 # endif /* BSDTIMES */
497 # endif /* BSDJOBS */
499 # if (!defined(fps500) && !defined(apollo) && !defined(__lucid) && !defined(HPBSD) && !defined(DECOSF1))
500 extern void setpwent();
501 extern void endpwent();
502 # endif /* !fps500 && !apollo && !__lucid && !HPBSD && !DECOSF1 */
505 extern struct passwd
*getpwuid(), *getpwnam(), *getpwent();
506 # ifdef HAVE_SHADOW_H
507 extern struct spwd
*getspnam(), *getspent();
508 # endif /* HAVE_SHADOW_H */
509 # if defined(HAVE_AUTH_H) && defined(HAVE_GETAUTHUID)
510 extern struct authorization
*getauthuid();
511 # endif /* HAVE_AUTH_H && HAVE_GETAUTHUID */
512 # endif /* __STDC__ */
515 extern char *getcwd();
518 #else /* POSIX || !SUNOS4 || !UTekV || !sysV88 */
520 # if (defined(SUNOS4) && !defined(__GNUC__)) || defined(_IBMR2) || defined(_IBMESA)
521 extern char *getvwd();
522 # endif /* (SUNOS4 && ! __GNUC__) || _IBMR2 || _IBMESA */
525 extern char *ttyname();
529 extern char *ttyname();
530 # endif /* __clipper__ */
532 #endif /* !POSIX || SUNOS4 || UTekV || sysV88 */
534 #if defined(SUNOS4) && __GNUC__ == 2
536 * Somehow these are missing
538 extern int ioctl (int, int, ...);
539 extern int readlink (const char *, char *, size_t);
540 extern void setgrent (void);
541 extern void endgrent (void);
543 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
545 extern int getpeername (int, struct sockaddr
*, int *);
546 # endif /* _SOCKLEN_T */
547 # endif /* REMOTEHOST */
548 #endif /* SUNOS4 && __GNUC__ == 2 */
550 #if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4)
551 # if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
552 extern void bcopy (const void *, void *, size_t);
553 # define memmove(a, b, c) (bcopy((char *) (b), (char *) (a), (int) (c)), a)
554 # endif /* __alpha && __osf__ && DECOSF1 < 200 */
555 #endif /* (BSD && !BSD4_4) || SUNOS4 */
558 # include <memory.h> /* memset should be declared in <string.h> but isn't */
563 /* Irix6 defines getpeername(int, void *, int *) which conflicts with
564 the definition below. */
565 # if !defined(__sgi) && !defined(_OSD_POSIX) && !defined(__MVS__)
566 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
568 extern int getpeername (int, struct sockaddr
*, int *);
569 # endif /* _SOCKLEN_T */
570 # endif /* !__sgi && !_OSD_POSIX && !__MVS__ */
571 # endif /* REMOTEHOST */
573 extern int getrlimit (int, struct rlimit
*);
574 extern int setrlimit (int, const struct rlimit
*);
575 # endif /* !BSDTIMES */
576 # if defined(SOLARIS2)
577 extern char *strerror (int);
578 # endif /* SOLARIS2 */
579 #endif /* SYSVREL == 4 */
581 #if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
582 /* These are ok for 1.3, but conflict with the header files for 2.0 */
583 extern char *sbrk (ssize_t
);
584 extern int ioctl (int, unsigned long, char *);
585 extern pid_t
vfork (void);
586 extern int killpg (pid_t
, int);
587 #endif /* __osf__ && __alpha && DECOSF1 < 200 */
591 # define va_copy(DEST, SRC) __va_copy(DEST, SRC)
593 # define va_copy(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(va_list))
597 #endif /* _h_tc_os */