1 /* $Header: /p/tcsh/cvsroot/tcsh/tc.os.h,v 3.105 2011/02/04 18:00: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
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/resource.h>
99 # include <sys/dmon.h>
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...
120 * hpux 7.0 does not define it
127 # if !defined(hp9000s500) && !(defined(SIGRTMAX) || defined(SIGRTMIN))
131 # include <sys/bsdtty.h>
132 # endif /* !hp9000s500 && !(SIGRTMAX || SIGRTMIN) */
135 # include <sys/strtio.h>
140 * ISC does not define CSUSP
146 # if defined(POSIX) && !defined(TIOCGWINSZ)
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.
151 # define TIOCGWINSZ (('T'<<8)|104)
152 # endif /* POSIX && !TIOCGWINSZ */
160 * XXX: This will be changed soon to
161 * #if (SYSVREL > 0) && defined(TIOCGWINSZ)
162 * If that breaks on your machine, let me know.
164 * It would break on glibc, where all this is
165 * defined in <termios.h>. Wrapper added.
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)
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 */
180 # include <sys/time.h>
181 # include <sys/resource.h>
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.
191 * From: scott@craycos.com (Scott Bolte)
196 # define FD_CLOEXEC 1
198 # define close_on_exec(fd, v) fcntl((fd), F_SETFD, ((v) ? FD_CLOEXEC : 0))
199 # else /* !F_SETFD */
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 */
214 /* these are not defined for _POSIX_SOURCE under ISC 2.2 */
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 */
224 # define S_IFLNK 0120000 /* symbolic link */
229 #ifdef STAT_MACROS_BROKEN
238 #endif /* STAT_MACROS_BROKEN */
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 */
268 /* The header files lie; we really don't have symlinks */
274 # define S_IREAD 0000400
277 # define S_IROTH (S_IREAD >> 6)
280 # define S_IRGRP (S_IREAD >> 3)
283 # define S_IRUSR S_IREAD
287 # define S_IWRITE 0000200
288 #endif /* S_IWRITE */
290 # define S_IWOTH (S_IWRITE >> 6)
293 # define S_IWGRP (S_IWRITE >> 3)
296 # define S_IWUSR S_IWRITE
300 # define S_IEXEC 0000100
303 # define S_IXOTH (S_IEXEC >> 6)
306 # define S_IXGRP (S_IEXEC >> 3)
309 # define S_IXUSR S_IEXEC
313 # define S_ISUID 0004000 /* setuid */
316 # define S_ISGID 0002000 /* setgid */
319 # define S_ISVTX 0001000 /* sticky */
322 # define S_ENFMT S_ISGID /* record locking enforcement flag */
325 /* the following macros are for POSIX conformance */
327 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
330 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
333 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
357 #endif /* O_RDONLY */
360 #endif /* O_WRONLY */
365 # define O_TEMPORARY 0
366 #endif /* O_TEMPORARY */
371 # define O_LARGEFILE 0
372 #endif /* O_LARGEFILE */
382 # define L_SET SEEK_SET
383 # else /* !SEEK_SET */
385 # endif /* SEEK_SET */
389 # define L_INCR SEEK_CUR
390 # else /* !SEEK_CUR */
392 # endif /* SEEK_CUR */
396 # define L_XTND SEEK_END
397 # else /* !SEEK_END */
399 # endif /* SEEK_END */
402 #if !defined (HAVE_SETPGID) && !defined (SETPGRP_VOID)
403 # define setpgid(pid, pgrp) setpgrp(pid, pgrp)
406 #if defined(BSDJOBS) && !(defined(POSIX) && defined(POSIXJOBS))
407 # define NEEDtcgetpgrp
408 #endif /* BSDJOBS && !(POSIX && POSIXJOBS) */
412 * RENO has this broken. It is fixed on 4.4BSD
414 # define NEEDtcgetpgrp
420 * Only needed in the system V environment.
422 # define setrlimit bsd_setrlimit
423 # define getrlimit bsd_getrlimit
427 #if defined(_MINIX) || defined(__EMX__)
430 * Minix does not have these, so...
432 # define getpgrp getpid
433 #endif /* _MINIX || __EMX__ */
436 /* XXX: How can we get the tty name in emx? */
437 # define ttyname(fd) (isatty(fd) ? "/dev/tty" : NULL)
445 #if defined(BSDTIMES) && !defined(_SEQUENT_)
446 typedef struct timeval timeval_t
;
447 #endif /* BSDTIMES && ! _SEQUENT_ */
451 * From Tony_Mason@transarc.com, override NeXT's malloc stuff.
453 # define malloc tcsh_malloc
454 # define calloc tcsh_calloc
455 # define realloc tcsh_realloc
456 # define free tcsh_free
459 #if defined(HAVE_GETHOSTNAME) && !HAVE_DECL_GETHOSTNAME
460 extern int gethostname (char *, int);
464 # define mygetpgrp() getpgrp(0)
466 # define mygetpgrp() getpgrp()
469 #if !defined(POSIX) || defined(SUNOS4) || defined(UTekV) || defined(sysV88)
470 extern time_t time();
471 extern char *getenv();
474 extern char *ttyname();
475 # endif /* __EMX__ */
480 extern int toupper (int);
481 # endif /* toupper */
483 extern int tolower (int);
484 # endif /* tolower */
485 extern caddr_t
sbrk (int);
487 # ifndef WINNT_NATIVE
492 # endif /* !WINNT_NATIVE */
495 extern void perror();
499 extern uid_t
getuid(), geteuid();
500 extern gid_t
getgid(), getegid();
504 extern memalign_t
malloc();
505 extern memalign_t
realloc();
506 extern memalign_t
calloc();
508 # endif /* SYSMALLOC */
513 extern pid_t
wait3();
514 # endif /* __MACHTEN__ */
515 # endif /* BSDTIMES */
516 # endif /* BSDJOBS */
518 # if (!defined(fps500) && !defined(apollo) && !defined(__lucid) && !defined(HPBSD) && !defined(DECOSF1))
519 extern void setpwent();
520 extern void endpwent();
521 # endif /* !fps500 && !apollo && !__lucid && !HPBSD && !DECOSF1 */
524 extern struct passwd
*getpwuid(), *getpwnam(), *getpwent();
525 # ifdef HAVE_SHADOW_H
526 extern struct spwd
*getspnam(), *getspent();
527 # endif /* HAVE_SHADOW_H */
528 # if defined(HAVE_AUTH_H) && defined(HAVE_GETAUTHUID)
529 extern struct authorization
*getauthuid();
530 # endif /* HAVE_AUTH_H && HAVE_GETAUTHUID */
531 # endif /* __STDC__ */
534 extern char *getcwd();
537 #else /* POSIX || !SUNOS4 || !UTekV || !sysV88 */
539 # if (defined(SUNOS4) && !defined(__GNUC__)) || defined(_IBMR2) || defined(_IBMESA)
540 extern char *getvwd();
541 # endif /* (SUNOS4 && ! __GNUC__) || _IBMR2 || _IBMESA */
544 extern char *ttyname();
548 extern char *ttyname();
549 # endif /* __clipper__ */
551 #endif /* !POSIX || SUNOS4 || UTekV || sysV88 */
553 #if defined(SUNOS4) && __GNUC__ == 2
555 * Somehow these are missing
557 extern int ioctl (int, int, ...);
558 extern int readlink (const char *, char *, size_t);
559 extern void setgrent (void);
560 extern void endgrent (void);
562 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
564 extern int getpeername (int, struct sockaddr
*, int *);
565 # endif /* _SOCKLEN_T */
566 # endif /* REMOTEHOST */
567 #endif /* SUNOS4 && __GNUC__ == 2 */
569 #if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4)
570 # if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
571 extern void bcopy (const void *, void *, size_t);
572 # define memmove(a, b, c) (bcopy((char *) (b), (char *) (a), (int) (c)), a)
573 # endif /* __alpha && __osf__ && DECOSF1 < 200 */
574 #endif /* (BSD && !BSD4_4) || SUNOS4 */
577 # include <memory.h> /* memset should be declared in <string.h> but isn't */
582 /* Irix6 defines getpeername(int, void *, int *) which conflicts with
583 the definition below. */
584 # if !defined(__sgi) && !defined(_OSD_POSIX) && !defined(__MVS__)
585 # ifndef _SOCKLEN_T /* Avoid Solaris 2.7 bogosity. */
587 extern int getpeername (int, struct sockaddr
*, int *);
588 # endif /* _SOCKLEN_T */
589 # endif /* !__sgi && !_OSD_POSIX && !__MVS__ */
590 # endif /* REMOTEHOST */
592 extern int getrlimit (int, struct rlimit
*);
593 extern int setrlimit (int, const struct rlimit
*);
594 # endif /* !BSDTIMES */
595 # if defined(SOLARIS2)
596 extern char *strerror (int);
597 # endif /* SOLARIS2 */
598 #endif /* SYSVREL == 4 */
600 #if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
601 /* These are ok for 1.3, but conflict with the header files for 2.0 */
602 extern char *sbrk (ssize_t
);
603 extern int ioctl (int, unsigned long, char *);
604 extern pid_t
vfork (void);
605 extern int killpg (pid_t
, int);
606 #endif /* __osf__ && __alpha && DECOSF1 < 200 */
610 # define va_copy(DEST, SRC) __va_copy(DEST, SRC)
612 # define va_copy(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(va_list))
616 #if defined(__CYGWIN__) && !defined(NO_CRYPT)
617 extern char *cygwin_xcrypt(struct passwd
*, const char *, const char *);
618 #endif /* __CYGWIN__ && !NO_CRYPT */
620 #endif /* _h_tc_os */