1 /* $Header: /src/pub/tcsh/tc.os.h,v 3.97 2005/03/03 22:32:01 kim 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>
93 # define NCARGS sysconf(_SC_ARG_MAX)
94 # else /* !_SC_ARG_MAX */
96 # define NCARGS ARG_MAX
103 # endif /* ARG_MAX */
104 # endif /* _SC_ARG_MAX */
108 # include <sys/dmon.h>
118 * Hpux defines struct ucred, in <sys/user.h>, but if I include that
119 * then I need to include the *world*
120 * [all this to pass lint cleanly!!!]
121 * so I define struct ucred here...
129 * hpux 7.0 does not define it
136 # if !defined(hp9000s500) && !(defined(SIGRTMAX) || defined(SIGRTMIN))
140 # include <sys/bsdtty.h>
141 # endif /* !hp9000s500 && !(SIGRTMAX || SIGRTMIN) */
144 # include <sys/strtio.h>
149 * ISC does not define CSUSP
155 # if defined(POSIX) && !defined(TIOCGWINSZ)
157 * ISC defines this only in termio.h. If we are using POSIX and include
158 * termios.h, then we define it ourselves so that window resizing works.
160 # define TIOCGWINSZ (('T'<<8)|104)
161 # endif /* POSIX && !TIOCGWINSZ */
169 * XXX: This will be changed soon to
170 * #if (SYSVREL > 0) && defined(TIOCGWINSZ)
171 * If that breaks on your machine, let me know.
173 * It would break on glibc, where all this is
174 * defined in <termios.h>. Wrapper added.
176 #if !defined(linux) && !defined(__GNU__) && !defined(__GLIBC__) && !defined(_VMS_POSIX)
177 # if defined(INTEL) || defined(u3b2) || defined (u3b5) || defined(ub15) || defined(u3b20d) || defined(ISC) || defined(SCO) || defined(tower32)
182 # include <sys/stream.h>
183 # include <sys/ptem.h>
184 # endif /* TIOCGWINSZ */
185 # endif /* INTEL || u3b2 || u3b5 || ub15 || u3b20d || ISC || SCO || tower32 */
186 #endif /* !glibc && !_VMS_POSIX */
189 # include <sys/time.h>
190 # include <sys/resource.h>
194 * For some versions of system V software, specially ones that use the
195 * Wollongong Software TCP/IP, the FIOCLEX, FIONCLEX, FIONBIO calls
196 * might not work correctly for file descriptors [they work only for
197 * sockets]. So we try to use first the fcntl() and we only use the
198 * ioctl() form, only if we don't have the fcntl() one.
200 * From: scott@craycos.com (Scott Bolte)
205 # define FD_CLOEXEC 1
207 # define close_on_exec(fd, v) fcntl((fd), F_SETFD, ((v) ? FD_CLOEXEC : 0))
208 # else /* !F_SETFD */
210 # define close_on_exec(fd, v) ioctl((fd), ((v) ? FIOCLEX : FIONCLEX), NULL)
211 # else /* !FIOCLEX */
212 # define close_on_exec(fd, v) /* Nothing */
213 # endif /* FIOCLEX */
214 # endif /* F_SETFD */
215 #else /* WINNT_NATIVE */
216 # define close_on_exec(fd, v) nt_close_on_exec((fd),(v))
217 #endif /* !WINNT_NATIVE */
223 /* these are not defined for _POSIX_SOURCE under ISC 2.2 */
225 # define S_IFMT 0170000 /* type of file */
226 # define S_IFDIR 0040000 /* directory */
227 # define S_IFCHR 0020000 /* character special */
228 # define S_IFBLK 0060000 /* block special */
229 # define S_IFREG 0100000 /* regular */
230 # define S_IFIFO 0010000 /* fifo */
231 # define S_IFNAM 0050000 /* special named file */
233 # define S_IFLNK 0120000 /* symbolic link */
238 #ifdef STAT_MACROS_BROKEN
247 #endif /* STAT_MACROS_BROKEN */
250 # if !defined(S_ISDIR) && defined(S_IFDIR)
251 # define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR)
252 # endif /* ! S_ISDIR && S_IFDIR */
253 # if !defined(S_ISCHR) && defined(S_IFCHR)
254 # define S_ISCHR(a) (((a) & S_IFMT) == S_IFCHR)
255 # endif /* ! S_ISCHR && S_IFCHR */
256 # if !defined(S_ISBLK) && defined(S_IFBLK)
257 # define S_ISBLK(a) (((a) & S_IFMT) == S_IFBLK)
258 # endif /* ! S_ISBLK && S_IFBLK */
259 # if !defined(S_ISREG) && defined(S_IFREG)
260 # define S_ISREG(a) (((a) & S_IFMT) == S_IFREG)
261 # endif /* ! S_ISREG && S_IFREG */
262 # if !defined(S_ISFIFO) && defined(S_IFIFO)
263 # define S_ISFIFO(a) (((a) & S_IFMT) == S_IFIFO)
264 # endif /* ! S_ISFIFO && S_IFIFO */
265 # if !defined(S_ISNAM) && defined(S_IFNAM)
266 # define S_ISNAM(a) (((a) & S_IFMT) == S_IFNAM)
267 # endif /* ! S_ISNAM && S_IFNAM */
268 # if !defined(S_ISLNK) && defined(S_IFLNK)
269 # define S_ISLNK(a) (((a) & S_IFMT) == S_IFLNK)
270 # endif /* ! S_ISLNK && S_IFLNK */
271 # if !defined(S_ISSOCK) && defined(S_IFSOCK)
272 # define S_ISSOCK(a) (((a) & S_IFMT) == S_IFSOCK)
273 # endif /* ! S_ISSOCK && S_IFSOCK */
277 /* The header files lie; we really don't have symlinks */
283 # define S_IREAD 0000400
286 # define S_IROTH (S_IREAD >> 6)
289 # define S_IRGRP (S_IREAD >> 3)
292 # define S_IRUSR S_IREAD
296 # define S_IWRITE 0000200
297 #endif /* S_IWRITE */
299 # define S_IWOTH (S_IWRITE >> 6)
302 # define S_IWGRP (S_IWRITE >> 3)
305 # define S_IWUSR S_IWRITE
309 # define S_IEXEC 0000100
312 # define S_IXOTH (S_IEXEC >> 6)
315 # define S_IXGRP (S_IEXEC >> 3)
318 # define S_IXUSR S_IEXEC
322 # define S_ISUID 0004000 /* setuid */
325 # define S_ISGID 0002000 /* setgid */
328 # define S_ISVTX 0001000 /* sticky */
331 # define S_ENFMT S_ISGID /* record locking enforcement flag */
334 /* the following macros are for POSIX conformance */
336 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
339 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
342 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
366 #endif /* O_RDONLY */
369 #endif /* O_WRONLY */
379 # define L_SET SEEK_SET
380 # else /* !SEEK_SET */
382 # endif /* SEEK_SET */
386 # define L_INCR SEEK_CUR
387 # else /* !SEEK_CUR */
389 # endif /* SEEK_CUR */
393 # define L_XTND SEEK_END
394 # else /* !SEEK_END */
396 # endif /* SEEK_END */
399 #if !defined (HAVE_SETPGID) && !defined (SETPGRP_VOID)
400 # define setpgid(pid, pgrp) setpgrp(pid, pgrp)
403 #if defined(BSDJOBS) && !(defined(POSIX) && defined(POSIXJOBS))
404 # define NEEDtcgetpgrp
405 #endif /* BSDJOBS && !(POSIX && POSIXJOBS) */
409 * RENO has this broken. It is fixed on 4.4BSD
411 # define NEEDtcgetpgrp
417 * Only needed in the system V environment.
419 # define setrlimit bsd_setrlimit
420 # define getrlimit bsd_getrlimit
424 #if defined(_MINIX) || defined(__EMX__)
427 * Minix does not have these, so...
429 # define getpgrp getpid
430 #endif /* _MINIX || __EMX__ */
433 /* XXX: How can we get the tty name in emx? */
434 # define ttyname(fd) (isatty(fd) ? "/dev/tty" : NULL)
442 #if defined(BSDTIMES) && !defined(_SEQUENT_)
443 typedef struct timeval timeval_t;
444 #endif /* BSDTIMES && ! _SEQUENT_ */
448 * From Tony_Mason@transarc.com, override NeXT's malloc stuff.
450 # define malloc tcsh_malloc
451 # define calloc tcsh_calloc
452 # define realloc tcsh_realloc
453 # define free tcsh_free
456 #if defined(HAVE_GETHOSTNAME) && !HAVE_DECL_GETHOSTNAME
457 extern int gethostname __P((char *, int));
461 # define mygetpgrp() getpgrp(0)
463 # define mygetpgrp() getpgrp()
466 #if !defined(POSIX) || defined(SUNOS4) || defined(UTekV) || defined(sysV88)
467 extern time_t time();
468 extern char *getenv();
471 extern char *ttyname();
472 # endif /* __EMX__ */
477 extern int toupper __P((int));
478 # endif /* toupper */
480 extern int tolower __P((int));
481 # endif /* tolower */
482 extern caddr_t sbrk __P((int));
484 # ifndef WINNT_NATIVE
489 # endif /* !WINNT_NATIVE */
492 extern void perror();
496 # if !defined(_AIX370) && !defined(MACH) && !defined(NeXT) && !defined(_AIXPS2) && !defined(ardent) && !defined(SUNOS4) && !defined(HPBSD) && !defined(__MACHTEN__)
497 # if (!defined(apollo) || !defined(__STDC__)) && !defined(__DGUX__) && !defined(fps500)
498 extern RETSIGTYPE sigvec();
500 extern void sigpause();
502 # endif /* (!apollo || !__STDC__) && !__DGUX__ && !fps500 */
503 # endif /* _AIX370 || MACH || NeXT || _AIXPS2 || ardent || SUNOS4 || HPBSD */
504 extern sigmask_t sigblock();
505 extern sigmask_t sigsetmask();
506 # endif /* BSDSIGS */
509 extern uid_t getuid(), geteuid();
510 extern gid_t getgid(), getegid();
514 extern memalign_t malloc();
515 extern memalign_t realloc();
516 extern memalign_t calloc();
518 # endif /* SYSMALLOC */
523 extern pid_t wait3();
524 # endif /* __MACHTEN__ */
525 # endif /* BSDTIMES */
526 # endif /* BSDJOBS */
528 # if (!defined(fps500) && !defined(apollo) && !defined(__lucid) && !defined(HPBSD) && !defined(DECOSF1))
529 extern void setpwent();
530 extern void endpwent();
531 # endif /* !fps500 && !apollo && !__lucid && !HPBSD && !DECOSF1 */
534 extern struct passwd *getpwuid(), *getpwnam(), *getpwent();
535 # ifdef HAVE_SHADOW_H
536 extern struct spwd *getspnam(), *getspent();
537 # endif /* HAVE_SHADOW_H */
539 extern struct authorization *getauthuid();
540 # endif /* HAVE_AUTH_H */
541 # endif /* __STDC__ */
544 extern char *getcwd();
547 #else /* POSIX || !SUNOS4 || !UTekV || !sysV88 */
549 # if (defined(SUNOS4) && !defined(__GNUC__)) || defined(_IBMR2) || defined(_IBMESA)
550 extern char *getvwd();
551 # endif /* (SUNOS4 && ! __GNUC__) || _IBMR2 || _IBMESA */
554 extern char *ttyname();
558 extern char *ttyname();
559 # endif /* __clipper__ */
561 #endif /* !POSIX || SUNOS4 || UTekV || sysV88 */
563 #if defined(SUNOS4) && __GNUC__ == 2
565 * Somehow these are missing
567 extern int ioctl __P((int, int, ...));
568 extern int readlink __P((const char *, char *, size_t));
569 extern void setgrent __P((void));
570 extern void endgrent __P((void));
572 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
574 extern int getpeername __P((int, struct sockaddr *, int *));
575 # endif /* _SOCKLEN_T */
576 # endif /* REMOTEHOST */
577 #endif /* SUNOS4 && __GNUC__ == 2 */
579 #if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4)
580 # if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
581 extern void bcopy __P((const void *, void *, size_t));
582 # define memmove(a, b, c) (bcopy((char *) (b), (char *) (a), (int) (c)), a)
583 # endif /* __alpha && __osf__ && DECOSF1 < 200 */
584 #endif /* (BSD && !BSD4_4) || SUNOS4 */
587 # include <memory.h> /* memset should be declared in <string.h> but isn't */
592 /* Irix6 defines getpeername(int, void *, int *) which conflicts with
593 the definition below. */
594 # if !defined(__sgi) && !defined(_OSD_POSIX) && !defined(__MVS__)
595 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
597 extern int getpeername __P((int, struct sockaddr *, int *));
598 # endif /* _SOCKLEN_T */
599 # endif /* !__sgi && !_OSD_POSIX && !__MVS__ */
600 # endif /* REMOTEHOST */
602 extern int getrlimit __P((int, struct rlimit *));
603 extern int setrlimit __P((int, const struct rlimit *));
604 # endif /* !BSDTIMES */
605 # if defined(SOLARIS2)
606 extern char *strerror __P((int));
607 # endif /* SOLARIS2 */
608 #endif /* SYSVREL == 4 */
610 #if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
611 /* These are ok for 1.3, but conflict with the header files for 2.0 */
612 extern char *sbrk __P((ssize_t));
613 extern int ioctl __P((int, unsigned long, char *));
614 extern pid_t vfork __P((void));
615 extern int killpg __P((pid_t, int));
616 #endif /* __osf__ && __alpha && DECOSF1 < 200 */
618 #endif /* _h_tc_os */