1 /* $Header: /src/pub/tcsh/tc.os.h,v 3.88 2002/05/16 13:51:26 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
37 #define NEEDstrerror /* Too hard to find which systems have it */
38 #endif /* WINNT_NATIVE */
43 * for SVR4 and linux we used to fork pipelines backwards.
44 * This should not be needed any more.
45 * more info in sh.sem.c
58 # define nice(a) setprio((getpid()),a)
59 # undef NEEDstrerror /* won't get sensible error messages otherwise */
60 # define NEEDgethostname
61 # include <sys/time.h> /* for time stuff in tc.prompt.c */
63 #endif /* atp vmsposix */
65 #if defined(DECOSF1) || defined(HPUXVERSION)
66 # include <sys/signal.h>
67 #endif /* DECOSF1 || HPUXVERSION */
70 # include <sys/ioctl.h>
73 #if defined(OPEN_MAX) && !defined(NOFILE)
74 # define NOFILE OPEN_MAX
75 #endif /* OPEN_MAX && !NOFILE */
77 #if defined(USR_NFDS) && !defined(NOFILE)
78 # define NOFILE USR_NFDS
79 #endif /* USR_NFDS && !NOFILE */
85 #if defined(linux) || defined(__NetBSD__) || defined(__FreeBSD__) || SYSVREL >= 4 || defined(_MINIX_VMD)
87 #endif /* linux || __NetBSD__ || __FreeBSD__ || SYSVREL >= 4 || _MINIX_VMD */
89 #if !defined(pyr) && !defined(sinix)
90 /* Pyramid's cpp complains about the next line */
91 # if defined(BSD) && BSD >= 199306
93 # endif /* BSD && BSD >= 199306 */
97 # include <sys/time.h>
99 /* Don't include it, because it defines things we don't really have */
100 # include <sys/resource.h>
103 # include <sys/tty.h>
104 # include <termios.h>
110 # define NCARGS sysconf(_SC_ARG_MAX)
111 # else /* !_SC_ARG_MAX */
113 # define NCARGS ARG_MAX
114 # else /* !ARG_MAX */
120 # endif /* ARG_MAX */
121 # endif /* _SC_ARG_MAX */
125 # include <sys/dmon.h>
135 * Hpux defines struct ucred, in <sys/user.h>, but if I include that
136 * then I need to include the *world*
137 * [all this to pass lint cleanly!!!]
138 * so I define struct ucred here...
146 * hpux 7.0 does not define it
153 # if !defined(hp9000s500) && !(defined(SIGRTMAX) || defined(SIGRTMIN))
157 # include <sys/bsdtty.h>
158 # endif /* !hp9000s500 && !(SIGRTMAX || SIGRTMIN) */
162 # define getpgrp(a) getpgrp2(a)
163 # define setpgrp(a, b) setpgrp2(a, b)
164 # endif /* BSDJOBS */
167 # include <sys/strtio.h>
172 * ISC does not define CSUSP
178 # if defined(POSIX) && !defined(TIOCGWINSZ)
180 * ISC defines this only in termio.h. If we are using POSIX and include
181 * termios.h, then we define it ourselves so that window resizing works.
183 # define TIOCGWINSZ (('T'<<8)|104)
184 # endif /* POSIX && !TIOCGWINSZ */
192 * XXX: This will be changed soon to
193 * #if (SYSVREL > 0) && defined(TIOCGWINSZ)
194 * If that breaks on your machine, let me know.
196 * It would break on linux, where all this is
197 * defined in <termios.h>. Wrapper added.
199 #if !defined(linux) && !defined(_VMS_POSIX)
200 # if defined(INTEL) || defined(u3b2) || defined (u3b5) || defined(ub15) || defined(u3b20d) || defined(ISC) || defined(SCO) || defined(tower32)
205 # include <sys/stream.h>
206 # include <sys/ptem.h>
207 # endif /* TIOCGWINSZ */
209 # define NEEDgethostname
211 # endif /* INTEL || u3b2 || u3b5 || ub15 || u3b20d || ISC || SCO || tower32 */
212 #endif /* !linux && !_VMS_POSIX */
214 #if defined(UNIXPC) || defined(COHERENT)
215 # define NEEDgethostname
216 #endif /* UNIXPC || COHERENT */
219 # include <sys/time.h>
220 # include <sys/resource.h>
223 * BSDsetpgrp() and BSDgetpgrp() are BSD versions of setpgrp, etc.
225 # define setpgrp BSDsetpgrp
226 # define getpgrp BSDgetpgrp
231 * For some versions of system V software, specially ones that use the
232 * Wollongong Software TCP/IP, the FIOCLEX, FIONCLEX, FIONBIO calls
233 * might not work correctly for file descriptors [they work only for
234 * sockets]. So we try to use first the fcntl() and we only use the
235 * ioctl() form, only if we don't have the fcntl() one.
237 * From: scott@craycos.com (Scott Bolte)
241 # define close_on_exec(fd, v) fcntl((fd), F_SETFD, v)
242 # else /* !F_SETFD */
244 # define close_on_exec(fd, v) ioctl((fd), ((v) ? FIOCLEX : FIONCLEX), NULL)
245 # else /* !FIOCLEX */
246 # define close_on_exec(fd, v) /* Nothing */
247 # endif /* FIOCLEX */
248 # endif /* F_SETFD */
249 #else /* WINNT_NATIVE */
250 # define close_on_exec(fd, v) nt_close_on_exec((fd),(v))
251 #endif /* !WINNT_NATIVE */
257 /* these are not defined for _POSIX_SOURCE under ISC 2.2 */
259 # define S_IFMT 0170000 /* type of file */
260 # define S_IFDIR 0040000 /* directory */
261 # define S_IFCHR 0020000 /* character special */
262 # define S_IFBLK 0060000 /* block special */
263 # define S_IFREG 0100000 /* regular */
264 # define S_IFIFO 0010000 /* fifo */
265 # define S_IFNAM 0050000 /* special named file */
267 # define S_IFLNK 0120000 /* symbolic link */
272 #if defined(uts) || defined(UTekV) || defined(sysV88)
274 * The uts 2.1.2 macros (Amdahl) are busted!
275 * You should fix <sys/stat.h>, cause other programs will break too!
277 * From: creiman@ncsa.uiuc.edu (Charlie Reiman)
281 * The same applies to Motorola MPC (System V/88 R32V2, UTekV 3.2e)
282 * workstations, the stat macros are broken.
283 * Kaveh Ghazi (ghazi@caip.rutgers.edu)
293 #endif /* uts || UTekV || sysV88 */
296 # if !defined(S_ISDIR) && defined(S_IFDIR)
297 # define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR)
298 # endif /* ! S_ISDIR && S_IFDIR */
299 # if !defined(S_ISCHR) && defined(S_IFCHR)
300 # define S_ISCHR(a) (((a) & S_IFMT) == S_IFCHR)
301 # endif /* ! S_ISCHR && S_IFCHR */
302 # if !defined(S_ISBLK) && defined(S_IFBLK)
303 # define S_ISBLK(a) (((a) & S_IFMT) == S_IFBLK)
304 # endif /* ! S_ISBLK && S_IFBLK */
305 # if !defined(S_ISREG) && defined(S_IFREG)
306 # define S_ISREG(a) (((a) & S_IFMT) == S_IFREG)
307 # endif /* ! S_ISREG && S_IFREG */
308 # if !defined(S_ISFIFO) && defined(S_IFIFO)
309 # define S_ISFIFO(a) (((a) & S_IFMT) == S_IFIFO)
310 # endif /* ! S_ISFIFO && S_IFIFO */
311 # if !defined(S_ISNAM) && defined(S_IFNAM)
312 # define S_ISNAM(a) (((a) & S_IFMT) == S_IFNAM)
313 # endif /* ! S_ISNAM && S_IFNAM */
314 # if !defined(S_ISLNK) && defined(S_IFLNK)
315 # define S_ISLNK(a) (((a) & S_IFMT) == S_IFLNK)
316 # endif /* ! S_ISLNK && S_IFLNK */
317 # if !defined(S_ISSOCK) && defined(S_IFSOCK)
318 # define S_ISSOCK(a) (((a) & S_IFMT) == S_IFSOCK)
319 # endif /* ! S_ISSOCK && S_IFSOCK */
323 /* The header files lie; we really don't have symlinks */
329 # define S_IREAD 0000400
332 # define S_IROTH (S_IREAD >> 6)
335 # define S_IRGRP (S_IREAD >> 3)
338 # define S_IRUSR S_IREAD
342 # define S_IWRITE 0000200
343 #endif /* S_IWRITE */
345 # define S_IWOTH (S_IWRITE >> 6)
348 # define S_IWGRP (S_IWRITE >> 3)
351 # define S_IWUSR S_IWRITE
355 # define S_IEXEC 0000100
358 # define S_IXOTH (S_IEXEC >> 6)
361 # define S_IXGRP (S_IEXEC >> 3)
364 # define S_IXUSR S_IEXEC
368 # define S_ISUID 0004000 /* setuid */
371 # define S_ISGID 0002000 /* setgid */
374 # define S_ISVTX 0001000 /* sticky */
377 # define S_ENFMT S_ISGID /* record locking enforcement flag */
380 /* the following macros are for POSIX conformance */
382 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
385 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
388 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
412 #endif /* O_RDONLY */
415 #endif /* O_WRONLY */
425 # define L_SET SEEK_SET
426 # else /* !SEEK_SET */
428 # endif /* SEEK_SET */
432 # define L_INCR SEEK_CUR
433 # else /* !SEEK_CUR */
435 # endif /* SEEK_CUR */
439 # define L_XTND SEEK_END
440 # else /* !SEEK_END */
442 # endif /* SEEK_END */
446 # define NEEDgethostname
447 #endif /* _SEQUENT_ */
449 #if defined(BSD) && defined(POSIXJOBS) && !defined(BSD4_4) && !defined(__hp_osf)
450 # define setpgid(pid, pgrp) setpgrp(pid, pgrp)
451 #endif /* BSD && POSIXJOBS && && !BSD4_4 && !__hp_osf */
453 #if defined(BSDJOBS) && !(defined(POSIX) && defined(POSIXJOBS))
454 # if !defined(_AIX370) && !defined(_AIXPS2)
455 # define setpgid(pid, pgrp) setpgrp(pid, pgrp)
456 # endif /* !_AIX370 && !_AIXPS2 */
457 # define NEEDtcgetpgrp
458 #endif /* BSDJOBS && !(POSIX && POSIXJOBS) */
462 * RENO has this broken. It is fixed on 4.4BSD
464 # define NEEDtcgetpgrp
468 # define setpgrp(a, b) setpgrp2(a, b)
469 # define getpgrp(a) getpgrp2(a)
475 * Only needed in the system V environment.
477 # define setrlimit bsd_setrlimit
478 # define getrlimit bsd_getrlimit
482 #if defined(_MINIX) || defined(__EMX__)
483 # define NEEDgethostname
487 * Minix does not have these, so...
489 # define getpgrp getpid
490 #endif /* _MINIX || __EMX__ */
493 /* XXX: How can we get the tty name in emx? */
494 # define ttyname(fd) (isatty(fd) ? "/dev/tty" : NULL)
498 # define mygetpgrp() getpgrp(0)
500 # if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4) || defined(IRIS4D) || defined(DGUX) || defined(HPRT)
501 # define mygetpgrp() getpgrp(0)
502 # else /* !((BSD && !BSD4_4) || SUNOS4 || IRIS4D || DGUX || HPRT) */
503 # define mygetpgrp() getpgrp()
504 # endif /* (BSD && BSD4_4) || SUNOS4 || IRISD || DGUX || HPRT */
508 #if !defined(SOLARIS2) && !defined(sinix) && !defined(BSD4_4) && !defined(WINNT_NATIVE)
509 # if (SYSVREL > 0 && !defined(OREO) && !defined(sgi) && !defined(linux) && !defined(sinix) && !defined(_AIX) &&!defined(_UWIN)) || defined(NeXT)
511 # endif /* (SYSVREL > 0 && !OREO && !sgi && !linux && !sinix && !_AIX && !_UWIN) || NeXT */
519 #if defined(BSDTIMES) && !defined(_SEQUENT_)
520 typedef struct timeval timeval_t
;
521 #endif /* BSDTIMES && ! _SEQUENT_ */
525 * From Tony_Mason@transarc.com, override NeXT's malloc stuff.
527 # define malloc tcsh_malloc
528 # define calloc tcsh_calloc
529 # define realloc tcsh_realloc
530 # define free tcsh_free
533 #if !defined(BSD4_4) && !defined(__linux__) && !defined(__hpux) && \
534 !defined(sgi) && !defined(_AIX) && !defined(__CYGWIN__)
535 #ifndef NEEDgethostname
536 extern int gethostname
__P((char *, int));
537 #endif /* NEEDgethostname */
538 #endif /* !BDS4_4 && !__linux__ && !__hpux && !sgi */
540 #if !defined(POSIX) || defined(SUNOS4) || defined(UTekV) || defined(sysV88)
541 extern time_t time();
542 extern char *getenv();
545 extern char *ttyname();
546 # endif /* __EMX__ */
550 extern int toupper
__P((int));
551 # endif /* toupper */
553 extern int tolower
__P((int));
554 # endif /* tolower */
555 extern caddr_t sbrk
__P((int));
556 # if SYSVREL == 0 && !defined(__lucid)
558 # endif /* SYSVREL == 0 && !__lucid */
560 # ifndef WINNT_NATIVE
564 # endif /* __GNUC__ != 2 */
567 # endif /* !fps500 */
572 # endif /* !WINNT_NATIVE */
575 extern void perror();
579 # if defined(_AIX370) || defined(MACH) || defined(NeXT) || defined(_AIXPS2) || defined(ardent) || defined(SUNOS4) || defined(HPBSD) || defined(__MACHTEN__)
581 extern int sigpause();
582 # else /* !(_AIX370 || MACH || NeXT || _AIXPS2 || ardent || SUNOS4 || HPBSD) */
583 # if (!defined(apollo) || !defined(__STDC__)) && !defined(__DGUX__) && !defined(fps500)
584 extern sigret_t
sigvec();
586 extern void sigpause();
588 # endif /* (!apollo || !__STDC__) && !__DGUX__ && !fps500 */
589 # endif /* _AIX370 || MACH || NeXT || _AIXPS2 || ardent || SUNOS4 || HPBSD */
590 extern sigmask_t
sigblock();
591 extern sigmask_t
sigsetmask();
592 # endif /* BSDSIGS */
603 extern uid_t
getuid(), geteuid();
604 extern gid_t
getgid(), getegid();
608 extern memalign_t
malloc();
609 extern memalign_t
realloc();
610 extern memalign_t
calloc();
612 # endif /* SYSMALLOC */
615 extern int getrlimit();
616 extern int setrlimit();
617 extern int getrusage();
618 extern int gettimeofday();
619 # endif /* BSDTIMES */
621 # if defined(NLS) && !defined(NOSTRCOLL) && !defined(NeXT)
622 extern int strcoll();
623 # endif /* NLS && !NOSTRCOLL && !NeXT */
628 extern pid_t
wait3();
633 # endif /* __MACHTEN__ */
634 # else /* !BSDTIMES */
635 # if !defined(POSIXJOBS) && !defined(_SEQUENT_)
637 # else /* POSIXJOBS || _SEQUENT_ */
638 extern int waitpid();
639 # endif /* POSIXJOBS || _SEQUENT_ */
640 # endif /* BSDTIMES */
641 # else /* !BSDJOBS */
643 extern int ourwait();
644 # else /* SYSVREL >= 3 */
646 # endif /* SYSVREL < 3 */
647 # endif /* BSDJOBS */
650 extern int setpriority();
651 # else /* !BSDNICE */
653 # endif /* BSDNICE */
655 # if (!defined(fps500) && !defined(apollo) && !defined(__lucid) && !defined(HPBSD) && !defined(DECOSF1))
656 extern void setpwent();
657 extern void endpwent();
658 # endif /* !fps500 && !apollo && !__lucid && !HPBSD && !DECOSF1 */
661 extern struct passwd
*getpwuid(), *getpwnam(), *getpwent();
663 extern struct spwd
*getspnam(), *getspent();
664 # endif /* PW_SHADOW */
666 extern struct authorization
*getauthuid();
667 # endif /* PW_AUTH */
668 # endif /* __STDC__ */
671 extern char *getcwd();
674 #else /* POSIX || !SUNOS4 || !UTekV || !sysV88 */
676 # if (defined(SUNOS4) && !defined(__GNUC__)) || defined(_IBMR2) || defined(_IBMESA)
677 extern char *getvwd();
678 # endif /* (SUNOS4 && ! __GNUC__) || _IBMR2 || _IBMESA */
681 extern char *ttyname();
685 extern char *ttyname();
686 # endif /* __clipper__ */
688 #endif /* !POSIX || SUNOS4 || UTekV || sysV88 */
690 #if defined(SUNOS4) && __GNUC__ == 2
692 * Somehow these are missing
694 extern int ioctl
__P((int, int, ...));
695 extern int readlink
__P((const char *, char *, size_t));
696 extern void setgrent
__P((void));
697 extern void endgrent
__P((void));
699 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
701 extern int getpeername
__P((int, struct sockaddr
*, int *));
702 # endif /* _SOCKLEN_T */
703 # endif /* REMOTEHOST */
704 #endif /* SUNOS4 && __GNUC__ == 2 */
706 #if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4)
707 # if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
708 extern void bcopy
__P((const void *, void *, size_t));
709 # define memmove(a, b, c) (bcopy((char *) (b), (char *) (a), (int) (c)), a)
710 # endif /* __alpha && __osf__ && DECOSF1 < 200 */
711 #endif /* (BSD && !BSD4_4) || SUNOS4 */
713 #if !defined(hpux) && !defined(COHERENT) && ((SYSVREL < 4) || defined(_SEQUENT_)) && !defined(BSD4_4) && !defined(memmove)
715 #endif /* !hpux && !COHERENT && (SYSVREL < 4 || _SEQUENT_) && !BSD4_4 && !memmove */
717 #if defined(UTek) || defined(pyr)
719 #else /* !UTek && !pyr */
721 # include <memory.h> /* memset should be declared in <string.h> but isn't */
723 #endif /* UTek || pyr */
727 /* Irix6 defines getpeername(int, void *, int *) which conflicts with
728 the definition below. */
729 # if !defined(__sgi) && !defined(_OSD_POSIX) && !defined(__MVS__)
730 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
732 extern int getpeername
__P((int, struct sockaddr
*, int *));
733 # endif /* _SOCKLEN_T */
734 # endif /* !__sgi && !_OSD_POSIX && !__MVS__ */
735 # endif /* REMOTEHOST */
737 extern int getrlimit
__P((int, struct rlimit
*));
738 extern int setrlimit
__P((int, const struct rlimit
*));
739 # endif /* !BSDTIMES */
740 # if !defined(IRIS4D) && !defined(SOLARIS2)
741 extern int wait3(); /* I think some bizarre systems still need this */
742 # endif /* !IRIS4D && !SOLARIS2 */
743 # if defined(SOLARIS2)
745 extern char *strerror
__P((int));
746 # endif /* SOLARIS2 */
747 #endif /* SYSVREL == 4 */
749 #if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
750 /* These are ok for 1.3, but conflict with the header files for 2.0 */
751 extern int gethostname
__P((char *, int));
752 extern char *sbrk
__P((ssize_t
));
753 extern int ioctl
__P((int, unsigned long, char *));
754 extern pid_t vfork
__P((void));
755 extern int killpg
__P((pid_t
, int));
756 #endif /* __osf__ && __alpha && DECOSF1 < 200 */
758 #endif /* _h_tc_os */