a05a18034f03a7c19af9ca5312a6de82253bdcc6
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, see
23 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
33 #include <sys/param.h>
35 /* In strict ANSI mode, HP-UX machines define __hpux but not hpux */
36 #if defined(__hpux) && !defined(hpux)
40 #if defined(__bsdi__) || defined(__386BSD__) || defined(_CX_UX) || defined(hpux) || defined(_IBMR2) || defined(linux)
42 #endif /* __bsdi__ || __386BSD__ || _CX_UX || hpux || _IBMR2 || linux */
51 # include <sys/bsdtypes.h>
52 # include <net/errno.h>
56 # define getpgrp __getpgrp
61 # if defined(__STDC__)
63 # endif /* __STDC__ */
70 #ifndef linux /* all done in <errno.h> */
74 /* No macros, please */
78 #if !defined(SYSV) && !defined(linux)
80 # define strlen ___strlen___
87 # if defined(SVR4) || defined(NEWSOS)
88 # define strlen ___strlen___
91 # if !defined(NEWSOS) && !defined(__hpux)
92 extern size_t strlen(const char *);
100 # if defined(__STDC__)
102 # define VA_LIST(var) va_list var;
105 # define VA_START(ap, fmt) va_start(ap, fmt)
106 # define VA_ARGS(ap) ap
107 # define VA_END(ap) va_end(ap)
109 # include <varargs.h>
110 # define VA_LIST(var) va_list var;
111 # define VA_DOTS va_alist
112 # define VA_DECL va_dcl
113 # define VA_START(ap, fmt) va_start(ap)
114 # define VA_ARGS(ap) ap
115 # define VA_END(ap) va_end(ap)
118 # define VA_LIST(var)
119 # define VA_DOTS p1, p2, p3, p4, p5, p6
120 # define VA_DECL unsigned long VA_DOTS;
121 # define VA_START(ap, fmt)
122 # define VA_ARGS(ap) VA_DOTS
125 # define vsnprintf xsnprintf
128 #if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
131 #include <sys/time.h>
133 #ifdef M_UNIX /* SCO */
134 # include <sys/stream.h>
135 # include <sys/ptem.h>
136 # define ftruncate(fd, s) chsize(fd, s)
140 # define index strchr
141 # define rindex strrchr
142 # define bzero(poi,len) memset(poi,0,len)
144 # define killpg(pgrp,sig) kill( -(pgrp), sig)
148 # define getcwd(b,l) getwd(b)
153 # define bcopy(s,d,len) memmove(d,s,len)
156 # define bcopy(s,d,len) memcpy(d,s,len)
158 # define NEED_OWN_BCOPY
159 # define bcopy xbcopy
164 #if defined(HAVE_SETRESUID) && !defined(HAVE_SETREUID)
165 # define setreuid(ruid, euid) setresuid(ruid, euid, -1)
166 # define setregid(rgid, egid) setresgid(rgid, egid, -1)
169 #if defined(HAVE_SETEUID) || defined(HAVE_SETREUID) || defined(HAVE_SETRESUID)
173 #if !defined(HAVE__EXIT) && !defined(_exit)
174 #define _exit(x) exit(x)
178 # define utimes utime
180 #ifndef HAVE_VSNPRINTF
181 # define vsnprintf xvsnprintf
184 #ifdef BUILTIN_TELNET
185 # include <netinet/in.h>
186 # include <arpa/inet.h>
189 #if defined(USE_LOCALE) && (!defined(HAVE_SETLOCALE) || !defined(HAVE_STRFTIME))
193 /*****************************************************************
198 # include <termios.h>
216 # include <cytermio.h>
224 # ifdef _POSIX_VDISABLE
225 # define VDISABLE _POSIX_VDISABLE
227 # define VDISABLE 0377
228 # endif /* _POSIX_VDISABLE */
229 #endif /* !VDISABLE */
232 /* on sgi, regardless of the stream head's read mode (RNORM/RMSGN/RMSGD)
233 * TIOCPKT mode causes data loss if our buffer is too small (IOSIZE)
234 * to hold the whole packet at first read().
238 * TIOCPKT is broken on dgux 5.4.1 generic AViiON mc88100
240 * Joe Traister: On AIX4, programs like irc won't work if screen
241 * uses TIOCPKT (select fails to return on pty read).
243 #if defined(sgi) || defined(DGUX) || defined(_IBMR2)
247 /* linux ncurses is broken, we have to use our own tputs */
248 #if defined(linux) && defined(TERMINFO)
249 # define tputs xtputs
252 /* Alexandre Oliva: SVR4 style ptys don't work with osf */
254 # undef HAVE_SVR4_PTYS
257 /*****************************************************************
262 typedef char *slot_t
;
267 #if defined(UTMPOK) || defined(BUGGYGETLOGIN)
268 # if defined(SVR4) && !defined(DGUX) && !defined(__hpux) && !defined(linux)
270 # define UTMPFILE UTMPX_FILE
272 # define getutent getutxent
273 # define getutid getutxid
274 # define getutline getutxline
275 # define pututline pututxline
276 # define setutent setutxent
277 # define endutent endutxent
278 # define ut_time ut_xtime
284 * We don't have GETUTENT, so we dig into utmp ourselves.
285 * But we save the permanent filedescriptor and
286 * open utmp just when we need to.
287 * This code supports an unsorted utmp. jw.
294 # define UTMPFILE UTMP_FILE
297 # define UTMPFILE _PATH_UTMP
299 # define UTMPFILE "/etc/utmp"
300 # endif /* _PATH_UTMP */
304 #endif /* UTMPOK || BUGGYGETLOGIN */
306 #if !defined(UTMPOK) && defined(USRLIMIT)
311 # ifndef LOGINDEFAULT
312 # define LOGINDEFAULT 0
318 # define LOGINDEFAULT 1
322 /*****************************************************************
340 #define S_IFIFO 0010000
343 #define S_IREAD 0000400
346 #define S_IWRITE 0000200
349 #define S_IEXEC 0000100
352 #if defined(S_IFIFO) && defined(S_IFMT) && !defined(S_ISFIFO)
353 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
355 #if defined(S_IFSOCK) && defined(S_IFMT) && !defined(S_ISSOCK)
356 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
358 #if defined(S_IFCHR) && defined(S_IFMT) && !defined(S_ISCHR)
359 #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
361 #if defined(S_IFDIR) && defined(S_IFMT) && !defined(S_ISDIR)
362 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
364 #if defined(S_IFLNK) && defined(S_IFMT) && !defined(S_ISLNK)
365 #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
369 * SunOS 4.1.3: `man 2V open' has only one line that mentions O_NOBLOCK:
371 * O_NONBLOCK Same as O_NDELAY above.
373 * on the very same SunOS 4.1.3, I traced the open system call and found
374 * that an open("/dev/ttyy08", O_RDWR|O_NONBLOCK|O_NOCTTY) was blocked,
375 * whereas open("/dev/ttyy08", O_RDWR|O_NDELAY |O_NOCTTY) went through.
377 * For this simple reason I now favour O_NDELAY. jw. 4.5.95
379 #if defined(sun) && !defined(SVR4)
383 #if !defined(O_NONBLOCK) && defined(O_NDELAY)
384 # define O_NONBLOCK O_NDELAY
387 #if !defined(FNBLOCK) && defined(FNONBLOCK)
388 # define FNBLOCK FNONBLOCK
390 #if !defined(FNBLOCK) && defined(FNDELAY)
391 # define FNBLOCK FNDELAY
393 #if !defined(FNBLOCK) && defined(O_NONBLOCK)
394 # define FNBLOCK O_NONBLOCK
399 #define mkfifo(n,m) mknod(n,S_IFIFO|(m),0)
402 #if !defined(HAVE_LSTAT) && !defined(lstat)
406 /*****************************************************************
412 # define sigret_t void
414 # define SIGRETURN return 0;
415 # define sigret_t int
418 /* Geeeee, reverse it? */
419 #if defined(SVR4) || (defined(SYSV) && defined(ISC)) || defined(_AIX) || defined(linux) || defined(ultrix) || defined(__386BSD__) || defined(__bsdi__) || defined(POSIX) || defined(NeXT)
424 # define SIGPROTOARG (int)
425 # define SIGDEFARG (sigsig) int sigsig;
428 # define SIGPROTOARG (void)
429 # define SIGDEFARG ()
434 #define SIGCHLD SIGCLD
437 #if defined(POSIX) || defined(hpux)
438 # define signal xsignal
441 # define signal sigset
442 # endif /* USESIGSET */
445 /* used in screen.c and attacher.c */
446 #ifndef NSIG /* kbeal needs these w/o SYSV */
451 /*****************************************************************
455 #if (!defined(sysV68) && !defined(M_XENIX)) || defined(NeXT) || defined(M_UNIX)
456 # include <sys/wait.h>
460 # ifndef BSDWAIT /* if wait is NOT a union: */
461 # define WTERMSIG(status) (status & 0177)
463 # define WTERMSIG(status) status.w_T.w_Termsig
468 # ifndef BSDWAIT /* if wait is NOT a union: */
469 # define WSTOPSIG(status) ((status >> 8) & 0377)
471 # define WSTOPSIG(status) status.w_S.w_Stopsig
475 /* NET-2 uses WCOREDUMP */
476 #if defined(WCOREDUMP) && !defined(WIFCORESIG)
477 # define WIFCORESIG(status) WCOREDUMP(status)
481 # ifndef BSDWAIT /* if wait is NOT a union: */
482 # define WIFCORESIG(status) (status & 0200)
484 # define WIFCORESIG(status) status.w_T.w_Coredump
489 # ifndef BSDWAIT /* if wait is NOT a union: */
490 # define WEXITSTATUS(status) ((status >> 8) & 0377)
492 # define WEXITSTATUS(status) status.w_T.w_Retcode
497 /*****************************************************************
501 #if defined(M_XENIX) || defined(M_UNIX) || defined(_SEQUENT_)
502 #include <sys/select.h> /* for timeval + FD... */
506 * SunOS 3.5 - Tom Schmidt - Micron Semiconductor, Inc - 27-Jul-93
507 * tschmidt@vax.micron.com
511 typedef struct fd_set
{ int fds_bits
[1]; } fd_set
;
513 # define FD_ZERO(fd) ((fd)->fds_bits[0] = 0)
514 # define FD_SET(b, fd) ((fd)->fds_bits[0] |= 1 << (b))
515 # define FD_ISSET(b, fd) ((fd)->fds_bits[0] & 1 << (b))
516 # define FD_SETSIZE 32
520 /*****************************************************************
521 * user defineable stuff
524 #ifndef TERMCAP_BUFSIZE
525 # define TERMCAP_BUFSIZE 2048
529 # define MAXPATHLEN 1024
533 * you may try to vary this value. Use low values if your (VMS) system
534 * tends to choke when pasting. Use high values if you want to test
535 * how many characters your pty's can buffer.