2 * tc.os.h: Shell os dependent defines
5 * Copyright (c) 1980, 1991 The Regents of the University of California.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * for SVR4 and linux we used to fork pipelines backwards.
38 * This should not be needed any more.
39 * more info in sh.sem.c
46 # define NOFILE sysconf(_SC_OPEN_MAX)
53 # define nice(a) setprio((getpid()),a)
54 # include <sys/time.h> /* for time stuff in tc.prompt.c */
56 #endif /* atp vmsposix */
58 #if defined(DECOSF1) || defined(HPUXVERSION)
59 # include <sys/signal.h>
60 #endif /* DECOSF1 || HPUXVERSION */
63 # include <sys/ioctl.h>
66 #if defined(OPEN_MAX) && !defined(NOFILE)
67 # define NOFILE OPEN_MAX
68 #endif /* OPEN_MAX && !NOFILE */
70 #if defined(USR_NFDS) && !defined(NOFILE)
71 # define NOFILE USR_NFDS
72 #endif /* USR_NFDS && !NOFILE */
79 # include <sys/time.h>
81 /* Don't include it, because it defines things we don't really have */
82 # include <sys/resource.h>
91 #include <sys/resource.h>
98 # include <sys/dmon.h>
108 * Hpux defines struct ucred, in <sys/user.h>, but if I include that
109 * then I need to include the *world*
110 * [all this to pass lint cleanly!!!]
111 * so I define struct ucred here...
119 * hpux 7.0 does not define it
126 # if !defined(hp9000s500) && !(defined(SIGRTMAX) || defined(SIGRTMIN))
130 # include <sys/bsdtty.h>
131 # endif /* !hp9000s500 && !(SIGRTMAX || SIGRTMIN) */
134 # include <sys/strtio.h>
139 * ISC does not define CSUSP
145 # if defined(POSIX) && !defined(TIOCGWINSZ)
147 * ISC defines this only in termio.h. If we are using POSIX and include
148 * termios.h, then we define it ourselves so that window resizing works.
150 # define TIOCGWINSZ (('T'<<8)|104)
151 # endif /* POSIX && !TIOCGWINSZ */
159 * XXX: This will be changed soon to
160 * #if (SYSVREL > 0) && defined(TIOCGWINSZ)
161 * If that breaks on your machine, let me know.
163 * It would break on glibc, where all this is
164 * defined in <termios.h>. Wrapper added.
166 #if !defined(__linux__) && !defined(__GNU__) && !defined(__GLIBC__) && !defined(_VMS_POSIX)
167 # if defined(INTEL) || defined(u3b2) || defined (u3b5) || defined(ub15) || defined(u3b20d) || defined(ISC) || defined(SCO) || defined(tower32)
172 # include <sys/stream.h>
173 # include <sys/ptem.h>
174 # endif /* TIOCGWINSZ */
175 # endif /* INTEL || u3b2 || u3b5 || ub15 || u3b20d || ISC || SCO || tower32 */
176 #endif /* !glibc && !_VMS_POSIX */
179 # include <sys/time.h>
180 # include <sys/resource.h>
184 * For some versions of system V software, specially ones that use the
185 * Wollongong Software TCP/IP, the FIOCLEX, FIONCLEX, FIONBIO calls
186 * might not work correctly for file descriptors [they work only for
187 * sockets]. So we try to use first the fcntl() and we only use the
188 * ioctl() form, only if we don't have the fcntl() one.
190 * From: scott@craycos.com (Scott Bolte)
195 # define FD_CLOEXEC 1
197 # define close_on_exec(fd, v) fcntl((fd), F_SETFD, ((v) ? FD_CLOEXEC : 0))
198 # else /* !F_SETFD */
200 # define close_on_exec(fd, v) ioctl((fd), ((v) ? FIOCLEX : FIONCLEX), NULL)
201 # else /* !FIOCLEX */
202 # define close_on_exec(fd, v) /* Nothing */
203 # endif /* FIOCLEX */
204 # endif /* F_SETFD */
205 #else /* WINNT_NATIVE */
206 # define close_on_exec(fd, v) nt_close_on_exec((fd),(v))
207 #endif /* !WINNT_NATIVE */
213 /* these are not defined for _POSIX_SOURCE under ISC 2.2 */
215 # define S_IFMT 0170000 /* type of file */
216 # define S_IFDIR 0040000 /* directory */
217 # define S_IFCHR 0020000 /* character special */
218 # define S_IFBLK 0060000 /* block special */
219 # define S_IFREG 0100000 /* regular */
220 # define S_IFIFO 0010000 /* fifo */
221 # define S_IFNAM 0050000 /* special named file */
223 # define S_IFLNK 0120000 /* symbolic link */
228 #ifdef STAT_MACROS_BROKEN
237 #endif /* STAT_MACROS_BROKEN */
240 # if !defined(S_ISDIR) && defined(S_IFDIR)
241 # define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR)
242 # endif /* ! S_ISDIR && S_IFDIR */
243 # if !defined(S_ISCHR) && defined(S_IFCHR)
244 # define S_ISCHR(a) (((a) & S_IFMT) == S_IFCHR)
245 # endif /* ! S_ISCHR && S_IFCHR */
246 # if !defined(S_ISBLK) && defined(S_IFBLK)
247 # define S_ISBLK(a) (((a) & S_IFMT) == S_IFBLK)
248 # endif /* ! S_ISBLK && S_IFBLK */
249 # if !defined(S_ISREG) && defined(S_IFREG)
250 # define S_ISREG(a) (((a) & S_IFMT) == S_IFREG)
251 # endif /* ! S_ISREG && S_IFREG */
252 # if !defined(S_ISFIFO) && defined(S_IFIFO)
253 # define S_ISFIFO(a) (((a) & S_IFMT) == S_IFIFO)
254 # endif /* ! S_ISFIFO && S_IFIFO */
255 # if !defined(S_ISNAM) && defined(S_IFNAM)
256 # define S_ISNAM(a) (((a) & S_IFMT) == S_IFNAM)
257 # endif /* ! S_ISNAM && S_IFNAM */
258 # if !defined(S_ISLNK) && defined(S_IFLNK)
259 # define S_ISLNK(a) (((a) & S_IFMT) == S_IFLNK)
260 # endif /* ! S_ISLNK && S_IFLNK */
261 # if !defined(S_ISSOCK) && defined(S_IFSOCK)
262 # define S_ISSOCK(a) (((a) & S_IFMT) == S_IFSOCK)
263 # endif /* ! S_ISSOCK && S_IFSOCK */
267 /* The header files lie; we really don't have symlinks */
273 # define S_IREAD 0000400
276 # define S_IROTH (S_IREAD >> 6)
279 # define S_IRGRP (S_IREAD >> 3)
282 # define S_IRUSR S_IREAD
286 # define S_IWRITE 0000200
287 #endif /* S_IWRITE */
289 # define S_IWOTH (S_IWRITE >> 6)
292 # define S_IWGRP (S_IWRITE >> 3)
295 # define S_IWUSR S_IWRITE
299 # define S_IEXEC 0000100
302 # define S_IXOTH (S_IEXEC >> 6)
305 # define S_IXGRP (S_IEXEC >> 3)
308 # define S_IXUSR S_IEXEC
312 # define S_ISUID 0004000 /* setuid */
315 # define S_ISGID 0002000 /* setgid */
318 # define S_ISVTX 0001000 /* sticky */
321 # define S_ENFMT S_ISGID /* record locking enforcement flag */
324 /* the following macros are for POSIX conformance */
326 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
329 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
332 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
356 #endif /* O_RDONLY */
359 #endif /* O_WRONLY */
364 # define O_TEMPORARY 0
365 #endif /* O_TEMPORARY */
370 # define O_LARGEFILE 0
371 #endif /* O_LARGEFILE */
381 # define L_SET SEEK_SET
382 # else /* !SEEK_SET */
384 # endif /* SEEK_SET */
388 # define L_INCR SEEK_CUR
389 # else /* !SEEK_CUR */
391 # endif /* SEEK_CUR */
395 # define L_XTND SEEK_END
396 # else /* !SEEK_END */
398 # endif /* SEEK_END */
401 #if !defined (HAVE_SETPGID) && !defined (SETPGRP_VOID)
402 # define setpgid(pid, pgrp) setpgrp(pid, pgrp)
405 #if defined(BSDJOBS) && !(defined(POSIX) && defined(POSIXJOBS))
406 # define NEEDtcgetpgrp
407 #endif /* BSDJOBS && !(POSIX && POSIXJOBS) */
411 * RENO has this broken. It is fixed on 4.4BSD
413 # define NEEDtcgetpgrp
419 * Only needed in the system V environment.
421 # define setrlimit bsd_setrlimit
422 # define getrlimit bsd_getrlimit
426 #if defined(_MINIX) || defined(__EMX__)
429 * Minix does not have these, so...
431 # define getpgrp getpid
432 #endif /* _MINIX || __EMX__ */
435 /* XXX: How can we get the tty name in emx? */
436 # define ttyname(fd) (isatty(fd) ? "/dev/tty" : NULL)
444 #if defined(BSDTIMES) && !defined(_SEQUENT_)
445 typedef struct timeval timeval_t;
446 #endif /* BSDTIMES && ! _SEQUENT_ */
450 * From Tony_Mason@transarc.com, override NeXT's malloc stuff.
452 # define malloc tcsh_malloc
453 # define calloc tcsh_calloc
454 # define realloc tcsh_realloc
455 # define free tcsh_free
458 #if defined(HAVE_GETHOSTNAME) && !HAVE_DECL_GETHOSTNAME
459 extern int gethostname (char *, int);
463 # define mygetpgrp() getpgrp(0)
465 # define mygetpgrp() getpgrp()
468 #if !defined(POSIX) || defined(SUNOS4) || defined(UTekV) || defined(sysV88)
469 extern time_t time();
470 extern char *getenv();
473 extern char *ttyname();
474 # endif /* __EMX__ */
479 extern int toupper (int);
480 # endif /* toupper */
482 extern int tolower (int);
483 # endif /* tolower */
484 extern caddr_t sbrk (int);
486 # ifndef WINNT_NATIVE
491 # endif /* !WINNT_NATIVE */
494 extern void perror();
498 extern uid_t getuid(), geteuid();
499 extern gid_t getgid(), getegid();
503 extern memalign_t malloc();
504 extern memalign_t realloc();
505 extern memalign_t calloc();
507 # endif /* SYSMALLOC */
512 extern pid_t wait3();
513 # endif /* __MACHTEN__ */
514 # endif /* BSDTIMES */
515 # endif /* BSDJOBS */
517 # if (!defined(fps500) && !defined(apollo) && !defined(__lucid) && !defined(HPBSD) && !defined(DECOSF1))
518 extern void setpwent();
519 extern void endpwent();
520 # endif /* !fps500 && !apollo && !__lucid && !HPBSD && !DECOSF1 */
523 extern struct passwd *getpwuid(), *getpwnam(), *getpwent();
524 # ifdef HAVE_SHADOW_H
525 extern struct spwd *getspnam(), *getspent();
526 # endif /* HAVE_SHADOW_H */
527 # if defined(HAVE_AUTH_H) && defined(HAVE_GETAUTHUID)
528 extern struct authorization *getauthuid();
529 # endif /* HAVE_AUTH_H && HAVE_GETAUTHUID */
530 # endif /* __STDC__ */
533 extern char *getcwd();
536 #else /* POSIX || !SUNOS4 || !UTekV || !sysV88 */
538 # if (defined(SUNOS4) && !defined(__GNUC__)) || defined(_IBMR2) || defined(_IBMESA)
539 extern char *getvwd();
540 # endif /* (SUNOS4 && ! __GNUC__) || _IBMR2 || _IBMESA */
543 extern char *ttyname();
547 extern char *ttyname();
548 # endif /* __clipper__ */
550 #endif /* !POSIX || SUNOS4 || UTekV || sysV88 */
552 #if defined(SUNOS4) && __GNUC__ == 2
554 * Somehow these are missing
556 extern int ioctl (int, int, ...);
557 extern int readlink (const char *, char *, size_t);
558 extern void setgrent (void);
559 extern void endgrent (void);
561 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
563 extern int getpeername (int, struct sockaddr *, int *);
564 # endif /* _SOCKLEN_T */
565 # endif /* REMOTEHOST */
566 #endif /* SUNOS4 && __GNUC__ == 2 */
568 #if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4)
569 # if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
570 extern void bcopy (const void *, void *, size_t);
571 # define memmove(a, b, c) (bcopy((char *) (b), (char *) (a), (int) (c)), a)
572 # endif /* __alpha && __osf__ && DECOSF1 < 200 */
573 #endif /* (BSD && !BSD4_4) || SUNOS4 */
576 # include <memory.h> /* memset should be declared in <string.h> but isn't */
581 /* Irix6 defines getpeername(int, void *, int *) which conflicts with
582 the definition below. */
583 # if !defined(__sgi) && !defined(_OSD_POSIX) && !defined(__MVS__)
584 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
586 extern int getpeername (int, struct sockaddr *, int *);
587 # endif /* _SOCKLEN_T */
588 # endif /* !__sgi && !_OSD_POSIX && !__MVS__ */
589 # endif /* REMOTEHOST */
591 extern int getrlimit (int, struct rlimit *);
592 extern int setrlimit (int, const struct rlimit *);
593 # endif /* !BSDTIMES */
594 # if defined(SOLARIS2)
595 extern char *strerror (int);
596 # endif /* SOLARIS2 */
597 #endif /* SYSVREL == 4 */
599 #if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
600 /* These are ok for 1.3, but conflict with the header files for 2.0 */
601 extern char *sbrk (ssize_t);
602 extern int ioctl (int, unsigned long, char *);
603 extern pid_t vfork (void);
604 extern int killpg (pid_t, int);
605 #endif /* __osf__ && __alpha && DECOSF1 < 200 */
609 # define va_copy(DEST, SRC) __va_copy(DEST, SRC)
611 # define va_copy(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(va_list))
615 #if defined(__CYGWIN__) && !defined(NO_CRYPT)
616 extern char *cygwin_xcrypt(struct passwd *, const char *, const char *);
617 #endif /* __CYGWIN__ && !NO_CRYPT */
619 #endif /* _h_tc_os */