tc.os.h revision 167465
1/* $Header: /p/tcsh/cvsroot/tcsh/tc.os.h,v 3.101 2006/02/14 00:52:52 christos Exp $ */
2/*
3 * tc.os.h: Shell os dependent defines
4 */
5/*-
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
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.
20 *
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
31 * SUCH DAMAGE.
32 */
33#ifndef _h_tc_os
34#define _h_tc_os
35
36#ifdef notdef
37/*
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
41 */
42# define BACKPIPE
43#endif /* notdef */
44
45#ifdef __CYGWIN__
46#  undef NOFILE
47#  define NOFILE sysconf(_SC_OPEN_MAX)
48#endif
49
50#ifdef   _VMS_POSIX
51# ifndef  NOFILE
52#  define  NOFILE 64
53# endif /* NOFILE */
54# define  nice(a)       setprio((getpid()),a)
55# include <sys/time.h>    /* for time stuff in tc.prompt.c */
56# include <limits.h>
57#endif /* atp vmsposix */
58
59#if defined(DECOSF1) || defined(HPUXVERSION)
60# include <sys/signal.h>
61#endif /* DECOSF1 || HPUXVERSION */
62
63#ifdef DECOSF1
64# include <sys/ioctl.h>
65#endif /* DECOSF1 */
66
67#if defined(OPEN_MAX) && !defined(NOFILE)
68# define NOFILE OPEN_MAX
69#endif /* OPEN_MAX && !NOFILE */
70
71#if defined(USR_NFDS) && !defined(NOFILE)
72# define NOFILE USR_NFDS
73#endif /* USR_NFDS && !NOFILE */
74
75#ifndef NOFILE
76# define NOFILE 256
77#endif /* NOFILE */
78
79#ifdef OREO
80# include <sys/time.h>
81# ifdef notdef
82  /* Don't include it, because it defines things we don't really have */
83#  include <sys/resource.h>
84# endif /* notdef */
85# ifdef POSIX
86#  include <sys/tty.h>
87#  include <termios.h>
88# endif /* POSIX */
89#endif /* OREO */
90
91#ifdef convex
92# include <sys/dmon.h>
93#endif /* convex */
94
95#ifdef titan
96extern int end;
97#endif /* titan */
98
99#ifdef hpux
100# ifdef lint
101/*
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...
106 */
107struct ucred {
108    int     foo;
109};
110# endif /* lint */
111
112/*
113 * hpux 7.0 does not define it
114 */
115# ifndef CSUSP
116#  define CSUSP 032
117# endif	/* CSUSP */
118
119# include <signal.h>
120# if !defined(hp9000s500) && !(defined(SIGRTMAX) || defined(SIGRTMIN))
121/*
122 * hpux < 7
123 */
124#  include <sys/bsdtty.h>
125# endif /* !hp9000s500 && !(SIGRTMAX || SIGRTMIN) */
126
127# ifndef TIOCSTI
128#  include <sys/strtio.h>
129# endif
130#endif /* hpux */
131
132/*
133 * ISC does not define CSUSP
134 */
135#ifdef ISC
136# ifndef CSUSP
137#  define CSUSP 032
138# endif	/* CSUSP */
139# if defined(POSIX) && !defined(TIOCGWINSZ)
140/*
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.
143 */
144#  define TIOCGWINSZ      (('T'<<8)|104)
145# endif /* POSIX && !TIOCGWINSZ */
146#endif /* ISC */
147
148#ifdef ISC202
149# undef TIOCGWINSZ
150#endif /* ISC202 */
151
152/*
153 * XXX: This will be changed soon to
154 * #if (SYSVREL > 0) && defined(TIOCGWINSZ)
155 * If that breaks on your machine, let me know.
156 *
157 * It would break on glibc, where all this is
158 * defined in <termios.h>. Wrapper added.
159 */
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)
162#  ifdef TIOCGWINSZ
163/*
164 * for struct winsiz
165 */
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 */
171
172#ifdef IRIS4D
173# include <sys/time.h>
174# include <sys/resource.h>
175#endif /* IRIS4D */
176
177/*
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.
183 *
184 * From: scott@craycos.com (Scott Bolte)
185 */
186#ifndef WINNT_NATIVE
187# ifdef F_SETFD
188#  ifndef FD_CLOEXEC
189#   define FD_CLOEXEC 1
190#  endif
191#  define close_on_exec(fd, v) fcntl((fd), F_SETFD, ((v) ? FD_CLOEXEC : 0))
192# else /* !F_SETFD */
193#  ifdef FIOCLEX
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 */
202
203/*
204 * Stat
205 */
206#ifdef ISC
207/* these are not defined for _POSIX_SOURCE under ISC 2.2 */
208# ifndef S_IFMT
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 */
216#  ifndef ISC202
217#   define S_IFLNK	0120000		/* symbolic link */
218#  endif /* ISC202 */
219# endif /* S_IFMT */
220#endif /* ISC */
221
222#ifdef STAT_MACROS_BROKEN
223# undef S_ISDIR
224# undef S_ISCHR
225# undef S_ISBLK
226# undef S_ISREG
227# undef S_ISFIFO
228# undef S_ISNAM
229# undef S_ISLNK
230# undef S_ISSOCK
231#endif /* STAT_MACROS_BROKEN */
232
233#ifdef S_IFMT
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 */
258#endif /* S_IFMT */
259
260#ifdef tower32
261/* The header files lie; we really don't have symlinks */
262# undef S_ISLNK
263# undef S_IFLNK
264#endif /* tower32 */
265
266#ifndef S_IREAD
267# define S_IREAD 0000400
268#endif /* S_IREAD */
269#ifndef S_IROTH
270# define S_IROTH (S_IREAD >> 6)
271#endif /* S_IROTH */
272#ifndef S_IRGRP
273# define S_IRGRP (S_IREAD >> 3)
274#endif /* S_IRGRP */
275#ifndef S_IRUSR
276# define S_IRUSR S_IREAD
277#endif /* S_IRUSR */
278
279#ifndef S_IWRITE
280# define S_IWRITE 0000200
281#endif /* S_IWRITE */
282#ifndef S_IWOTH
283# define S_IWOTH (S_IWRITE >> 6)
284#endif /* S_IWOTH */
285#ifndef S_IWGRP
286# define S_IWGRP (S_IWRITE >> 3)
287#endif /* S_IWGRP */
288#ifndef S_IWUSR
289# define S_IWUSR S_IWRITE
290#endif /* S_IWUSR */
291
292#ifndef S_IEXEC
293# define S_IEXEC 0000100
294#endif /* S_IEXEC */
295#ifndef S_IXOTH
296# define S_IXOTH (S_IEXEC >> 6)
297#endif /* S_IXOTH */
298#ifndef S_IXGRP
299# define S_IXGRP (S_IEXEC >> 3)
300#endif /* S_IXGRP */
301#ifndef S_IXUSR
302# define S_IXUSR S_IEXEC
303#endif /* S_IXUSR */
304
305#ifndef S_ISUID
306# define S_ISUID 0004000 	/* setuid */
307#endif /* S_ISUID */
308#ifndef S_ISGID
309# define S_ISGID 0002000	/* setgid */
310#endif /* S_ISGID */
311#ifndef S_ISVTX
312# define S_ISVTX 0001000	/* sticky */
313#endif /* S_ISVTX */
314#ifndef S_ENFMT
315# define S_ENFMT S_ISGID	/* record locking enforcement flag */
316#endif /* S_ENFMT */
317
318/* the following macros are for POSIX conformance */
319#ifndef S_IRWXU
320# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
321#endif /* S_IRWXU */
322#ifndef S_IRWXG
323# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
324#endif /* S_IRWXG */
325#ifndef S_IRWXO
326# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
327#endif /* S_IRWXO */
328
329/*
330 * Access()
331 */
332#ifndef F_OK
333# define F_OK 0
334#endif /* F_OK */
335#ifndef X_OK
336# define X_OK 1
337#endif /* X_OK */
338#ifndef W_OK
339# define W_OK 2
340#endif /* W_OK */
341#ifndef R_OK
342# define R_OK 4
343#endif /* R_OK */
344
345/*
346 * Open()
347 */
348#ifndef O_RDONLY
349# define O_RDONLY	0
350#endif /* O_RDONLY */
351#ifndef O_WRONLY
352# define O_WRONLY	1
353#endif /* O_WRONLY */
354#ifndef O_RDWR
355# define O_RDWR		2
356#endif /* O_RDWR */
357
358/*
359 * Lseek()
360 */
361#ifndef L_SET
362# ifdef SEEK_SET
363#  define L_SET		SEEK_SET
364# else /* !SEEK_SET */
365#  define L_SET		0
366# endif	/* SEEK_SET */
367#endif /* L_SET */
368#ifndef L_INCR
369# ifdef SEEK_CUR
370#  define L_INCR	SEEK_CUR
371# else /* !SEEK_CUR */
372#  define L_INCR	1
373# endif	/* SEEK_CUR */
374#endif /* L_INCR */
375#ifndef L_XTND
376# ifdef SEEK_END
377#  define L_XTND	SEEK_END
378# else /* !SEEK_END */
379#  define L_XTND	2
380# endif /* SEEK_END */
381#endif /* L_XTND */
382
383#if !defined (HAVE_SETPGID) && !defined (SETPGRP_VOID)
384# define setpgid(pid, pgrp)	setpgrp(pid, pgrp)
385#endif
386
387#if defined(BSDJOBS) && !(defined(POSIX) && defined(POSIXJOBS))
388# define NEEDtcgetpgrp
389#endif /* BSDJOBS && !(POSIX && POSIXJOBS) */
390
391#ifdef RENO
392/*
393 * RENO has this broken. It is fixed on 4.4BSD
394 */
395# define NEEDtcgetpgrp
396#endif /* RENO */
397
398#ifdef SXA
399# ifndef _BSDX_
400/*
401 * Only needed in the system V environment.
402 */
403#  define setrlimit 	bsd_setrlimit
404#  define getrlimit	bsd_getrlimit
405# endif	/* _BSDX_ */
406#endif /* SXA */
407
408#if defined(_MINIX) || defined(__EMX__)
409# define HAVENOLIMIT
410/*
411 * Minix does not have these, so...
412 */
413# define getpgrp		getpid
414#endif /* _MINIX || __EMX__ */
415
416#ifdef __EMX__
417/* XXX: How can we get the tty name in emx? */
418# define ttyname(fd) (isatty(fd) ? "/dev/tty" : NULL)
419#endif /* __EMX__ */
420
421#ifndef S_IFLNK
422# define lstat stat
423#endif /* S_IFLNK */
424
425
426#if defined(BSDTIMES) && !defined(_SEQUENT_)
427typedef struct timeval timeval_t;
428#endif /* BSDTIMES && ! _SEQUENT_ */
429
430#ifdef NeXT
431/*
432 * From Tony_Mason@transarc.com, override NeXT's malloc stuff.
433 */
434# define malloc tcsh_malloc
435# define calloc tcsh_calloc
436# define realloc tcsh_realloc
437# define free tcsh_free
438#endif /* NeXT */
439
440#if defined(HAVE_GETHOSTNAME) && !HAVE_DECL_GETHOSTNAME
441extern int gethostname (char *, int);
442#endif
443
444#ifndef GETPGRP_VOID
445# define mygetpgrp()    getpgrp(0)
446#else
447# define mygetpgrp()    getpgrp()
448#endif
449
450#if !defined(POSIX) || defined(SUNOS4) || defined(UTekV) || defined(sysV88)
451extern time_t time();
452extern char *getenv();
453extern int atoi();
454# ifndef __EMX__
455extern char *ttyname();
456# endif /* __EMX__ */
457
458
459# if defined(SUNOS4)
460#  ifndef toupper
461extern int toupper (int);
462#  endif /* toupper */
463#  ifndef tolower
464extern int tolower (int);
465#  endif /* tolower */
466extern caddr_t sbrk (int);
467# else /* !SUNOS4 */
468#  ifndef WINNT_NATIVE
469#   ifdef hpux
470extern void abort();
471extern void qsort();
472#   endif /* hpux */
473#  endif /* !WINNT_NATIVE */
474# endif	/* SUNOS4 */
475#ifndef _CX_UX
476extern void perror();
477#endif
478
479# ifdef BSD
480extern uid_t getuid(), geteuid();
481extern gid_t getgid(), getegid();
482# endif /* BSD */
483
484# ifdef SYSMALLOC
485extern memalign_t malloc();
486extern memalign_t realloc();
487extern memalign_t calloc();
488extern void free();
489# endif	/* SYSMALLOC */
490
491# ifdef BSDJOBS
492#  ifdef BSDTIMES
493#   ifdef __MACHTEN__
494extern pid_t wait3();
495#   endif /* __MACHTEN__ */
496#  endif /* BSDTIMES */
497# endif	/* BSDJOBS */
498
499# if (!defined(fps500) && !defined(apollo) && !defined(__lucid) && !defined(HPBSD) && !defined(DECOSF1))
500extern void setpwent();
501extern void endpwent();
502# endif /* !fps500 && !apollo && !__lucid && !HPBSD && !DECOSF1 */
503
504# ifndef __STDC__
505extern struct passwd *getpwuid(), *getpwnam(), *getpwent();
506#  ifdef HAVE_SHADOW_H
507extern struct spwd *getspnam(), *getspent();
508#  endif /* HAVE_SHADOW_H */
509#  if defined(HAVE_AUTH_H) && defined(HAVE_GETAUTHUID)
510extern struct authorization *getauthuid();
511#  endif /* HAVE_AUTH_H && HAVE_GETAUTHUID */
512# endif /* __STDC__ */
513
514# ifndef getcwd
515extern char *getcwd();
516# endif	/* getcwd */
517
518#else /* POSIX || !SUNOS4 || !UTekV || !sysV88 */
519
520# if (defined(SUNOS4) && !defined(__GNUC__)) || defined(_IBMR2) || defined(_IBMESA)
521extern char *getvwd();
522# endif	/* (SUNOS4 && ! __GNUC__) || _IBMR2 || _IBMESA */
523
524# ifdef SCO
525extern char *ttyname();
526# endif /* SCO */
527
528# ifdef __clipper__
529extern char *ttyname();
530# endif /* __clipper__ */
531
532#endif /* !POSIX || SUNOS4 || UTekV || sysV88 */
533
534#if defined(SUNOS4) && __GNUC__ == 2
535/*
536 * Somehow these are missing
537 */
538extern int ioctl (int, int, ...);
539extern int readlink (const char *, char *, size_t);
540extern void setgrent (void);
541extern void endgrent (void);
542# ifdef REMOTEHOST
543#  ifndef _SOCKLEN_T	/* Avoid Solaris 2.7 bogosity. */
544struct sockaddr;
545extern int getpeername (int, struct sockaddr *, int *);
546#  endif /* _SOCKLEN_T */
547# endif /* REMOTEHOST */
548#endif /* SUNOS4 && __GNUC__ == 2 */
549
550#if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4)
551# if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
552extern 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 */
556
557#ifdef SUNOS4
558# include <memory.h>	/* memset should be declared in <string.h> but isn't */
559#endif /* SUNOS4 */
560
561#if SYSVREL == 4
562# ifdef REMOTEHOST
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. */
567struct sockaddr;
568extern int getpeername (int, struct sockaddr *, int *);
569#   endif /* _SOCKLEN_T */
570#  endif /* !__sgi && !_OSD_POSIX && !__MVS__ */
571# endif /* REMOTEHOST */
572# ifndef BSDTIMES
573extern int getrlimit (int, struct rlimit *);
574extern int setrlimit (int, const struct rlimit *);
575# endif /* !BSDTIMES */
576# if defined(SOLARIS2)
577extern char *strerror (int);
578# endif /* SOLARIS2 */
579#endif /* SYSVREL == 4 */
580
581#if defined(__alpha) && defined(__osf__) && DECOSF1 < 200
582/* These are ok for 1.3, but conflict with the header files for 2.0 */
583extern char *sbrk (ssize_t);
584extern int ioctl (int, unsigned long, char *);
585extern pid_t vfork (void);
586extern int killpg (pid_t, int);
587#endif /* __osf__ && __alpha && DECOSF1 < 200 */
588
589#ifndef va_copy
590# ifdef __va_copy
591#  define va_copy(DEST, SRC) __va_copy(DEST, SRC)
592# else
593#  define va_copy(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(va_list))
594# endif
595#endif
596
597#endif /* _h_tc_os */
598