Main Page | Class List | File List | Class Members | File Members

os.h

Go to the documentation of this file.
00001 /* Copyright (c) 1993-2002
00002  *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
00003  *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
00004  * Copyright (c) 1987 Oliver Laumann
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program (see the file COPYING); if not, write to the
00018  * Free Software Foundation, Inc.,
00019  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
00020  *
00021  ****************************************************************
00022  * $Id: os.h,v 1.10 1994/05/31 12:32:22 mlschroe Exp $ FAU
00023  */
00024 
00025 #include <stdio.h>
00026 #include <errno.h>
00027 
00028 #include <sys/param.h>
00029 
00030 /* In strict ANSI mode, HP-UX machines define __hpux but not hpux */
00031 #if defined(__hpux) && !defined(hpux)
00032 # define hpux
00033 #endif
00034 
00035 #if defined(__bsdi__) || defined(__386BSD__) || defined(_CX_UX) || defined(hpux) || defined(_IBMR2) || defined(linux)
00036 # include <signal.h>
00037 #endif /* __bsdi__ || __386BSD__ || _CX_UX || hpux || _IBMR2 || linux */
00038 
00039 #ifdef ISC
00040 # ifdef ENAMETOOLONG
00041 #  undef ENAMETOOLONG
00042 # endif
00043 # ifdef ENOTEMPTY
00044 #  undef ENOTEMPTY
00045 # endif
00046 # include <sys/bsdtypes.h>
00047 # include <net/errno.h>
00048 #endif
00049 
00050 #ifdef sun
00051 # define getpgrp __getpgrp
00052 # define exit __exit
00053 #endif
00054 #ifdef POSIX
00055 # include <unistd.h>
00056 # if defined(__STDC__)
00057 #  include <stdlib.h>
00058 # endif /* __STDC__ */
00059 #endif /* POSIX */
00060 #ifdef sun
00061 # undef getpgrp
00062 # undef exit
00063 #endif /* sun */
00064 
00065 #ifndef linux /* all done in <errno.h> */
00066 extern int errno;
00067 #endif /* linux */
00068 #ifndef HAVE_STRERROR
00069 /* No macros, please */
00070 #undef strerror
00071 #endif
00072 
00073 #if !defined(SYSV) && !defined(linux)
00074 # ifdef NEWSOS
00075 #  define strlen ___strlen___
00076 #  include <strings.h>
00077 #  undef strlen
00078 # else /* NEWSOS */
00079 #  include <strings.h>
00080 # endif /* NEWSOS */
00081 #else /* SYSV */
00082 # if defined(SVR4) || defined(NEWSOS)
00083 #  define strlen ___strlen___
00084 #  include <string.h>
00085 #  undef strlen
00086 #  if !defined(NEWSOS) && !defined(__hpux)
00087     extern size_t strlen(const char *);
00088 #  endif
00089 # else /* SVR4 */
00090 #  include <string.h>
00091 # endif /* SVR4 */
00092 #endif /* SYSV */
00093 
00094 #ifdef USEVARARGS
00095 # if defined(__STDC__)
00096 #  include <stdarg.h>
00097 #  define VA_LIST(var) va_list var;
00098 #  define VA_DOTS ...
00099 #  define VA_DECL
00100 #  define VA_START(ap, fmt) va_start(ap, fmt)
00101 #  define VA_ARGS(ap) ap
00102 #  define VA_END(ap) va_end(ap)
00103 # else
00104 #  include <varargs.h>
00105 #  define VA_LIST(var) va_list var;
00106 #  define VA_DOTS va_alist
00107 #  define VA_DECL va_dcl
00108 #  define VA_START(ap, fmt) va_start(ap)
00109 #  define VA_ARGS(ap) ap
00110 #  define VA_END(ap) va_end(ap)
00111 # endif
00112 #else
00113 # define VA_LIST(var)
00114 # define VA_DOTS p1, p2, p3, p4, p5, p6
00115 # define VA_DECL unsigned long VA_DOTS;
00116 # define VA_START(ap, fmt)
00117 # define VA_ARGS(ap) VA_DOTS
00118 # define VA_END(ap)
00119 # undef vsnprintf
00120 # define vsnprintf xsnprintf
00121 #endif
00122 
00123 #if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
00124 # include <time.h>
00125 #endif
00126 #include <sys/time.h>
00127 
00128 #ifdef M_UNIX   /* SCO */
00129 # include <sys/stream.h>
00130 # include <sys/ptem.h>
00131 # define ftruncate(fd, s) chsize(fd, s)
00132 #endif
00133 
00134 #ifdef SYSV
00135 # define index strchr
00136 # define rindex strrchr
00137 # define bzero(poi,len) memset(poi,0,len)
00138 # define bcmp memcmp
00139 # define killpg(pgrp,sig) kill( -(pgrp), sig)
00140 #endif
00141 
00142 #ifndef HAVE_GETCWD
00143 # define getcwd(b,l) getwd(b)
00144 #endif
00145 
00146 #ifndef USEBCOPY
00147 # ifdef USEMEMMOVE
00148 #  define bcopy(s,d,len) memmove(d,s,len)
00149 # else
00150 #  ifdef USEMEMCPY
00151 #   define bcopy(s,d,len) memcpy(d,s,len)
00152 #  else
00153 #   define NEED_OWN_BCOPY
00154 #   define bcopy xbcopy
00155 #  endif
00156 # endif
00157 #endif
00158 
00159 #ifdef hpux
00160 # define setreuid(ruid, euid) setresuid(ruid, euid, -1)
00161 # define setregid(rgid, egid) setresgid(rgid, egid, -1)
00162 #endif
00163 
00164 #if defined(HAVE_SETEUID) || defined(HAVE_SETREUID)
00165 # define USE_SETEUID
00166 #endif
00167 
00168 #if !defined(HAVE__EXIT) && !defined(_exit)
00169 #define _exit(x) exit(x)
00170 #endif
00171 
00172 #ifndef HAVE_UTIMES
00173 # define utimes utime
00174 #endif
00175 #ifndef HAVE_VSNPRINTF
00176 # define vsnprintf xvsnprintf
00177 #endif
00178 
00179 #ifdef BUILTIN_TELNET
00180 # include <netinet/in.h>
00181 # include <arpa/inet.h>
00182 #endif
00183 
00184 #if defined(USE_LOCALE) && (!defined(HAVE_SETLOCALE) || !defined(HAVE_STRFTIME))
00185 # undef USE_LOCALE
00186 #endif
00187 
00188 /*****************************************************************
00189  *    terminal handling
00190  */
00191 
00192 #ifdef POSIX
00193 # include <termios.h>
00194 # ifdef hpux
00195 #  include <bsdtty.h>
00196 # endif /* hpux */
00197 # ifdef NCCS
00198 #  define MAXCC NCCS
00199 # else
00200 #  define MAXCC 256
00201 # endif
00202 #else /* POSIX */
00203 # ifdef TERMIO
00204 #  include <termio.h>
00205 #  ifdef NCC
00206 #   define MAXCC NCC
00207 #  else
00208 #   define MAXCC 256
00209 #  endif
00210 #  ifdef CYTERMIO
00211 #   include <cytermio.h>
00212 #  endif
00213 # else /* TERMIO */
00214 #  include <sgtty.h>
00215 # endif /* TERMIO */
00216 #endif /* POSIX */
00217 
00218 #ifndef VDISABLE
00219 # ifdef _POSIX_VDISABLE
00220 #  define VDISABLE _POSIX_VDISABLE
00221 # else
00222 #  define VDISABLE 0377
00223 # endif /* _POSIX_VDISABLE */
00224 #endif /* !VDISABLE */
00225 
00226 
00227 /* on sgi, regardless of the stream head's read mode (RNORM/RMSGN/RMSGD)
00228  * TIOCPKT mode causes data loss if our buffer is too small (IOSIZE)
00229  * to hold the whole packet at first read().
00230  * (Marc Boucher)
00231  *
00232  * matthew green:
00233  * TIOCPKT is broken on dgux 5.4.1 generic AViiON mc88100
00234  *
00235  * Joe Traister: On AIX4, programs like irc won't work if screen
00236  * uses TIOCPKT (select fails to return on pty read).
00237  */
00238 #if defined(sgi) || defined(DGUX) || defined(_IBMR2)
00239 # undef TIOCPKT
00240 #endif
00241 
00242 /* linux ncurses is broken, we have to use our own tputs */
00243 #if defined(linux) && defined(TERMINFO)
00244 # define tputs xtputs
00245 #endif
00246 
00247 /* Alexandre Oliva: SVR4 style ptys don't work with osf */
00248 #ifdef __osf__
00249 # undef HAVE_SVR4_PTYS
00250 #endif
00251 
00252 /*****************************************************************
00253  *   utmp handling
00254  */
00255 
00256 #ifdef GETUTENT
00257   typedef char *slot_t;
00258 #else
00259   typedef int slot_t;
00260 #endif
00261 
00262 #if defined(UTMPOK) || defined(BUGGYGETLOGIN)
00263 # if defined(SVR4) && !defined(DGUX) && !defined(__hpux) && !defined(linux)
00264 #  include <utmpx.h>
00265 #  define UTMPFILE      UTMPX_FILE
00266 #  define utmp          utmpx
00267 #  define getutent      getutxent
00268 #  define getutid       getutxid
00269 #  define getutline     getutxline
00270 #  define pututline     pututxline
00271 #  define setutent      setutxent
00272 #  define endutent      endutxent
00273 #  define ut_time       ut_xtime
00274 # else /* SVR4 */
00275 #  include <utmp.h>
00276 # endif /* SVR4 */
00277 # ifdef apollo
00278    /* 
00279     * We don't have GETUTENT, so we dig into utmp ourselves.
00280     * But we save the permanent filedescriptor and
00281     * open utmp just when we need to. 
00282     * This code supports an unsorted utmp. jw.
00283     */
00284 #  define UTNOKEEP
00285 # endif /* apollo */
00286 
00287 # ifndef UTMPFILE
00288 #  ifdef UTMP_FILE
00289 #   define UTMPFILE     UTMP_FILE
00290 #  else
00291 #   ifdef _PATH_UTMP
00292 #    define UTMPFILE    _PATH_UTMP
00293 #   else
00294 #    define UTMPFILE    "/etc/utmp"
00295 #   endif /* _PATH_UTMP */
00296 #  endif
00297 # endif
00298 
00299 #endif /* UTMPOK || BUGGYGETLOGIN */
00300 
00301 #if !defined(UTMPOK) && defined(USRLIMIT)
00302 # undef USRLIMIT
00303 #endif
00304 
00305 #ifdef LOGOUTOK
00306 # ifndef LOGINDEFAULT
00307 #  define LOGINDEFAULT 0
00308 # endif
00309 #else
00310 # ifdef LOGINDEFAULT
00311 #  undef LOGINDEFAULT
00312 # endif
00313 # define LOGINDEFAULT 1
00314 #endif
00315 
00316 
00317 /*****************************************************************
00318  *    file stuff
00319  */
00320 
00321 #ifndef F_OK
00322 #define F_OK 0
00323 #endif
00324 #ifndef X_OK
00325 #define X_OK 1
00326 #endif
00327 #ifndef W_OK
00328 #define W_OK 2
00329 #endif
00330 #ifndef R_OK
00331 #define R_OK 4
00332 #endif
00333 
00334 #ifndef S_IFIFO
00335 #define S_IFIFO  0010000
00336 #endif
00337 #ifndef S_IREAD
00338 #define S_IREAD  0000400
00339 #endif
00340 #ifndef S_IWRITE
00341 #define S_IWRITE 0000200
00342 #endif
00343 #ifndef S_IEXEC
00344 #define S_IEXEC  0000100
00345 #endif
00346 
00347 #if defined(S_IFIFO) && defined(S_IFMT) && !defined(S_ISFIFO)
00348 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
00349 #endif
00350 #if defined(S_IFSOCK) && defined(S_IFMT) && !defined(S_ISSOCK)
00351 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
00352 #endif
00353 #if defined(S_IFCHR) && defined(S_IFMT) && !defined(S_ISCHR)
00354 #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
00355 #endif
00356 #if defined(S_IFDIR) && defined(S_IFMT) && !defined(S_ISDIR)
00357 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
00358 #endif
00359 #if defined(S_IFLNK) && defined(S_IFMT) && !defined(S_ISLNK)
00360 #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
00361 #endif
00362 
00363 /*
00364  * SunOS 4.1.3: `man 2V open' has only one line that mentions O_NOBLOCK:
00365  *
00366  *     O_NONBLOCK     Same as O_NDELAY above.
00367  *
00368  * on the very same SunOS 4.1.3, I traced the open system call and found
00369  * that an open("/dev/ttyy08", O_RDWR|O_NONBLOCK|O_NOCTTY) was blocked,
00370  * whereas open("/dev/ttyy08", O_RDWR|O_NDELAY  |O_NOCTTY) went through.
00371  *
00372  * For this simple reason I now favour O_NDELAY. jw. 4.5.95
00373  */
00374 #if defined(sun) && !defined(SVR4)
00375 # undef O_NONBLOCK
00376 #endif
00377 
00378 #if !defined(O_NONBLOCK) && defined(O_NDELAY)
00379 # define O_NONBLOCK O_NDELAY
00380 #endif
00381 
00382 #if !defined(FNBLOCK) && defined(FNONBLOCK)
00383 # define FNBLOCK FNONBLOCK
00384 #endif
00385 #if !defined(FNBLOCK) && defined(FNDELAY)
00386 # define FNBLOCK FNDELAY
00387 #endif
00388 #if !defined(FNBLOCK) && defined(O_NONBLOCK)
00389 # define FNBLOCK O_NONBLOCK
00390 #endif
00391 
00392 #ifndef POSIX
00393 #undef mkfifo
00394 #define mkfifo(n,m) mknod(n,S_IFIFO|(m),0)
00395 #endif
00396 
00397 #if !defined(HAVE_LSTAT) && !defined(lstat)
00398 # define lstat stat
00399 #endif
00400 
00401 /*****************************************************************
00402  *    signal handling
00403  */
00404 
00405 #ifdef SIGVOID
00406 # define SIGRETURN
00407 # define sigret_t void
00408 #else
00409 # define SIGRETURN return 0;
00410 # define sigret_t int
00411 #endif
00412 
00413 /* Geeeee, reverse it? */
00414 #if defined(SVR4) || (defined(SYSV) && defined(ISC)) || defined(_AIX) || defined(linux) || defined(ultrix) || defined(__386BSD__) || defined(__bsdi__) || defined(POSIX) || defined(NeXT)
00415 # define SIGHASARG
00416 #endif
00417 
00418 #ifdef SIGHASARG
00419 # define SIGPROTOARG   (int)
00420 # define SIGDEFARG     (sigsig) int sigsig;
00421 # define SIGARG        0
00422 #else
00423 # define SIGPROTOARG   (void)
00424 # define SIGDEFARG     ()
00425 # define SIGARG
00426 #endif
00427 
00428 #ifndef SIGCHLD
00429 #define SIGCHLD SIGCLD
00430 #endif
00431 
00432 #if defined(POSIX) || defined(hpux)
00433 # define signal xsignal
00434 #else
00435 # ifdef USESIGSET
00436 #  define signal sigset
00437 # endif /* USESIGSET */
00438 #endif
00439 
00440 /* used in screen.c and attacher.c */
00441 #ifndef NSIG            /* kbeal needs these w/o SYSV */
00442 # define NSIG 32
00443 #endif /* !NSIG */
00444 
00445 
00446 /*****************************************************************
00447  *    Wait stuff
00448  */
00449 
00450 #if (!defined(sysV68) && !defined(M_XENIX)) || defined(NeXT) || defined(M_UNIX)
00451 # include <sys/wait.h>
00452 #endif
00453 
00454 #ifndef WTERMSIG
00455 # ifndef BSDWAIT /* if wait is NOT a union: */
00456 #  define WTERMSIG(status) (status & 0177)
00457 # else
00458 #  define WTERMSIG(status) status.w_T.w_Termsig 
00459 # endif
00460 #endif
00461 
00462 #ifndef WSTOPSIG
00463 # ifndef BSDWAIT /* if wait is NOT a union: */
00464 #  define WSTOPSIG(status) ((status >> 8) & 0377)
00465 # else
00466 #  define WSTOPSIG(status) status.w_S.w_Stopsig 
00467 # endif
00468 #endif
00469 
00470 /* NET-2 uses WCOREDUMP */
00471 #if defined(WCOREDUMP) && !defined(WIFCORESIG)
00472 # define WIFCORESIG(status) WCOREDUMP(status)
00473 #endif
00474 
00475 #ifndef WIFCORESIG
00476 # ifndef BSDWAIT /* if wait is NOT a union: */
00477 #  define WIFCORESIG(status) (status & 0200)
00478 # else
00479 #  define WIFCORESIG(status) status.w_T.w_Coredump
00480 # endif
00481 #endif
00482 
00483 #ifndef WEXITSTATUS
00484 # ifndef BSDWAIT /* if wait is NOT a union: */
00485 #  define WEXITSTATUS(status) ((status >> 8) & 0377)
00486 # else
00487 #  define WEXITSTATUS(status) status.w_T.w_Retcode
00488 # endif
00489 #endif
00490 
00491 
00492 /*****************************************************************
00493  *    select stuff
00494  */
00495 
00496 #if defined(M_XENIX) || defined(M_UNIX) || defined(_SEQUENT_)
00497 #include <sys/select.h>         /* for timeval + FD... */
00498 #endif
00499 
00500 /*
00501  * SunOS 3.5 - Tom Schmidt - Micron Semiconductor, Inc - 27-Jul-93
00502  * tschmidt@vax.micron.com
00503  */
00504 #ifndef FD_SET
00505 # ifndef SUNOS3
00506 typedef struct fd_set { int fds_bits[1]; } fd_set;
00507 # endif
00508 # define FD_ZERO(fd) ((fd)->fds_bits[0] = 0)
00509 # define FD_SET(b, fd) ((fd)->fds_bits[0] |= 1 << (b))
00510 # define FD_ISSET(b, fd) ((fd)->fds_bits[0] & 1 << (b))
00511 # define FD_SETSIZE 32
00512 #endif
00513 
00514 
00515 /*****************************************************************
00516  *    user defineable stuff
00517  */
00518 
00519 #ifndef TERMCAP_BUFSIZE
00520 # define TERMCAP_BUFSIZE 2048
00521 #endif
00522 
00523 #ifndef MAXPATHLEN
00524 # define MAXPATHLEN 1024
00525 #endif
00526 
00527 /* 
00528  * you may try to vary this value. Use low values if your (VMS) system
00529  * tends to choke when pasting. Use high values if you want to test
00530  * how many characters your pty's can buffer.
00531  */
00532 #define IOSIZE          4096
00533 

Generated on Sat Jul 2 20:56:16 2005 for GNU Screen by  doxygen 1.4.3