ckutio.c
资源名称:cku197.tar.Z [点击查看]
上传用户:dufan58
上传日期:2007-01-05
资源大小:3407k
文件大小:361k
源码类别:
通讯/手机编程
开发平台:
Windows_Unix
- #ifdef aegis
- char *ckxv = "Aegis Communications support, 7.0.231, 31 Dec 1999";
- #else
- #ifdef Plan9
- char *ckxv = "Plan 9 Communications support, 7.0.231, 31 Dec 1999";
- #else
- char *ckxv = "UNIX Communications support, 7.0.231, 31 Dec 1999";
- #endif /* Plan9 */
- #endif /* aegis */
- /* C K U T I O */
- /* C-Kermit interrupt, communications control and I/O functions for UNIX */
- /*
- Author: Frank da Cruz (fdc@columbia.edu),
- Columbia University Academic Information Systems, New York City.
- Copyright (C) 1985, 2000,
- Trustees of Columbia University in the City of New York.
- All rights reserved. See the C-Kermit COPYING.TXT file or the
- copyright text in the ckcmai.c module for disclaimer and permissions.
- */
- /*
- NOTE TO CONTRIBUTORS: This file, and all the other C-Kermit files, must be
- compatible with C preprocessors that support only #ifdef, #else, #endif,
- #define, and #undef. Please do not use #if, logical operators, or other
- preprocessor features in any of the portable C-Kermit modules. You can,
- of course, use these constructions in platform-specific modules when they
- are supported by all compilers/preprocessors that could be used on that
- platform.
- */
- extern int nettype; /* Defined in ckcmai.c */
- /* Includes */
- #include "ckcsym.h" /* This must go first */
- #include "ckcdeb.h" /* This must go second */
- #ifdef OSF13
- #ifdef CK_ANSIC
- #ifdef _NO_PROTO
- #undef _NO_PROTO
- #endif /* _NO_PROTO */
- #endif /* CK_ANSIC */
- #endif /* OSF13 */
- #include <errno.h> /* System error numbers */
- #ifdef __386BSD__
- #define ENOTCONN 57
- #else
- #ifdef __bsdi__
- #define ENOTCONN 57
- #else
- #ifdef __FreeBSD__
- #define ENOTCONN 57
- #endif /* __FreeBSD__ */
- #endif /* __bsdi__ */
- #endif /* __386BSD__ */
- #ifdef SCO_OSR504
- #define NBBY 8
- #endif /* SCO_OSR504 */
- #ifdef Plan9
- #define SELECT
- #include <sys/time.h>
- #include <select.h>
- #define FD_SETSIZE (3 * sizeof(long) * 8)
- static struct timeval tv;
- #endif /* Plan9 */
- #ifdef CLIX
- #include <sys/time.h>
- #endif /* CLIX */
- #include "ckcnet.h" /* Symbols for network types. */
- #ifdef CK_SSL
- #include "ck_ssl.h"
- #endif /* CK_SSL */
- /*
- The directory-related includes are here because we need to test some
- file-system-related symbols to find out which system we're being compiled
- under. For example, MAXNAMLEN is defined in BSD4.2 but not 4.1.
- */
- #ifdef SDIRENT /* Directory bits... */
- #define DIRENT
- #endif /* SDIRENT */
- #ifdef XNDIR
- #include <sys/ndir.h>
- #else /* !XNDIR */
- #ifdef NDIR
- #include <ndir.h>
- #else /* !NDIR, !XNDIR */
- #ifdef RTU
- #include "/usr/lib/ndir.h"
- #else /* !RTU, !NDIR, !XNDIR */
- #ifdef DIRENT
- #ifdef SDIRENT
- #include <sys/dirent.h>
- #else
- #include <dirent.h>
- #endif /* SDIRENT */
- #else /* !RTU, !NDIR, !XNDIR, !DIRENT, i.e. all others */
- #include <sys/dir.h>
- #endif /* DIRENT */
- #endif /* RTU */
- #endif /* NDIR */
- #endif /* XNDIR */
- #ifdef QNX
- #include <sys/dev.h>
- #endif /* QNX */
- #ifdef HPUX5
- #ifndef TCPSOCKET
- /* I don't know why this is needed here since we never reference bzero(). */
- /* But without it C-Kermit won't link in an HP-UX 5.xx non-TCP build. */
- void
- bzero(s,n) char *s; int n; {
- extern char * memset();
- memset(s,0,n);
- }
- #endif /* TCPSOCKET */
- #endif /* HPUX5 */
- /* Definition of HZ, used in msleep() */
- #ifdef MIPS
- #define HZ ( 1000 / CLOCK_TICK )
- #else
- #ifdef ATTSV
- #ifndef NAP
- #ifndef TRS16
- #include <sys/param.h>
- #else
- #define HZ ( 1000 / CLOCK_TICK )
- #endif /* TRS16 */
- #ifdef NAPHACK
- #define nap(x) (void)syscall(3112, (x))
- #define NAP
- #endif /* NAPHACK */
- #endif /* NAP */
- #endif /* ATTSV */
- #endif /* MIPS */
- #ifdef M_UNIX
- #undef NGROUPS_MAX /* Prevent multiple definition warnings */
- #endif /* M_UNIX */
- /*
- NOTE: HP-UX 8.0 has a <sys/poll.h>, but there is no corresponding
- library routine, so _poll comes up undefined at link time.
- */
- #ifdef CK_POLL
- #ifndef AIXRS /* IBM AIX needs special handling */
- #include <poll.h> /* "standard" (SVID) i/o multiplexing, etc */
- #else /* AIXRS */
- #ifdef SVR4 /* AIX 3.2 is like SVID... */
- #include <poll.h>
- #else /* But AIX 3.1 is not ... */
- #include <sys/poll.h> /* The include file is in include/sys */
- #define events reqevents /* And it does not map IBM-specific member */
- #define revents rtnevents /* names to the System V equivalents */
- #endif /* SVR4 */
- #endif /* AIXRS */
- #endif /* CK_POLL */
- #include <signal.h> /* Signals */
- /* For setjmp and longjmp */
- #ifndef ZILOG
- #include <setjmp.h>
- #else
- #include <setret.h>
- #endif /* ZILOG */
- /* Maximum length for the name of a tty device */
- #ifndef DEVNAMLEN
- #define DEVNAMLEN 32
- #endif /* DEVNAMLEN */
- #ifdef NETCONN
- #undef DEVNAMLEN
- #define DEVNAMLEN 256 /* Longer field for host:service */
- #endif /* NETCONN */
- /*
- The following test differentiates between 4.1 BSD and 4.2 & later.
- If you have a 4.1BSD system with the DIRENT library, this test could
- mistakenly diagnose 4.2BSD and then later enable the use of system calls
- that aren't defined. If indeed there are such systems, we can use some
- other way of testing for 4.1BSD, or add yet another compile-time switch.
- */
- #ifdef BSD4
- #ifdef MAXNAMLEN
- #ifndef FT21 /* Except for Fortune. */
- #ifndef FT18
- #ifndef BELLV10 /* And Bell Labs Research UNIX V10 */
- #define BSD42
- #endif /* BELLV10 */
- #endif /* FT18 */
- #endif /* FT21 */
- #endif /* MAXNAMLEN */
- #endif /* BSD4 */
- /*
- Minix 2.0 support added by Terry McConnell,
- Syracuse University <tmc@barnyard.syr.edu>
- No more sgtty interface, posix compliant.
- */
- #ifdef MINIX2
- #define _MINIX /* Needed for some Minix header files */
- #undef MINIX /* Old minix 1.0: used sgtty interface */
- #define BSD44ORPOSIX
- #define SVORPOSIX
- #define DCLTIMEVAL
- #define NOFILEH
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <termios.h>
- #include <limits.h>
- #undef TIOCGETC /* defined in sys/ioctl.h, but not really supported */
- #define TANDEM 0
- #endif /* MINIX2 */
- /*
- MINIX 1.0 support added by Charles Hedrick,
- Rutgers University <hedrick@aramis.rutgers.edu>.
- MINIX also has V7 enabled.
- */
- #ifdef MINIX
- #define TANDEM 0
- #define MYREAD
- #define NOSYSIOCTLH
- #include <limits.h>
- #endif /* MINIX */
- #ifdef CK_REDIR /* <sys/wait.h> needed only for REDIRECT command. */
- /*
- If anybody can figure out how to make this work with NeXTSTEP, be
- my guest! (NeXTBlah/NeXTBlah/bsd/sys/wait.h does not define WEXITSTATUS)
- */
- #ifndef CK_WAIT_H /* If wait.h not already included... */
- #include <sys/wait.h> /* Include it */
- #endif /* CK_WAIT_H */
- #endif /* CK_REDIR */
- #include "ckuver.h" /* Version herald */
- char *ckxsys = HERALD;
- #ifdef CK_UTSNAME
- #include <sys/utsname.h>
- #ifdef UW7
- #ifndef SYS_NMLN
- #define SYS_NMLN 257
- #endif /* NMLN */
- #endif /* UW7 */
- #ifdef HPUX9PLUS
- static int hpis800 = 0;
- #endif /* HPUX9PLUS */
- #ifdef SYS_NMLN
- #define CK_SYSNMLN SYS_NMLN
- #else
- #ifdef _SYS_NMLN
- #define CK_SYSNMLN _SYS_NMLN
- #else
- #ifdef UTSLEN
- #define CK_SYSNMLN UTSLEN
- #else
- #define CK_SYSNMLN 31
- #endif /* UTSLEN */
- #endif /* _SYS_NMLN */
- #endif /* SYS_NMLN */
- char unm_mch[CK_SYSNMLN+1] = { ' ', ' ' };
- char unm_mod[CK_SYSNMLN+1] = { ' ', ' ' };
- char unm_nam[CK_SYSNMLN+1] = { ' ', ' ' };
- char unm_rel[CK_SYSNMLN+1] = { ' ', ' ' };
- char unm_ver[CK_SYSNMLN+1] = { ' ', ' ' };
- #endif /* CK_UTSNAME */
- #ifdef CIE
- #include <stat.h> /* For chasing symlinks, etc. */
- #else
- #include <sys/stat.h>
- #endif /* CIE */
- /* UUCP lockfile material... */
- #ifndef NOUUCP
- #ifdef USETTYLOCK
- #ifdef USE_UU_LOCK
- #include <libutil.h>
- #endif /* USE_UU_LOCK */
- #else /* USETTYLOCK */
- /* Name of UUCP tty device lockfile */
- #ifdef LINUXFSSTND
- #ifndef HDBUUCP
- #define HDBUUCP
- #endif /* HDBUUCP */
- #endif /* LINUXFSSTND */
- #ifdef ACUCNTRL
- #define LCKDIR
- #endif /* ACUCNTRL */
- /*
- PIDSTRING means use ASCII string to represent pid in lockfile.
- */
- #ifndef PIDSTRING
- #ifdef HDBUUCP
- #define PIDSTRING
- #else
- #ifdef BSD44
- #define PIDSTRING
- #else
- #ifdef RTAIX
- #define PIDSTRING
- #else
- #ifdef AIXRS
- #define PIDSTRING
- #else
- #ifdef COHERENT
- #define PIDSTRING
- #endif /* COHERENT */
- #endif /* AIXRS */
- #endif /* RTAIX */
- #endif /* BSD44 */
- #endif /* HDBUUCP */
- #endif /* PIDSTRING */
- /* Now the PIDSTRING exceptions... */
- #ifdef PIDSTRING
- #ifdef HPUX
- #undef PIDSTRING
- #endif /* HPUX */
- #endif /* PIDSTRING */
- #ifdef __bsdi__ /* BSDI (at least thru 1.1) */
- #ifdef PIDSTRING
- #undef PIDSTRING
- #endif /* PIDSTRING */
- #endif /* __bsdi__ */
- #ifdef OSF32 /* Digital UNIX (OSF/1) 3.2 */
- #ifdef PIDSTRING
- #undef PIDSTRING
- #endif /* PIDSTRING */
- #endif /* OSF32 */
- /*
- LOCK_DIR is the name of the lockfile directory.
- If LOCK_DIR is already defined (e.g. on command line), we don't change it.
- */
- #ifndef LOCK_DIR
- #ifdef BSD44
- #ifdef __386BSD__
- #define LOCK_DIR "/var/spool/lock"
- #else
- #ifdef __FreeBSD__
- #define LOCK_DIR "/var/spool/lock"
- #else
- #ifdef __NetBSD__
- #define LOCK_DIR "/var/spool/lock"
- #else
- #define LOCK_DIR "/var/spool/uucp"
- #endif /* __NetBSD__ */
- #endif /* __FreeBSD__ */
- #endif /* __386BSD__ */
- #else
- #ifdef DGUX430
- #define LOCK_DIR "/var/spool/locks"
- #else
- #ifdef HPUX10
- #define LOCK_DIR "/var/spool/locks"
- #else
- #ifdef RTAIX /* IBM RT PC AIX 2.2.1 */
- #define LOCK_DIR "/etc/locks"
- #else
- #ifdef AIXRS
- #define LOCK_DIR "/etc/locks"
- #else
- #ifdef ISIII
- #define LOCK_DIR "/etc/locks"
- #else
- #ifdef HDBUUCP
- #ifdef M_SYS5
- #define LOCK_DIR "/usr/spool/uucp"
- #else
- #ifdef M_UNIX
- #define LOCK_DIR "/usr/spool/uucp"
- #else
- #ifdef SVR4
- #define LOCK_DIR "/var/spool/locks"
- #else
- #ifdef SUNOS4
- #define LOCK_DIR "/var/spool/locks"
- #else
- #ifdef LINUXFSSTND
- #define LOCK_DIR "/var/lock";
- #else
- #define LOCK_DIR "/usr/spool/locks"
- #endif /* LINUXFSSTND */
- #endif /* SUNOS4 */
- #endif /* SVR4 */
- #endif /* M_UNIX */
- #endif /* M_SYS5 */
- #else
- #ifdef LCKDIR
- #define LOCK_DIR "/usr/spool/uucp/LCK"
- #else
- #ifdef COHERENT
- #define LOCK_DIR "/usr/spool/uucp"
- #else
- #define LOCK_DIR "/usr/spool/uucp"
- #endif /* COHERENT */
- #endif /* LCKDIR */
- #endif /* HDBUUCP */
- #endif /* ISIII */
- #endif /* AIXRS */
- #endif /* RTAIX */
- #endif /* HPUX10 */
- #endif /* DGUX430 */
- #endif /* BSD44 */
- #endif /* !LOCK_DIR (outside ifndef) */
- #ifdef OSF2 /* OSF/1 2.0 or later */
- #ifdef LOCK_DIR /* (maybe 1.x too, who knows...) */
- #undef LOCK_DIR
- #define LOCK_DIR "/var/spool/locks"
- #endif /* LOCK_DIR */
- #endif /* OSF2 */
- #ifdef SVR4
- #ifndef BSD44
- #ifndef LOCKF
- #define LOCKF /* Use lockf() on tty device in SVR4 */
- #endif /* LOCKF */
- #endif /* BSD44 */
- #endif /* SVR4 */
- #ifdef NOLOCKF /* But NOLOCKF cancels LOCKF */
- #ifdef LOCKF
- #undef LOCKF
- #endif /* LOCKF */
- #endif /* NOLOCKF */
- /* More about this below... */
- #endif /* USETTYLOCK */
- #endif /* NOUUCP */
- /*
- MYREAD means use our internally defined nonblocking buffered read routine.
- */
- #ifdef ATTSV
- #define MYREAD
- #endif /* ATTSV */
- #ifdef ATT7300
- #ifndef MYREAD
- #define MYREAD
- #endif /* MYREAD */
- /* bits for attmodem: internal modem in use, restart getty */
- #define ISMODEM 1
- #define DOGETY 512
- #endif /* ATT7300 */
- #ifdef BSD42
- #define MYREAD
- #endif /* BSD42 */
- #ifdef POSIX
- #define MYREAD
- #endif /* POSIX */
- #ifdef __bsdi__
- #ifndef O_NDELAY
- #define O_NDELAY O_NONBLOCK
- #endif /* O_NDELAY */
- #endif /* __bsdi__ */
- /*
- Variables available to outside world:
- dftty -- Pointer to default tty name string, like "/dev/tty".
- dfloc -- 0 if dftty is console, 1 if external line.
- dfprty -- Default parity
- dfflow -- Default flow control
- ckxech -- Flag for who echoes console typein:
- 1 - The program (system echo is turned off)
- 0 - The system (or front end, or terminal).
- functions that want to do their own echoing should check this flag
- before doing so.
- flfnam -- Name of lock file, including its path, e.g.,
- "/usr/spool/uucp/LCK..cul0" or "/etc/locks/tty77"
- lkflfn -- Name of link to lock file, including its paths
- haslock -- Flag set if this kermit established a uucp lock.
- lockpid -- PID of other process that has desired line open, as string.
- backgrd -- Flag indicating program executing in background ( & on
- end of shell command). Used to ignore INT and QUIT signals.
- rtu_bug -- Set by stptrap(). RTU treats ^Z as EOF (but only when we handle
- SIGTSTP)
- Functions for assigned communication line (either external or console tty):
- sysinit() -- System dependent program initialization
- syscleanup() -- System dependent program shutdown
- ttopen(ttname,local,mdmtyp,timo) -- Open the named tty for exclusive access.
- ttclos() -- Close & reset the tty, releasing any access lock.
- ttsspd(cps) -- Set the transmission speed of the tty.
- ttgspd() -- Get (read) the the transmission speed of the tty.
- ttpkt(speed,flow,parity) -- Put the tty in packet mode and set the speed.
- ttvt(speed,flow) -- Put the tty in virtual terminal mode.
- or in DIALING or CONNECTED modem control state.
- ttres() -- Restore original tty modes.
- ttscarr(carrier) -- Set carrier control mode, on/off/auto.
- ttinl(dest,max,timo) -- Timed read line from the tty.
- ttinc(timo) -- Timed read character from tty.
- myread() -- Raw mode bulk buffer read, gives subsequent
- chars one at a time and simulates FIONREAD.
- myunrd(c) -- Places c back in buffer to be read (one only)
- ttchk() -- See how many characters in tty input buffer.
- ttxin(n,buf) -- Read n characters from tty (untimed).
- ttol(string,length) -- Write a string to the tty.
- ttoc(c) -- Write a character to the tty.
- ttflui() -- Flush tty input buffer.
- ttsndb() -- Send BREAK signal.
- ttsndlb() -- Send Long BREAK signal.
- ttlock(ttname) -- "Lock" tty device against uucp collisions.
- ttunlck() -- Unlock tty device.
- For ATT7300/Unix PC, System V:
- attdial(ttname,speed,telnbr) -- dials ATT7300/Unix PC internal modem
- offgetty(ttname) -- Turns off getty(1m) for comms line
- ongetty(ttname) -- Restores getty() to comms line
- */
- /*
- Functions for console terminal:
- congm() -- Get console terminal modes.
- concb(esc) -- Put the console in single-character wakeup mode with no echo.
- conbin(esc) -- Put the console in binary (raw) mode.
- conres() -- Restore the console to mode obtained by congm().
- conoc(c) -- Unbuffered output, one character to console.
- conol(s) -- Unbuffered output, null-terminated string to the console.
- conola(s) -- Unbuffered output, array of strings to the console.
- conxo(n,s) -- Unbuffered output, n characters to the console.
- conchk() -- Check if characters available at console (bsd 4.2).
- Check if escape char (^) typed at console (System III/V).
- coninc(timo) -- Timed get a character from the console.
- congks(timo) -- Timed get keyboard scan code.
- conint() -- Enable terminal interrupts on the console if not background.
- connoi() -- Disable terminal interrupts on the console if not background.
- Time functions
- msleep(m) -- Millisecond sleep
- ztime(&s) -- Return pointer to date/time string
- rtimer() -- Reset timer
- gtimer() -- Get elapsed time since last call to rtimer()
- */
- /* Conditional Includes */
- /* Whether to include <sys/file.h> */
- #ifdef RTU /* RTU doesn't */
- #define NOFILEH
- #endif /* RTU */
- #ifdef CIE /* CIE does. */
- #undef NOFILEH
- #endif /* CIE */
- #ifdef BSD41 /* 4.1 BSD doesn't */
- #define NOFILEH
- #endif /* BSD41 */
- #ifdef is68k /* is68k (whatever that is) */
- #define NOFILEH
- #endif /* is68k */
- #ifdef MINIX /* MINIX */
- #define NOFILEH
- #endif /* MINIX */
- #ifdef COHERENT /* Coherent */
- #define NOFILEH
- #endif /* COHERENT */
- #ifndef NOFILEH /* Now include if selected. */
- #include <sys/file.h>
- #endif /* NOFILEH */
- /* POSIX */
- #ifdef BSD44ORPOSIX /* POSIX uses termios.h */
- #define TERMIOS
- #ifdef __bsdi__
- #ifdef POSIX
- #undef _POSIX_SOURCE /* Get extra stuff from termios.h */
- #endif /* POSIX */
- #endif /* __bsdi__ */
- #include <termios.h>
- #ifdef LINUX
- #include <sys/ioctl.h>
- #endif /* LINUX */
- #ifdef QNX16
- #include <ioctl.h>
- #endif /* QNX16 */
- #ifdef __bsdi__
- #ifdef POSIX
- #define _POSIX_SOURCE
- #endif /* POSIX */
- #endif /* __bsdi__ */
- #ifndef BSD44 /* Really POSIX */
- #ifndef CK_QNX32 /* was CK_QNX32 */
- #define NOSYSIOCTLH /* No ioctl's allowed. */
- #undef ultrix /* Turn off any ultrix features. */
- #endif /* CK_QNX32 */
- #endif /* BSD44 */
- #endif /* POSIX */
- /* System III, System V */
- #ifdef ATTSV
- #ifndef BSD44
- #ifndef POSIX
- #include <termio.h>
- #endif /* POSIX */
- #endif /* BSD44 */
- #ifdef TERMIOX
- /* Need this for termiox structure, RTS/CTS and DTR/CD flow control */
- #include <termiox.h>
- struct termiox rctsx;
- #else
- #ifdef STERMIOX
- #ifdef SCO_OSR504
- /* Sorry, this is truly disgusting but it's SCO's fault. */
- #ifndef _SVID3
- #define _CK_SVID3_X
- #define _SVID3
- #endif /* _SVID3 */
- #endif /* SCO_OSR504 */
- #include <sys/termiox.h>
- struct termiox rctsx;
- #ifdef CK_SVID3_X
- #undef _SVID3
- #undef CK_SVID3_X
- #endif /* CK_SVID3_X */
- #endif /* STERMIOX */
- #endif /* TERMIOX */
- #endif /* ATTSV */
- #ifdef COHERENT /* Use termio.h, not sgtty.h for Coherent */
- #include <termio.h>
- #endif /* COHERENT */
- #ifdef MINIX /* MINIX uses ioctl's */
- #define NOSYSIOCTLH /* but has no <sys/ioctl.h> */
- #endif /* MINIX */
- /* Others */
- #ifndef NOSYSIOCTLH /* Others use ioctl() */
- #ifdef SUN4S5
- /*
- This is to get rid of cpp warning messages that occur because all of
- these symbols are defined by both termios.h and ioctl.h on the SUN.
- */
- #undef ECHO
- #undef NL0
- #undef NL1
- #undef TAB0
- #undef TAB1
- #undef TAB2
- #undef XTABS
- #undef CR0
- #undef CR1
- #undef CR2
- #undef CR3
- #undef FF0
- #undef FF1
- #undef BS0
- #undef BS1
- #undef TOSTOP
- #undef FLUSHO
- #undef PENDIN
- #undef NOFLSH
- #endif /* SUN4S5 */
- #include <sys/ioctl.h>
- #endif /* NOSYSIOCTLH */
- /*
- We really, really, REALLY want FIONREAD, because it is the only way to find
- out not just *if* stuff is waiting to be read, but how much, which is
- critical to our sliding-window and streaming procedures, not to mention
- efficiency of CONNECT, etc.
- */
- #ifdef BELLV10
- #include <sys/filio.h> /* For FIONREAD */
- #ifdef FIONREAD
- #define MYREAD
- #endif /* MYREAD */
- #endif /* BELLV10 */
- #ifndef FIONREAD
- /* It wasn't found in ioctl.h or term*.h - try these places: */
- #ifdef UNIXWARE
- #include <sys/filio.h>
- #else
- #ifdef SOLARIS
- #include <sys/filio.h>
- #endif /* SOLARIS */
- #endif /* UNIXWARE */
- #endif /* FIONREAD */
- #ifdef XENIX /* Was M_UNIX but XENIX implies M_UNIX and applies to XENIX too */
- /*
- <sys/socket.h> included above via "ckcnet.h" defines FIONREAD as
- something. Due to this, in_chk() uses the FIONREAD instead of RDCHK
- and the hot keys during file transfer (X to cancel file etc) do not
- work because FIONREAD doesn't work even though it is defined.
- NOTE: This might also be true elsewhere.
- */
- #ifdef FIONREAD
- #undef FIONREAD
- #endif /* FIONREAD */
- #endif /* XENIX */
- #ifdef CK_SCOV5 /* Ditto for SCO OpenServer 5.0 */
- #ifdef FIONREAD
- #undef FIONREAD
- #endif /* FIONREAD */
- #endif /* XENIX */
- /* Whether to include <fcntl.h> */
- #ifndef is68k /* Only a few don't have this one. */
- #ifndef BSD41
- #ifndef FT21
- #ifndef FT18
- #ifndef COHERENT
- #include <fcntl.h>
- #endif /* COHERENT */
- #endif /* FT18 */
- #endif /* FT21 */
- #endif /* BSD41 */
- #endif /* not is68k */
- #ifdef COHERENT
- #ifdef _I386
- #include <fcntl.h>
- #else
- #include <sys/fcntl.h>
- #endif /* _I386 */
- #endif /* COHERENT */
- #ifdef ATT7300 /* Unix PC, internal modem dialer */
- #include <sys/phone.h>
- #endif /* ATT7300 */
- #ifdef HPUX /* HP-UX variations. */
- #define HPUXJOBCTL
- #include <sys/modem.h> /* HP-UX modem signals */
- #ifdef hp9000s500 /* Model 500 */
- #undef HPUXJOBCTL
- #endif /* hp9000s500 */
- #ifdef HPUXPRE65
- #undef HPUXJOBCTL
- typedef long mflag;
- #endif /* HPUXPRE65 */
- #ifdef HPUXJOBCTL
- #include <sys/bsdtty.h> /* HP-UX Berkeley tty support */
- #endif /* HPUXJOBCTL */
- #endif /* HPUX */
- /*
- Which time.h files to include... See ckcdeb.h for defaults.
- Note that 0, 1, 2, or all 3 of these can be included according to
- the symbol definitions.
- */
- #ifndef NOTIMEH
- #ifdef TIMEH
- #include <time.h>
- #endif /* TIMEH */
- #endif /* NOTIMEH */
- #ifndef NOSYSTIMEH
- #ifdef SYSTIMEH
- #include <sys/time.h>
- #endif /* SYSTIMEH */
- #endif /* NOSYSTIMEH */
- #ifndef NOSYSTIMEBH
- #ifdef SYSTIMEBH
- #include <sys/timeb.h>
- #endif /* SYSTIMEBH */
- #endif /* NOSYSTIMEBH */
- #ifdef DCLTIMEVAL
- /*
- In certain POSIX builds (like Unixware 7), <[sys/]time.h> refuses to
- define the structs we need to access the higher speeds, so we have to
- do it ourselves.
- */
- struct timeval {
- long tv_sec;
- long tv_usec;
- };
- struct timezone {
- int tz_minuteswest;
- int tz_dsttime;
- };
- #endif /* DCLTIMEVAL */
- #ifdef __linux__
- /* THIS IS OBSOLETE since about Linux 0.92 */
- #ifdef OLINUXHISPEED
- #include <linux/serial.h>
- #endif /* OLINUXHISPEED */
- #ifdef __alpha__ /* Linux on DEC Alpha */
- #ifndef __GLIBC__ /* But not with glibc */
- #include <asm/termios.h>
- #endif /* __GLIBC__ */
- #endif /* __alpha__ */
- #endif /* __linux__ */
- #ifdef NOIEXTEN /* This is broken on some systems */
- #undef IEXTEN /* like Convex/OS 9.1 */
- #endif /* NOIEXTEN */
- #ifndef IEXTEN /* Turn off ^O/^V processing. */
- #define IEXTEN 0 /* Needed, at least, on BSDI. */
- #endif /* IEXTEN */
- /*
- Pick up definitions needed for select() if we don't have them already.
- Normally they come from <sys/types.h> but some systems get them from
- <sys/select.h>... Rather than hardwire all of them into the source, we
- include it if SELECT_H is defined in compile-time CFLAGS.
- */
- #ifndef SCO_OSR504
- #ifdef SELECT_H
- #include <sys/select.h>
- #endif /* SELECT_H */
- #endif /* SCO_OSR504 */
- #ifdef aegis
- #include "/sys/ins/base.ins.c"
- #include "/sys/ins/error.ins.c"
- #include "/sys/ins/ios.ins.c"
- #include "/sys/ins/sio.ins.c"
- #include "/sys/ins/pad.ins.c"
- #include "/sys/ins/time.ins.c"
- #include "/sys/ins/pfm.ins.c"
- #include "/sys/ins/pgm.ins.c"
- #include "/sys/ins/ec2.ins.c"
- #include "/sys/ins/type_uids.ins.c"
- #include <default_acl.h>
- #undef TIOCEXCL
- #undef FIONREAD
- #endif /* aegis */
- #ifdef sxaE50 /* PFU Compact A SX/A TISP V10/L50 */
- #undef FIONREAD
- #endif /* sxaE50 */
- /* The following #defines are catch-alls for those systems */
- /* that didn't have or couldn't find <file.h>... */
- #ifndef FREAD
- #define FREAD 0x01
- #endif /* FREAD */
- #ifndef FWRITE
- #define FWRITE 0x10
- #endif /* FWRITE */
- #ifndef O_RDONLY
- #define O_RDONLY 000
- #endif /* O_RDONLY */
- #ifdef SVORPOSIX
- /*
- Modem signals are also forbidden in the POSIX world. But some POSIX-based
- platforms let us at them anyway if we know where to look.
- */
- #ifndef NEEDMDMDEFS
- /* Doesn't work for Linux */
- #ifdef UNIXWARE7
- #define NEEDMDMDEFS
- #endif /* UNIXWARE7 */
- #endif /* NEEDMDMDEFS */
- #ifdef NEEDMDMDEFS
- #ifndef TIOCMGET
- #define TIOCMGET (('t'<<8)|29)
- #endif /* TIOCMGET */
- #ifndef TIOCM_DTR
- #define TIOCM_DTR 0x0002
- #endif /* TIOCM_DTR */
- #ifndef TIOCM_RTS
- #define TIOCM_RTS 0x0004
- #endif /* TIOCM_RTS */
- #ifndef TIOCM_CTS
- #define TIOCM_CTS 0x0020
- #endif /* TIOCM_CTS */
- #ifndef TIOCM_CAR
- #define TIOCM_CAR 0x0040
- #endif /* TIOCM_CAR */
- #ifndef TIOCM_RNG
- #define TIOCM_RNG 0x0080
- #endif /* TIOCM_RNG */
- #ifndef TIOCM_DSR
- #define TIOCM_DSR 0x0100
- #endif /* TIOCM_DSR */
- #endif /* NEEDMDMDEFS */
- #endif /* SVORPOSIX */
- /* Declarations */
- #ifdef OXOS
- #undef TCGETA
- #undef TCSETA
- #undef TCSETAW
- #undef TCSETAF
- #define TCGETA TCGETS
- #define TCSETA TCSETS
- #define TCSETAW TCSETSW
- #define TCSETAF TCSETSF
- #define termio termios
- #endif /* OXOS */
- #ifdef SVORPOSIX /* AT&T Sys V or POSIX */
- #ifdef UNIXWAREPOSIX /* UnixWare 7 POSIX build */
- /*
- In Unixware POSIX builds, <[sys/]time.h> refuses to define the
- structs we need to access the higher speeds, so we have to do it
- ourselves.
- */
- struct timeval {
- long tv_sec;
- long tv_usec;
- };
- struct timezone {
- int tz_minuteswest;
- int tz_dsttime;
- };
- #endif /* UNIXWAREPOSIX */
- #endif /* SVORPOSIX */
- #ifdef __GNUC__
- #ifdef XENIX
- /*
- Because Xenix <time.h> doesn't declare time() if we're using gcc.
- */
- time_t time();
- #endif /* XENIX */
- #endif /* __GNUC__ */
- /* Special stuff for V7 input buffer peeking */
- #ifdef V7
- int kmem[2] = { -1, -1};
- char *initrawq(), *qaddr[2]={0,0};
- #define CON 0
- #define TTY 1
- #endif /* V7 */
- /* dftty is the device name of the default device for file transfer */
- /* dfloc is 0 if dftty is the user's console terminal, 1 if an external line */
- #ifdef BEOS
- char * dftty = NULL;
- char *dfmdm = "none";
- int dfloc = 0; /* that goes in local mode by default */
- #else
- #ifndef DFTTY
- #ifdef PROVX1
- char *dftty = "/dev/com1.dout"; /* Only example so far of a system */
- char *dfmdm = "none";
- int dfloc = 1; /* that goes in local mode by default */
- #else
- char *dftty = CTTNAM; /* Remote by default, use normal */
- char *dfmdm = "none";
- int dfloc = 0; /* controlling terminal name. */
- #endif /* PROVX1 */
- #else
- char *dftty = DFTTY; /* Default location specified on */
- char *dfmdm = "none"; /* command line. */
- int dfloc = 1; /* controlling terminal name. */
- #endif /* DFTTY */
- #endif /* BEOS */
- char cttnam[DEVNAMLEN+1] = { ' ', ' ' }; /* Determined at runtime */
- #ifdef RTU
- int rtu_bug = 0; /* set to 1 when returning from SIGTSTP */
- #endif /* RTU */
- int dfprty = DEFPAR; /* Default parity (0 = none) */
- int ttprty = 0; /* The parity that is in use. */
- static int ttpmsk = 0xff; /* Parity stripping mask. */
- int ttmdm = 0; /* Modem in use. */
- int ttcarr = CAR_AUT; /* Carrier handling mode. */
- int dfflow = FLO_NONE; /* Default flow control is NONE */
- int backgrd = 0; /* Assume in foreground (no '&' ) */
- #ifdef F_SETFL
- int iniflags = -1; /* fcntl flags for ttyfd */
- #endif /* F_SETFL */
- int fdflag = 0; /* Flag for redirected stdio */
- int ttfdflg = 0; /* Open File descriptor was given */
- int tvtflg = 0; /* Flag that ttvt has been called */
- long ttspeed = -1L; /* For saving speed */
- int ttflow = -9; /* For saving flow */
- int ttld = -1; /* Line discipline */
- #ifdef sony_news
- static int km_con = -1; /* Kanji mode for console tty */
- static int km_ext = -1; /* Kanji mode for external device */
- #endif /* sony_news */
- #ifdef PARSENSE
- static int needpchk = 1; /* Need parity check */
- #else
- static int needpchk = 0;
- #endif /* PARSENSE */
- #ifdef HWPARITY
- /*
- Unfortunately we must do this with global variables rather than through the
- tt...() APIs to avoid changing the APIs and the many modules that use them.
- If hwparity != 0, this indicates 8 data bits + parity, rather than 7 data
- bits + parity or 8 data bits and no parity, and overrides the regular parity
- variable, which is communicated to this module thru ttpkt(), and represented
- locally by the ttprty variable.
- */
- extern int hwparity; /* Hardware parity */
- extern int stopbits; /* Stop bits */
- #endif /* HWPARITY */
- #ifdef TCPSOCKET
- #ifdef TCP_NODELAY
- static int nodelay_sav = -1;
- #endif /* TCP_NODELAY */
- #endif /* TCPSOCKET */
- static int sigint_ign = 0; /* SIGINT is ignored */
- /*
- Having this module rely on external globals is bad, but fixing this
- requires overhaul of the ck*tio.c modules for all the different operating
- systems supported by C-Kermit. Left for a future release.
- */
- extern int ttnproto; /* Defined in ckcnet.c */
- extern int ttnet; /* Defined in ckcnet.c */
- extern int nopush, xfrcan, xfrchr, xfrnum; /* Defined in ckcmai.c */
- extern int suspend, wasclosed;
- extern int inserver, local;
- int ckxech = 0; /* 0 if system normally echoes console characters, else 1 */
- int ckmaxfiles = 0; /* Max number of open files */
- #ifdef CK_ENCRYPTION /* Kerberos */
- #include "ckuath.h"
- extern int me_encrypt, u_encrypt;
- #endif /* CK_ENCRYPTION */
- /* Declarations of variables global within this module */
- #ifdef TTLEBUF /* See ckcnet.h */
- int ttpush = -1;
- #define LEBUFSIZ 4096
- static CHAR le_buf[LEBUFSIZ];
- static int le_start = 0, le_end = 0, le_data = 0;
- #endif /* TTLEBUF */
- static time_t tcount = (time_t)0; /* Elapsed time counter */
- static SIGTYP (*saval)() = NULL; /* For saving alarm() handler */
- static SIGTYP (*savquit)() = NULL; /* and other signal handlers */
- #ifdef SIGUSR1
- static SIGTYP (*savusr1)() = NULL;
- #endif /* SIGUSR1 */
- #ifdef SIGUSR2
- static SIGTYP (*savusr2)() = NULL;
- #endif /* SIGUSR2 */
- #ifdef SIGPIPE
- static SIGTYP (*savpipe)() = NULL;
- #endif /* SIGPIPE */
- #ifdef SIGDANGER
- static SIGTYP (*savdanger)() = NULL;
- #endif /* SIGDANGER */
- #ifndef NOJC
- static SIGTYP (*jchdlr)() = NULL; /* For checking suspend handler */
- #endif /* NOJC */
- static int jcshell = -1; /* And flag for result */
- /*
- BREAKNULS is defined for systems that simulate sending a BREAK signal
- by sending a bunch of NUL characters at low speed.
- */
- #ifdef PROVX1
- #ifndef BREAKNULS
- #define BREAKNULS
- #endif /* BREAKNULS */
- #endif /* PROVX1 */
- #ifdef V7
- #ifndef BREAKNULS
- #define BREAKNULS
- #endif /* BREAKNULS */
- #endif /* V7 */
- #ifdef BREAKNULS
- static char /* A string of nulls */
- *brnuls = "