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