diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 34cc29c..46c9310 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.58 2005-05-30 08:47:25 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.59 2005-06-04 10:46:21 obarthel Exp $ # # :ts=8 # @@ -468,6 +468,7 @@ UNIX_LIB = \ stat_mkdir.o \ stat_rmdir.o \ stat_stat.o \ + stdio_ctermid.o \ stdio_fdhookentry.o \ stdio_fflush.o \ stdio_fopen.o \ @@ -483,6 +484,18 @@ UNIX_LIB = \ stdlib_mkstemp.o \ stdlib_mktemp.o \ stdlib_system.o \ + termios_cfgetispeed.o \ + termios_cfgetospeed.o \ + termios_cfmakeraw.o \ + termios_cfsetispeed.o \ + termios_cfsetospeed.o \ + termios_console_fdhookentry.o \ + termios_tcdrain.o \ + termios_tcflow.o \ + termios_tcflush.o \ + termios_tcgetattr.o \ + termios_tcsendbreak.o \ + termios_tcsetattr.o \ uio_readv.o \ uio_writev.o \ unistd_access.o \ @@ -501,6 +514,8 @@ UNIX_LIB = \ unistd_translaterel.o \ unistd_translateu2a.o \ unistd_truncate.o \ + unistd_ttyname.o \ + unistd_ttyname_r.o \ unistd_unix_path_semantics.o \ unistd_unlink.o \ unistd_wildcard_expand.o \ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index 69a927d..2d5eefc 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.os4,v 1.62 2005-05-30 08:47:26 obarthel Exp $ +# $Id: GNUmakefile.os4,v 1.63 2005-06-04 10:46:21 obarthel Exp $ # # :ts=8 # @@ -467,6 +467,7 @@ UNIX_LIB = \ stat_mkdir.o \ stat_rmdir.o \ stat_stat.o \ + stdio_ctermid.o \ stdio_fdhookentry.o \ stdio_fflush.o \ stdio_fopen.o \ @@ -482,6 +483,20 @@ UNIX_LIB = \ stdlib_mkstemp.o \ stdlib_mktemp.o \ stdlib_system.o \ + termios_cfgetispeed.o \ + termios_cfgetospeed.o \ + termios_cfmakeraw.o \ + termios_cfsetispeed.o \ + termios_cfsetospeed.o \ + termios_console_fdhookentry.o \ + termios_headers.h + termios_openserial.o \ + termios_tcdrain.o \ + termios_tcflow.o \ + termios_tcflush.o \ + termios_tcgetattr.o \ + termios_tcsendbreak.o \ + termios_tcsetattr.o \ uio_readv.o \ uio_writev.o \ unistd_access.o \ @@ -500,6 +515,8 @@ UNIX_LIB = \ unistd_translaterel.o \ unistd_translateu2a.o \ unistd_truncate.o \ + unistd_ttyname.o \ + unistd_ttyname_r.o \ unistd_unix_path_semantics.o \ unistd_unlink.o \ unistd_wildcard_expand.o \ diff --git a/library/amiga.lib_rev.h b/library/amiga.lib_rev.h index d3747eb..9fd2f33 100644 --- a/library/amiga.lib_rev.h +++ b/library/amiga.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 192 -#define DATE "12.5.2005" -#define VERS "amiga.lib 1.192" -#define VSTRING "amiga.lib 1.192 (12.5.2005)\r\n" -#define VERSTAG "\0$VER: amiga.lib 1.192 (12.5.2005)" +#define REVISION 193 +#define DATE "4.6.2005" +#define VERS "amiga.lib 1.193" +#define VSTRING "amiga.lib 1.193 (4.6.2005)\r\n" +#define VERSTAG "\0$VER: amiga.lib 1.193 (4.6.2005)" diff --git a/library/amiga.lib_rev.rev b/library/amiga.lib_rev.rev index 86a0307..2455a46 100644 --- a/library/amiga.lib_rev.rev +++ b/library/amiga.lib_rev.rev @@ -1 +1 @@ -192 +193 diff --git a/library/c.lib_rev.h b/library/c.lib_rev.h index 54d5f83..8f73686 100644 --- a/library/c.lib_rev.h +++ b/library/c.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 192 -#define DATE "12.5.2005" -#define VERS "c.lib 1.192" -#define VSTRING "c.lib 1.192 (12.5.2005)\r\n" -#define VERSTAG "\0$VER: c.lib 1.192 (12.5.2005)" +#define REVISION 193 +#define DATE "4.6.2005" +#define VERS "c.lib 1.193" +#define VSTRING "c.lib 1.193 (4.6.2005)\r\n" +#define VERSTAG "\0$VER: c.lib 1.193 (4.6.2005)" diff --git a/library/c.lib_rev.rev b/library/c.lib_rev.rev index 86a0307..2455a46 100644 --- a/library/c.lib_rev.rev +++ b/library/c.lib_rev.rev @@ -1 +1 @@ -192 +193 diff --git a/library/changes b/library/changes index 83cb5c1..1ac3f09 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,5 @@ +c.lib 1.193 (4.6.2005) + - fpclassify() now returns FP_ZERO both for 0 and -0. - nan() and nanf() now return quiet NaNs. @@ -79,6 +81,10 @@ - The scanf() family now supports character ranges for the %[ conversion. Note that this is a non-standard feature! +- Integrated Peter Bengtsson's termios code. Thank you very much! I chose + to add it to libunix.a rather than keeping it in a separate libtermios.a + library. + c.lib 1.192 (12.5.2005) diff --git a/library/debug.lib_rev.h b/library/debug.lib_rev.h index 9efe069..d116751 100644 --- a/library/debug.lib_rev.h +++ b/library/debug.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 192 -#define DATE "12.5.2005" -#define VERS "debug.lib 1.192" -#define VSTRING "debug.lib 1.192 (12.5.2005)\r\n" -#define VERSTAG "\0$VER: debug.lib 1.192 (12.5.2005)" +#define REVISION 193 +#define DATE "4.6.2005" +#define VERS "debug.lib 1.193" +#define VSTRING "debug.lib 1.193 (4.6.2005)\r\n" +#define VERSTAG "\0$VER: debug.lib 1.193 (4.6.2005)" diff --git a/library/debug.lib_rev.rev b/library/debug.lib_rev.rev index 86a0307..2455a46 100644 --- a/library/debug.lib_rev.rev +++ b/library/debug.lib_rev.rev @@ -1 +1 @@ -192 +193 diff --git a/library/include/limits.h b/library/include/limits.h index 3c88491..78e8608 100644 --- a/library/include/limits.h +++ b/library/include/limits.h @@ -1,5 +1,5 @@ /* - * $Id: limits.h,v 1.7 2005-05-12 13:21:47 obarthel Exp $ + * $Id: limits.h,v 1.8 2005-06-04 10:46:23 obarthel Exp $ * * :ts=4 * @@ -88,9 +88,9 @@ /****************************************************************************/ -#define LLONG_MIN (-0x7fffffffffffffffLL-1) -#define LLONG_MAX 0x7fffffffffffffffLL -#define ULLONG_MAX 0xffffffffffffffffULL +#define LLONG_MIN (-0x7fffffffffffffffLL-1) +#define LLONG_MAX 0x7fffffffffffffffLL +#define ULLONG_MAX 0xffffffffffffffffULL /****************************************************************************/ @@ -110,4 +110,63 @@ /****************************************************************************/ +#define WORD_BIT 32 +#define LONG_BIT 32 /* For now, at least. */ + +/****************************************************************************/ + +/* + * POSIX, POSIX... These are minimum maximum values. I.e. the maximum must be + * at least this large. I am not sure all of these make much sense on the Amiga + * (yet), but here they are anyway. + * + * Actually, these symbols should be defined only if the preprocessor symbol + * _POSIX_SOURCE is defined. Other symbols which should be defined, too, are + * ARG_MAX, CHILD_MAX, LINK_MAX, MAX_CANON, MAX_INPUT, NAME_MAX, NGROUPS_MAX, + * OPEN_MAX, PATH_MAX, PIPE_BUF, SSIZE_MAX, STREAM_MAX and TZNAME_MAX. + */ + +#define _POSIX_AIO_LISTIO_MAX 2 +#define _POSIX_AIO_MAX 1 +#define _POSIX_ARG_MAX 4096 +#define _POSIX_CHILD_MAX 6 +#define _POSIX_DELAYTIMER_MAX 32 +#define _POSIX_LINK_MAX 8 +#define _POSIX_LOGIN_NAME_MAX 9 +#define _POSIX_MAX_CANON 255 +#define _POSIX_MAX_INPUT 255 +#define _POSIX_MQ_OPEN_MAX 8 +#define _POSIX_MQ_PRIO_MAX 32 +#define _POSIX_NAME_MAX 14 +#define _POSIX_NGROUPS_MAX 0 +#define _POSIX_OPEN_MAX 16 +#define _POSIX_PATH_MAX 255 +#define _POSIX_PIPE_BUF 512 +#define _POSIX_RTSIG_MAX 8 +#define _POSIX_SEM_NSEMS_MAX 256 +#define _POSIX_SEM_VALUE_MAX 32767 +#define _POSIX_SIGQUEUE_MAX 32 +#define _POSIX_SSIZE_MAX 32767 +#define _POSIX_STREAM_MAX 8 +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 +#define _POSIX_THREAD_KEYS_MAX 128 +#define _POSIX_THREADS_MAX 64 +#define _POSIX_TIMER_MAX 32 +#define _POSIX_TTY_NAME_MAX 9 +#define _POSIX_TZNAME_MAX 3 +#define _POSIX2_BC_BASE_MAX 99 +#define _POSIX2_BC_DIM_MAX 2048 +#define _POSIX2_BC_SCALE_MAX 99 +#define _POSIX2_BC_STRING_MAX 1000 +#define _POSIX2_COLL_WEIGHTS_MAX 2 +#define _POSIX2_EXPR_NEST_MAX 32 +#define _POSIX2_LINE_MAX 2048 +#define _POSIX2_RE_DUP_MAX 255 +#define _XOPEN_IOV_MAX 16 + +/* And a maximum minimum value. */ +#define _POSIX_CLOCKRES_MIN 20000000 /* Nanoseconds */ + +/****************************************************************************/ + #endif /* _LIMITS_H */ diff --git a/library/include/stdio.h b/library/include/stdio.h index 87b9ca4..574694f 100644 --- a/library/include/stdio.h +++ b/library/include/stdio.h @@ -1,5 +1,5 @@ /* - * $Id: stdio.h,v 1.14 2005-05-11 20:15:28 obarthel Exp $ + * $Id: stdio.h,v 1.15 2005-06-04 10:46:23 obarthel Exp $ * * :ts=4 * @@ -342,6 +342,14 @@ extern char *tmpnam(char *buf); /****************************************************************************/ +#define L_ctermid 32 + +/****************************************************************************/ + +extern char *ctermid(char *); + +/****************************************************************************/ + /* * A special buffer flush routine which returns the last character written * in case of success and EOF in case of failure. This is used by the diff --git a/library/include/termios.h b/library/include/termios.h new file mode 100644 index 0000000..8e7a88c --- /dev/null +++ b/library/include/termios.h @@ -0,0 +1,189 @@ +/* + * $Id: termios.h,v 1.1 2005-06-04 10:46:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +/* + * Almost-but-not-quite termios. + */ + +#ifndef _TERMIOS_H +#define _TERMIOS_H + +typedef unsigned int tcflag_t; +typedef unsigned char cc_t; +typedef unsigned int speed_t; + +#define NCCS 16 /* Number of Control Characters = Length of the c_cc array. */ + +enum { /* All the control characters in c_cc[] in a struct termios (below) */ + VINTR=0, /* ^C (break) */ + VQUIT, /* ^\ (quit) */ + VERASE, /* ^H (eraase) */ + VKILL, /* ^X (erase-line) */ + VEOF, /* ^D (end-of-file) */ + VMIN, /* Minimum number of characters to read. Interacts with VTIME. */ + VEOL, /* NUL */ + VTIME, /* Timeout in 1/10:ths of a second. Interacts with VMIN. */ + VSTART, /* ^Q (continue) */ + VSTOP, /* ^S (stop) */ + VSUSP, /* ^Z (suspend) */ + VWERASE, /* ^W (word-erase) */ +}; + +struct termios { + tcflag_t c_iflag; + tcflag_t c_oflag; + tcflag_t c_cflag; + tcflag_t c_lflag; + cc_t c_cc[NCCS]; + /* Private */ + speed_t c_ispeed; + speed_t c_ospeed; + int type; + unsigned int flags; +}; + +/* c_iflag */ + +#define IGNBRK (1<<0L) /* Ignore VINTR */ +#define BRKINT (1<<1L) /* Unimpl. */ +#define IGNPAR (1<<2L) /* Unimpl. */ +#define PARMRK (1<<3L) /* Unimpl. */ +#define INPCK (1<<4L) /* Unimpl. */ +#define ISTRIP (1<<5L) /* 7-bit data (strip high bit) */ +#define INLCR (1<<6L) /* Map NL->CR */ +#define IGNCR (1<<7L) /* Map CR->nothing */ +#define ICRNL (1<<8L) /* Map CR->NL */ +#define IXON (1<<9L) /* Unimpl. Enable XON/XOFF for output. */ +#define IXOFF (1<<10L) /* Unimpl. Enable XON/XOFF for input. */ + +/* c_oflag */ + +#define OPOST (1<<0L) /* Enable output processing. */ +#define ONLCR (1<<1L) /* Map NL->CR+NL */ +#define OCRNL (1<<2L) /* Map CR->NL */ +#define ONOCR (1<<3L) /* Map CR->nothing, but only in column 0. */ +#define ONLRET (1<<4L) /* Map CR->nothing */ + +/* c_cflag */ + +#define CSIZE (0x07) /* Bit-width mask. */ +#define CS5 (0x01) /* 5-bits */ +#define CS6 (0x02) /* 6-bits */ +#define CS7 (0x03) /* 7-bits */ +#define CS8 (0x04) /* 8-bits */ +#define CSTOPB (1<<3L) /* Use 2 stop bits. */ +#define CREAD (1<<4L) /* Enable reading/receiving. */ +#define PARENB (1<<5L) /* Enable parity generation/checking. */ +#define PARODD (1<<6L) /* Parity is odd. */ +#define HUPCL (1<<7L) /* Hangup on close (when the device is closed). */ +#define CLOCAL (1<<8L) /* Ignore modem control lines (i.e. a null-modem) */ + +/* c_lflag */ + +#define ISIG (1<<0L) /* Send SIGINT for ^C, SIGQUIT for ^\ etc. */ +#define ICANON (1<<1L) /* Canonical mode. Line buffered with EOF, EOL etc. enabled. */ +#define ECHO (1<<2L) /* Echo input characters. */ +#define ECHONL (1<<3L) /* Echo newline characters even if ECHO is not set. */ +#define IEXTEN (1<<4L) /* Enable implementation defined input processing. (none) */ + +/* Speeds */ + +enum { + B0=0, /* 0 baud => disconnect. */ + B50=50, + B75=75, + B110=110, + B134=134, + B150=150, + B200=200, + B300=300, + B600=600, + B1200=1200, + B1800=1800, + B2400=2400, + B4800=4800, + B9600=9600, + B19200=19200, + B31250=31250, + B38400=38400, + B57600=57600, + B115200=115200, + B230400=230400, + B460800=460800, + B576000=576000, + B1152000=1152000 +}; + +#define EXTA 1 /* Tell applications we have speeds > 9600 baud. */ + +/* Action types for tcsetattr() */ + +enum { + TCSANOW, + TCSADRAIN, + TCSAFLUSH +}; + +/* Action types for tcflush() */ + +enum { + TCIFLUSH, + TCOFLUSH, + TCIOFLUSH +}; + +/* Action types for tcflow() */ + +enum { + TCOOFF, + TCOON, + TCIOFF, + TCION +}; + +/* Prototypes. */ + +extern int tcgetattr(int file_descriptor,struct termios *tios_p); +extern int tcsetattr(int file_descriptor,int action,struct termios *tios_p); +extern int tcsendbreak(int file_descriptor,int duration); +extern int tcdrain(int file_descriptor); +extern int tcflush(int file_descriptor,int what); +extern int tcflow(int file_descriptor,int action); +extern int cfmakeraw(struct termios *tios_p); +extern speed_t cfgetispeed(struct termios *tios_p); +extern speed_t cfgetospeed(struct termios *tios_p); +extern int cfsetispeed(struct termios *tios_p,speed_t input_speed); +extern int cfsetospeed(struct termios *tios_p,speed_t output_speed); + +#endif /* _TERMIOS_H */ diff --git a/library/include/unistd.h b/library/include/unistd.h index cb8d397..aa56f67 100644 --- a/library/include/unistd.h +++ b/library/include/unistd.h @@ -1,5 +1,5 @@ /* - * $Id: unistd.h,v 1.9 2005-02-04 15:03:14 obarthel Exp $ + * $Id: unistd.h,v 1.10 2005-06-04 10:46:23 obarthel Exp $ * * :ts=4 * @@ -100,6 +100,9 @@ extern pid_t getpid(void); extern char *realpath(const char *file_name, char *resolved_name); extern int fsync(int file_descriptor); extern int fdatasync(int file_descriptor); +extern char *ttyname(int); +extern int ttyname_r(int file_descriptor,char *name,size_t buflen); +extern int ttyname_t(int,char *,size_t); /****************************************************************************/ diff --git a/library/m.lib_rev.h b/library/m.lib_rev.h index 2c03b8c..eb43f8e 100644 --- a/library/m.lib_rev.h +++ b/library/m.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 192 -#define DATE "12.5.2005" -#define VERS "m.lib 1.192" -#define VSTRING "m.lib 1.192 (12.5.2005)\r\n" -#define VERSTAG "\0$VER: m.lib 1.192 (12.5.2005)" +#define REVISION 193 +#define DATE "4.6.2005" +#define VERS "m.lib 1.193" +#define VSTRING "m.lib 1.193 (4.6.2005)\r\n" +#define VERSTAG "\0$VER: m.lib 1.193 (4.6.2005)" diff --git a/library/m.lib_rev.rev b/library/m.lib_rev.rev index 86a0307..2455a46 100644 --- a/library/m.lib_rev.rev +++ b/library/m.lib_rev.rev @@ -1 +1 @@ -192 +193 diff --git a/library/m881.lib_rev.h b/library/m881.lib_rev.h index 0e7e5c2..d9edcb6 100644 --- a/library/m881.lib_rev.h +++ b/library/m881.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 192 -#define DATE "12.5.2005" -#define VERS "m881.lib 1.192" -#define VSTRING "m881.lib 1.192 (12.5.2005)\r\n" -#define VERSTAG "\0$VER: m881.lib 1.192 (12.5.2005)" +#define REVISION 193 +#define DATE "4.6.2005" +#define VERS "m881.lib 1.193" +#define VSTRING "m881.lib 1.193 (4.6.2005)\r\n" +#define VERSTAG "\0$VER: m881.lib 1.193 (4.6.2005)" diff --git a/library/m881.lib_rev.rev b/library/m881.lib_rev.rev index 86a0307..2455a46 100644 --- a/library/m881.lib_rev.rev +++ b/library/m881.lib_rev.rev @@ -1 +1 @@ -192 +193 diff --git a/library/net.lib_rev.h b/library/net.lib_rev.h index 06f4cb9..27e9b8a 100644 --- a/library/net.lib_rev.h +++ b/library/net.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 192 -#define DATE "12.5.2005" -#define VERS "net.lib 1.192" -#define VSTRING "net.lib 1.192 (12.5.2005)\r\n" -#define VERSTAG "\0$VER: net.lib 1.192 (12.5.2005)" +#define REVISION 193 +#define DATE "4.6.2005" +#define VERS "net.lib 1.193" +#define VSTRING "net.lib 1.193 (4.6.2005)\r\n" +#define VERSTAG "\0$VER: net.lib 1.193 (4.6.2005)" diff --git a/library/net.lib_rev.rev b/library/net.lib_rev.rev index 86a0307..2455a46 100644 --- a/library/net.lib_rev.rev +++ b/library/net.lib_rev.rev @@ -1 +1 @@ -192 +193 diff --git a/library/smakefile b/library/smakefile index b2e04b9..032645a 100644 --- a/library/smakefile +++ b/library/smakefile @@ -1,5 +1,5 @@ # -# $Id: smakefile,v 1.45 2005-05-30 11:42:38 obarthel Exp $ +# $Id: smakefile,v 1.46 2005-06-04 10:46:21 obarthel Exp $ # # :ts=8 # @@ -351,6 +351,7 @@ STAT_OBJ = \ STDIO_OBJ = \ stdio_asprintf.o \ stdio_clearerr.o \ + stdio_ctermid.o \ stdio_dropiobreadbuffer.o \ stdio_duplicate_fd.o \ stdio_examine_fh.o \ @@ -582,6 +583,20 @@ TIME_OBJ = \ UNISTD_OBJ = \ ftw_ftw.o \ ftw_nftw.o \ + termios_cfgetispeed.o \ + termios_cfgetospeed.o \ + termios_cfmakeraw.o \ + termios_cfsetispeed.o \ + termios_cfsetospeed.o \ + termios_console_fdhookentry.o \ + termios_headers.h + termios_openserial.o \ + termios_tcdrain.o \ + termios_tcflow.o \ + termios_tcflush.o \ + termios_tcgetattr.o \ + termios_tcsendbreak.o \ + termios_tcsetattr.o \ uio_readv.o \ uio_writev.o \ unistd_access.o \ @@ -618,6 +633,8 @@ UNISTD_OBJ = \ unistd_translaterel.o \ unistd_translateu2a.o \ unistd_truncate.o \ + unistd_ttyname.o \ + unistd_ttyname_r.o \ unistd_unix_path_semantics.o \ unistd_unlink.o \ unistd_usleep.o \ diff --git a/library/stack.lib_rev.h b/library/stack.lib_rev.h index 39362a3..d1481cc 100644 --- a/library/stack.lib_rev.h +++ b/library/stack.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 192 -#define DATE "12.5.2005" -#define VERS "stack.lib 1.192" -#define VSTRING "stack.lib 1.192 (12.5.2005)\r\n" -#define VERSTAG "\0$VER: stack.lib 1.192 (12.5.2005)" +#define REVISION 193 +#define DATE "4.6.2005" +#define VERS "stack.lib 1.193" +#define VSTRING "stack.lib 1.193 (4.6.2005)\r\n" +#define VERSTAG "\0$VER: stack.lib 1.193 (4.6.2005)" diff --git a/library/stack.lib_rev.rev b/library/stack.lib_rev.rev index 86a0307..2455a46 100644 --- a/library/stack.lib_rev.rev +++ b/library/stack.lib_rev.rev @@ -1 +1 @@ -192 +193 diff --git a/library/stdio_ctermid.c b/library/stdio_ctermid.c new file mode 100755 index 0000000..9b07d39 --- /dev/null +++ b/library/stdio_ctermid.c @@ -0,0 +1,51 @@ +/* + * $Id: stdio_ctermid.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +char * +ctermid(char *buf) +{ + static char cname[] = "CONSOLE:"; + + if(buf != NULL) + strcpy(buf,cname); + else + buf = cname; + + return(buf); +} diff --git a/library/stdio_headers.h b/library/stdio_headers.h index c857497..43412d1 100644 --- a/library/stdio_headers.h +++ b/library/stdio_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdio_headers.h,v 1.23 2005-04-24 08:46:37 obarthel Exp $ + * $Id: stdio_headers.h,v 1.24 2005-06-04 10:46:21 obarthel Exp $ * * :ts=4 * @@ -360,7 +360,8 @@ struct iob something like it. */ #define FDF_STDIO (1UL<<12) /* File is to be attached to one of the standard input/output/error streams. */ - +#define FDF_TERMIOS (1UL<<13) /* File is under termios control. + FDF_IS_INTERACTIVE should also be set. */ /****************************************************************************/ /* The file action function for unbuffered files. */ @@ -387,6 +388,9 @@ struct fd fd_cleanup_t fd_Cleanup; /* Cleanup function, if any. */ struct SignalSemaphore * fd_Lock; /* For thread locking */ + + void * fd_Aux; /* Auxilliary data for "special" files, + e.g. termios support. */ }; /****************************************************************************/ diff --git a/library/stdio_initializefd.c b/library/stdio_initializefd.c index d574610..043177d 100644 --- a/library/stdio_initializefd.c +++ b/library/stdio_initializefd.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_initializefd.c,v 1.4 2005-02-28 13:22:53 obarthel Exp $ + * $Id: stdio_initializefd.c,v 1.5 2005-06-04 10:46:21 obarthel Exp $ * * :ts=4 * @@ -53,4 +53,5 @@ __initialize_fd( fd->fd_Flags = flags; fd->fd_Action = action_function; fd->fd_Lock = lock; + fd->fd_Aux = NULL; } diff --git a/library/stdio_vfscanf.c b/library/stdio_vfscanf.c index e590736..d233599 100644 --- a/library/stdio_vfscanf.c +++ b/library/stdio_vfscanf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vfscanf.c,v 1.17 2005-06-03 11:12:12 obarthel Exp $ + * $Id: stdio_vfscanf.c,v 1.18 2005-06-04 10:46:21 obarthel Exp $ * * :ts=4 * @@ -1822,7 +1822,7 @@ vfscanf(FILE *stream, const char *format, va_list arg) for(scanset_length = 0 ; scanset[scanset_length] != '\0' && scanset[scanset_length] != ']' ; scanset_length++) format++; - /* We already skipped everything but the righ bracket. */ + /* We already skipped everything but the right bracket. */ if((*format) == ']') format++; @@ -1837,12 +1837,12 @@ vfscanf(FILE *stream, const char *format, va_list arg) /* Could this be a range? It's not a range if it is the first or the last character in the specification. */ - if(c == '-' && i != 0 && i != scanset_length - 1) + if(c == '-' && 0 < i && i < scanset_length - 1) { int first,last,j; /* Pick the first and the last character in - the range, e.g. for "[A-Z]" the first would + the range, e.g. for "%[A-Z]" the first would be the 'A' and the 'Z' would be the last. */ first = scanset[i-1]; last = scanset[i+1]; diff --git a/library/termios_cfgetispeed.c b/library/termios_cfgetispeed.c new file mode 100755 index 0000000..86e84ef --- /dev/null +++ b/library/termios_cfgetispeed.c @@ -0,0 +1,61 @@ +/* + * $Id: termios_cfgetispeed.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +speed_t +cfgetispeed(struct termios *tios) +{ + speed_t result = ERROR; + + ENTER(); + + SHOWPOINTER(tios); + + if(tios == NULL) + { + __set_errno(EFAULT); + goto out; + } + + result = tios->c_ispeed; + + out: + + RETURN(result); + return(result); +} diff --git a/library/termios_cfgetospeed.c b/library/termios_cfgetospeed.c new file mode 100755 index 0000000..87af915 --- /dev/null +++ b/library/termios_cfgetospeed.c @@ -0,0 +1,61 @@ +/* + * $Id: termios_cfgetospeed.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +speed_t +cfgetospeed(struct termios *tios) +{ + speed_t result = ERROR; + + ENTER(); + + SHOWPOINTER(tios); + + if(tios == NULL) + { + __set_errno(EFAULT); + goto out; + } + + result = tios->c_ospeed; + + out: + + RETURN(result); + return(result); +} diff --git a/library/termios_cfmakeraw.c b/library/termios_cfmakeraw.c new file mode 100755 index 0000000..8bc0494 --- /dev/null +++ b/library/termios_cfmakeraw.c @@ -0,0 +1,66 @@ +/* + * $Id: termios_cfmakeraw.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +int +cfmakeraw(struct termios *tios) +{ + int result = ERROR; + + ENTER(); + + SHOWPOINTER(tios); + + if(tios == NULL) + { + __set_errno(EFAULT); + goto out; + } + + tios->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + tios->c_oflag &= ~OPOST; + tios->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + tios->c_cflag &= ~(CSIZE|PARENB); + tios->c_cflag |= CS8; + + result = OK; + + out: + + return(result); +} diff --git a/library/termios_cfsetispeed.c b/library/termios_cfsetispeed.c new file mode 100755 index 0000000..62f61fa --- /dev/null +++ b/library/termios_cfsetispeed.c @@ -0,0 +1,97 @@ +/* + * $Id: termios_cfsetispeed.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +int +cfsetispeed(struct termios *tios,speed_t ispeed) +{ + int result = ERROR; + + ENTER(); + + SHOWPOINTER(tios); + SHOWVALUE(ispeed); + + if(tios == NULL) + { + __set_errno(EFAULT); + goto out; + } + + switch(ispeed) + { + case B0: + case B50: + case B75: + case B110: + case B134: + case B150: + case B200: + case B300: + case B600: + case B1200: + case B1800: + case B2400: + case B4800: + case B9600: + case B19200: + case B31250: + case B38400: + case B57600: + case B115200: + case B230400: + case B460800: + case B576000: + case B1152000: + + tios->c_ispeed = ispeed; + break; + + default: + + __set_errno(EINVAL); + goto out; + } + + result = OK; + + out: + + RETURN(result); + return(result); +} diff --git a/library/termios_cfsetospeed.c b/library/termios_cfsetospeed.c new file mode 100755 index 0000000..1b28213 --- /dev/null +++ b/library/termios_cfsetospeed.c @@ -0,0 +1,96 @@ +/* + * $Id: termios_cfsetospeed.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +int +cfsetospeed(struct termios *tios,speed_t ospeed) +{ + int result = ERROR; + + ENTER(); + + SHOWPOINTER(tios); + SHOWVALUE(ospeed); + + if(tios == NULL) + { + __set_errno(EFAULT); + goto out; + } + + switch(ospeed) + { + case B0: + case B50: + case B75: + case B110: + case B134: + case B150: + case B200: + case B300: + case B600: + case B1200: + case B1800: + case B2400: + case B4800: + case B9600: + case B19200: + case B31250: + case B38400: + case B57600: + case B115200: + case B230400: + case B460800: + case B576000: + case B1152000: + + tios->c_ospeed = ospeed; + break; + + default: + + __set_errno(EINVAL); + goto out; + } + + result = OK; + + out: + + return(result); +} diff --git a/library/termios_console_fdhookentry.c b/library/termios_console_fdhookentry.c new file mode 100755 index 0000000..cdb4522 --- /dev/null +++ b/library/termios_console_fdhookentry.c @@ -0,0 +1,654 @@ +/* + * $Id: termios_console_fdhookentry.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +/* + * Hook for termios emulation on a console. This can probably be cleaned up a bit + * by removing things which will (should) never happen on a console. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEMORY_H +#include "stdlib_memory.h" +#endif /* _STDLIB_MEMORY_H */ + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +/* + * Emulate canonical no-echo mode with a simple line-editor in raw mode. + */ +static int +LineEditor(BPTR file,char *buf,const int buflen,struct termios *tios) +{ + int pos = 0,len = 0; + unsigned char z; + int do_edit = 1; + int shift_mode = 0; + + SetMode(file,DOSTRUE); /* Set raw mode. */ + + while(do_edit && len < buflen) + { + if(WaitForChar(file,5000000) != DOSFALSE) /* 5 seconds. */ + { + if(Read(file,&z,1) == ERROR) + { + len = -1; + break; + } + + if(z == tios->c_cc[VQUIT]) + break; + + switch(z) + { + case '\n': /* NL */ + case '\r': /* CR */ + + do_edit = 0; + + buf[len++] = '\n'; + continue; + + case 155: /* CSI */ + + shift_mode = 1; + continue; + + case '\b': /* Backspace */ + + if(pos > 0) + { + memmove(&buf[pos-1],&buf[pos],len-pos); + pos--; + len--; + } + + continue; + + case 127: /* Delete */ + + if(pos < len) + { + memmove(&buf[pos],&buf[pos+1],len-pos-1); + len--; + } + + continue; + } + + if(shift_mode) + { + shift_mode = 0; + + switch(z) + { + case 'C': /* Right arrowkey */ + + if(pos < len) + pos++; + + continue; + + case 'D': /* Left arrowkey */ + + if(pos > 0) + pos--; + + continue; + } + } + + if(pos != len) + memmove(&buf[pos + 1],&buf[pos],len - pos); + + buf[pos]=z; + pos++; + len++; + } + } + + if(len >= 0 && len < buflen) /* Does not hurt to null-terminate if we can. */ + buf[len] = '\0'; + + SetMode(file,DOSFALSE); /* Restore mode */ + + return(len); /* Number of characters read. */ +} + +/****************************************************************************/ + +int +__termios_console_hook( + struct fd * fd, + struct file_action_message * fam) +{ + const unsigned char CR = '\r',NL = '\n'; + struct FileHandle * fh; + char * buffer = NULL; + int result = EOF; + int actual_out; + BOOL is_aliased; + BPTR file; + struct termios *tios; + + ENTER(); + + assert( fam != NULL && fd != NULL ); + assert( __is_valid_fd(fd) ); + assert( FLAG_IS_SET(fd->fd_Flags,FDF_TERMIOS) ); + assert( fd->fd_Aux != NULL); + + tios = (struct termios *)fd->fd_Aux; + + /* Careful: file_action_close has to monkey with the file descriptor + table and therefore needs to obtain the stdio lock before + it locks this particular descriptor entry. */ + if(fam->fam_Action == file_action_close) + __stdio_lock(); + + __fd_lock(fd); + + #if defined(__THREAD_SAFE) + { + /* Check if this file should be dynamically bound to one of the + three standard I/O streams. */ + if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO)) + { + switch(fd->fd_DefaultFile) + { + case STDIN_FILENO: + + file = Input(); + break; + + case STDOUT_FILENO: + + file = Output(); + break; + + case STDERR_FILENO: + + #if defined(__amigaos4__) + { + file = ErrorOutput(); + } + #else + { + struct Process * this_process = (struct Process *)FindTask(NULL); + + file = this_process->pr_CES; + } + #endif /* __amigaos4__ */ + + /* The following is rather controversial; if the standard error stream + is unavailable, we default to reuse the standard output stream. This + is problematic if the standard output stream was redirected and should + not be the same as the standard error output stream. */ + if(file == ZERO) + file = Output(); + + break; + + default: + + file = ZERO; + break; + } + } + else + { + file = fd->fd_DefaultFile; + } + } + #else + { + file = fd->fd_DefaultFile; + } + #endif /* __THREAD_SAFE */ + + if(file == ZERO) + { + SHOWMSG("file is closed"); + + fam->fam_Error = EBADF; + goto out; + } + + switch(fam->fam_Action) + { + case file_action_read: + + SHOWMSG("file_action_read"); + + if(FLAG_IS_CLEAR(tios->c_cflag,CREAD)) + { + SHOWMSG("Reading is not enabled for this console descriptor."); + fam->fam_Error = EIO; + goto out; + } + + assert( fam->fam_Data != NULL ); + assert( fam->fam_Size > 0 ); + + D(("read %ld bytes from position %ld to 0x%08lx",fam->fam_Size,Seek(file,0,OFFSET_CURRENT),fam->fam_Data)); + + PROFILE_OFF(); + + /* Attempt to fake everything needed in non-canonical mode. */ + + if(FLAG_IS_SET(tios->c_lflag,ICANON)) /* Canonical read = same as usual. Unless... */ + { + if(FLAG_IS_CLEAR(tios->c_lflag,ECHO)) /* No-echo mode needs to be emulated. */ + result = LineEditor(file,fam->fam_Data,fam->fam_Size,tios); + else + result = Read(file,fam->fam_Data,fam->fam_Size); + } + else if (fam->fam_Size > 0) + { + /* Non-canonical reads have timeouts and a minimum number of characters to read. */ + int i = 0; + + result = 0; + + if(tios->c_cc[VMIN]>0) + { + i = Read(file,fam->fam_Data,1); /* Reading the first character is not affected by the timeout unless VMIN==0. */ + if(i == ERROR) + { + fam->fam_Error = EIO; + goto out; + } + + result = i; + + while((result < tios->c_cc[VMIN]) && (result < fam->fam_Size)) + { + if(tios->c_cc[VTIME] > 0) + { + if(WaitForChar(file,100000 * tios->c_cc[VTIME]) == DOSFALSE) + break; /* No more characters available within alloted time. */ + } + + i = Read(file,&fam->fam_Data[result],1); + if(i <= 0) + break; /* Break out of this while loop only. */ + + result += i; + } + } + else + { + if(WaitForChar(fd->fd_DefaultFile,100000*tios->c_cc[VTIME])) + result = Read(file,fam->fam_Data,fam->fam_Size); + } + } + else + { + result = 0; /* Reading zero characters will always succeed. */ + } + + PROFILE_ON(); + + if(result == ERROR) + { + D(("read failed ioerr=%ld",IoErr())); + + fam->fam_Error = __translate_io_error_to_errno(IoErr()); + goto out; + } + + if(result > 0) + { + if(tios->c_iflag != 0) /* Input processing enabled. */ + { + int i,n; + int num_bytes = result; + unsigned char byte_in; + + /* XXX The input substitution could possibly be moved to the console handler with an input-map. (?) */ + for(i = n = 0 ; i < num_bytes ; i++) + { + byte_in = fam->fam_Data[i]; + + if(FLAG_IS_SET(tios->c_iflag,ISTRIP)) /* Strip 8:th bit. Done before any other processing. */ + byte_in &= 0x7f; + + if(FLAG_IS_SET(tios->c_iflag,IGNCR) && byte_in == CR) /* Remove CR */ + { + result--; + continue; + } + + if(FLAG_IS_SET(tios->c_iflag,ICRNL) && byte_in == CR) /* Map CR->NL */ + byte_in = NL; + + if(FLAG_IS_SET(tios->c_iflag,INLCR) && byte_in == NL) /* Map NL->CR */ + byte_in = CR; + + fam->fam_Data[n++] = byte_in; + } + } + + if(FLAG_IS_SET(tios->c_lflag,ECHO) && FLAG_IS_CLEAR(tios->c_lflag,ICANON) && FLAG_IS_SET(fd->fd_Flags,FDF_WRITE)) + { + if(Write(file,fam->fam_Data,result) == ERROR) + { + /* "Silently" disable echoing. */ + SHOWMSG("Echo failed and has been disabled."); + CLEAR_FLAG(tios->c_lflag,ECHO); + } + } + } + + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position += (ULONG)result; + + break; + + case file_action_write: + + SHOWMSG("file_action_write"); + + assert( fam->fam_Data != NULL ); + assert( fam->fam_Size > 0 ); + + if(FLAG_IS_SET(tios->c_oflag,OPOST)) /* Output processing enabled. */ + { + unsigned char byte_out; + int i,n; + + buffer = malloc(2 * fam->fam_Size); + if(buffer == NULL) + { + fam->fam_Error = ENOMEM; + goto out; + } + + for(i = n = 0 ; i < fam->fam_Size ; i++) + { + byte_out=fam->fam_Data[i]; + + if(FLAG_IS_SET(tios->c_oflag,ONLRET) && byte_out == CR) + continue; + + if(FLAG_IS_SET(tios->c_oflag,OCRNL) && byte_out == CR) + byte_out = NL; + + if(FLAG_IS_SET(tios->c_oflag,ONOCR) && byte_out == CR) + byte_out = NL; + + if(FLAG_IS_SET(tios->c_oflag,ONLCR) && byte_out == NL) + { + buffer[n++] = CR; + byte_out = NL; + } + + buffer[n++] = byte_out; + } + + actual_out = n; + } + else + { + buffer = fam->fam_Data; + actual_out = fam->fam_Size; + } + + /* Note. When output processing is enabled, write() can return _more_ than the data length. */ + D(("write %ld bytes to position %ld from 0x%08lx",actual_out,Seek(file,0,OFFSET_CURRENT),buffer)); + + if(actual_out > 0) + { + PROFILE_OFF(); + + result = Write(file,buffer,actual_out); + + PROFILE_ON(); + } + else + { + result = 0; + } + + if(buffer == fam->fam_Data) + buffer = NULL; /* Must do this to avoid freeing the user data. */ + + if(result == ERROR) + { + D(("write failed ioerr=%ld",IoErr())); + + fam->fam_Error = __translate_io_error_to_errno(IoErr()); + goto out; + } + + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position += (ULONG)result; + + break; + + case file_action_close: + + SHOWMSG("file_action_close"); + + /* The following is almost guaranteed not to fail. */ + result = OK; + + /* If this is an alias, just remove it. */ + is_aliased = __fd_is_aliased(fd); + if(is_aliased) + { + __remove_fd_alias(fd); + } + else if (FLAG_IS_CLEAR(fd->fd_Flags,FDF_STDIO)) + { + /* Should we reset this file into line buffered mode? */ + if(FLAG_IS_SET(fd->fd_Flags,FDF_NON_BLOCKING) && FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE)) + SetMode(fd->fd_DefaultFile,DOSFALSE); + + /* Are we allowed to close this file? */ + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_NO_CLOSE)) + { + /* Call a cleanup function, such as the one which + * releases locked records. + */ + if(fd->fd_Cleanup != NULL) + (*fd->fd_Cleanup)(fd); + + PROFILE_OFF(); + + if(CANNOT Close(fd->fd_DefaultFile)) + { + fam->fam_Error = __translate_io_error_to_errno(IoErr()); + + result = EOF; + } + + PROFILE_ON(); + + fd->fd_DefaultFile = ZERO; + } + } + + __fd_unlock(fd); + + #if defined(__THREAD_SAFE) + { + /* Free the lock semaphore now. */ + if(NOT is_aliased) + __delete_semaphore(fd->fd_Lock); + } + #endif /* __THREAD_SAFE */ + + /* And that's the last for this file descriptor. */ + memset(fd,0,sizeof(*fd)); + + break; + + case file_action_seek: + + SHOWMSG("file_action_seek"); + + fam->fam_Error = EINVAL; + goto out; + + case file_action_set_blocking: + + SHOWMSG("file_action_set_blocking"); + + PROFILE_OFF(); + + if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE)) + { + LONG mode; + + SHOWMSG("changing the mode"); + + if(fam->fam_Arg != 0) + mode = DOSFALSE; /* buffered mode */ + else + mode = DOSTRUE; /* single character mode */ + + if(CANNOT SetMode(file,mode)) + { + fam->fam_Error = __translate_io_error_to_errno(IoErr()); + goto out; + } + + /* Update tios to reflect state change. */ + if(mode == DOSTRUE) + CLEAR_FLAG(tios->c_lflag,ICANON); + else + SET_FLAG(tios->c_lflag,ICANON); + + result = OK; + } + else + { + SHOWMSG("can't do anything here"); + + fam->fam_Error = EBADF; + } + + PROFILE_ON(); + + break; + + case file_action_examine: + + SHOWMSG("file_action_examine"); + + fh = BADDR(file); + + if(CANNOT __safe_examine_file_handle(file,fam->fam_FileInfo)) + { + LONG error; + + /* So that didn't work. Did the file system simply fail to + respond to the request or is something more sinister + at work? */ + error = IoErr(); + if(error != ERROR_ACTION_NOT_KNOWN) + { + SHOWMSG("couldn't examine the file"); + + fam->fam_Error = __translate_io_error_to_errno(error); + goto out; + } + + /* OK, let's have another look at this file. Could it be a + console stream? */ + if(NOT IsInteractive(file)) + { + SHOWMSG("whatever it is, we don't know"); + + fam->fam_Error = ENOSYS; + goto out; + } + + /* Make up some stuff for this stream. */ + memset(fam->fam_FileInfo,0,sizeof(*fam->fam_FileInfo)); + + DateStamp(&fam->fam_FileInfo->fib_Date); + + fam->fam_FileInfo->fib_DirEntryType = ST_CONSOLE; + } + + fam->fam_FileSystem = fh->fh_Type; + + result = OK; + + break; + + default: + + SHOWVALUE(fam->fam_Action); + + fam->fam_Error = EBADF; + break; + } + + out: + + __fd_unlock(fd); + + if(fam->fam_Action == file_action_close) + __stdio_unlock(); + + if(buffer != NULL) + free(buffer); + + SHOWVALUE(result); + + RETURN(result); + return(result); +} diff --git a/library/termios_headers.h b/library/termios_headers.h new file mode 100755 index 0000000..69617d7 --- /dev/null +++ b/library/termios_headers.h @@ -0,0 +1,74 @@ +/* + * $Id: termios_headers.h,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#define _TERMIOS_HEADERS_H + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#ifndef _TERMIOS_H +#include +#endif /* _TERMIOS_H */ + +/****************************************************************************/ + +extern int __termios_console_hook(struct fd *,struct file_action_message *); +extern int __termios_serial_hook(struct fd *,struct file_action_message *); +extern struct termios *__get_termios(struct fd *); + +/****************************************************************************/ + +enum /* Termios types. */ +{ + TIOST_INVALID = 0, + TIOST_CONSOLE, + TIOST_SERIAL +}; + +enum +{ + TIOS_FLUSH_OUTPUT, + TIOS_FLUSH_SYNC, + TIOS_FLUSH_INPUT, + TIOS_FLUSH_IO +}; + +/****************************************************************************/ + +#endif /* _TERMIOS_HEADERS_H */ diff --git a/library/termios_openserial.c b/library/termios_openserial.c new file mode 100755 index 0000000..3b4962b --- /dev/null +++ b/library/termios_openserial.c @@ -0,0 +1,55 @@ +/* + * $Id: termios_openserial.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +/* + * This is a clib2/Amiga specific function to obtain a file descriptor + * for a serial port. This is intended as an easy porting path for Unix + * code (which might e.g. open "/dev/ttyS0") and the same concept might + * be applied to other device types as well. + * + * TODO: Implement it. And a serial_fd_hook. And, well, everything else too.... + */ + +int +openserial(const char *device_name,int unit,int mode) +{ + __set_errno(EIO); + + return(ERROR); +} diff --git a/library/termios_tcdrain.c b/library/termios_tcdrain.c new file mode 100755 index 0000000..e8340fc --- /dev/null +++ b/library/termios_tcdrain.c @@ -0,0 +1,100 @@ +/* + * $Id: termios_tcdrain.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +#if defined(__amigaos4__) && !defined(Flush) +#define Flush(fh) FFlush(fh) +#endif /* __amigaos4__ && !Flush */ + +/****************************************************************************/ + +int +tcdrain(int file_descriptor) +{ + int result = ERROR; + struct fd *fd; + struct termios *tios; + + ENTER(); + + SHOWVALUE(file_descriptor); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + __set_errno(EBADF); + goto out; + } + + if(FLAG_IS_SET(fd->fd_Flags,FDF_TERMIOS)) + { + tios = fd->fd_Aux; + + switch(tios->type) + { + case TIOST_CONSOLE: + + /* This also discards any buffered input, but it does + not appear possible to drain the output buffer + otherwise. (?) */ + if(CANNOT Flush(fd->fd_DefaultFile)) + goto out; + + break; + + default: /* TODO: Serial port support. */ + + __set_errno(ENXIO); + goto out; + } + + result = OK; + } + else + { + result = fdatasync(file_descriptor); /* If called on a "regular" file. */ + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/termios_tcflow.c b/library/termios_tcflow.c new file mode 100755 index 0000000..66485f1 --- /dev/null +++ b/library/termios_tcflow.c @@ -0,0 +1,65 @@ +/* + * $Id: termios_tcflow.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +int +tcflow(int file_descriptor,int UNUSED action) +{ + int result = ERROR; + struct fd *fd; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWVALUE(action); + + fd=__get_file_descriptor(file_descriptor); + if(fd == NULL) + { + __set_errno(EBADF); + goto out; + } + + /* XXX TODO */ + result = OK; + + out: + + RETURN(result); + return(result); +} diff --git a/library/termios_tcflush.c b/library/termios_tcflush.c new file mode 100755 index 0000000..c9f9254 --- /dev/null +++ b/library/termios_tcflush.c @@ -0,0 +1,120 @@ +/* + * $Id: termios_tcflush.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +/* + * This is a bit messy and might possibly be done in a better way, but console + * termios support is a bit of a hack at best. + * tcflush() could possibly be implemented with using CMD_CLEAR with the + * console.device, but this would be just as messy and possibly break + * even more if e.g. stdin is a pipe. + */ + +int +tcflush(int file_descriptor,int queue) +{ + int result = ERROR; + struct fd *fd; + char buf[64]; + struct termios *tios; + + ENTER(); + + SHOWVALUE(file_descriptor); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL || FLAG_IS_CLEAR(fd->fd_Flags,FDF_TERMIOS)) + { + __set_errno(EBADF); + goto out; + } + + if(queue < TCIFLUSH || queue > TCIOFLUSH) + { + SHOWMSG("Invalid queue specified to tcflush()."); + + __set_errno(EINVAL); + goto out; + } + + tios = fd->fd_Aux; + + if(queue == TCIFLUSH || queue == TCIOFLUSH) + { + /* Set raw mode so we can read without blocking. */ + if(FLAG_IS_SET(tios->c_lflag,ICANON)) + { + SetMode(fd->fd_DefaultFile,DOSTRUE); + + SET_FLAG(fd->fd_Flags,FDF_NON_BLOCKING); + } + + while(WaitForChar(fd->fd_DefaultFile,1) != DOSFALSE) + { + if(__check_abort_enabled) + __check_abort(); + + Read(fd->fd_DefaultFile,buf,64); /* Read away available data. (upto 8k) */ + } + + /* Restore the Raw/Cooked mode. */ + if(FLAG_IS_SET(tios->c_lflag,ICANON)) + { + SetMode(fd->fd_DefaultFile,DOSFALSE); /* Set Cooked = Canonical mode. */ + + CLEAR_FLAG(fd->fd_Flags,FDF_NON_BLOCKING); + } + + result = OK; + } + else if (queue == TCOFLUSH || queue == TCIOFLUSH) + { + /* TODO: Can we actually discard data buffered on the file? + * For now we do the same as tcdrain(). + */ + result = tcdrain(file_descriptor); + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/termios_tcgetattr.c b/library/termios_tcgetattr.c new file mode 100755 index 0000000..00050d0 --- /dev/null +++ b/library/termios_tcgetattr.c @@ -0,0 +1,174 @@ +/* + * $Id: termios_tcgetattr.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +static const cc_t def_console_cc[NCCS]= +{ + 3, /* VINTR = ETX */ + 28, /* VQUIT = FS */ + 127, /* VERASE = DEL */ + 24, /* VKILL = DC4 */ + 4, /* VEOF = EOT */ + 1, /* VMIN = Minimum number of characters in a non-canonical read. */ + 0, /* VEOL = NUL */ + 0, /* VTIME = Timout in deciseconds for a non-canonical read. */ + 17, /* VSTART = DC1 */ + 19, /* VSTOP = DC3 */ + 26, /* VSUSP = SUB */ + 23 /* VWERASE = ETB */ +}; + +/******************************************************************/ + +static struct termios * +get_console_termios(struct fd *fd) +{ + struct termios *tios; + + /* Create a new, fresh termios. TODO: Actually query some values, + e.g. ICANON and ECHO should not be set for RAW consoles. */ + tios = malloc(sizeof(*tios)); + if(tios == NULL) + { + __set_errno(ENOMEM); + goto out; + } + + memset(tios,0,sizeof(*tios)); + + /* Set up the initial termios state. */ + tios->c_iflag = 0; + tios->c_oflag = 0; + tios->c_cflag = CS8|CLOCAL; + + if(FLAG_IS_SET(fd->fd_Flags,FDF_READ)) + SET_FLAG(tios->c_cflag,CREAD); + + tios->c_lflag = ISIG|ICANON|ECHO; + + memcpy(tios->c_cc,def_console_cc,NCCS); + + tios->c_ispeed = B9600; /* A default as good as any? */ + tios->c_ospeed = B9600; + + tios->type = TIOST_CONSOLE; + tios->flags = 0; + + /* Change the hook. */ + fd->fd_Action = __termios_console_hook; + fd->fd_Aux = tios; + + SET_FLAG(fd->fd_Flags,FDF_TERMIOS); + + out: + + return(tios); +} + +/******************************************************************/ + +struct termios * +__get_termios(struct fd *fd) +{ + struct termios *tios = NULL; + + if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_SOCKET)) /* Network socket. Remote terminal? */ + { + __set_errno(ENODEV); + goto out; + } + + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_INTERACTIVE)) + { + __set_errno(ENOTTY); + goto out; + } + + if(FLAG_IS_SET(fd->fd_Flags,FDF_TERMIOS)) + tios = fd->fd_Aux; + else + tios = get_console_termios(fd); + + out: + + return(tios); +} + +/******************************************************************/ + +int +tcgetattr(int file_descriptor,struct termios *user_tios) +{ + int result = ERROR; + struct fd *fd; + struct termios *tios; + + if(user_tios == NULL) + { + __set_errno(EFAULT); + goto out; + } + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + __set_errno(EBADF); + goto out; + } + + if(FLAG_IS_SET(fd->fd_Flags,FDF_TERMIOS)) + { + assert(fd->fd_Aux != NULL); + + memcpy(user_tios,fd->fd_Aux,sizeof(struct termios)); + } + else + { + tios = __get_termios(fd); + if(tios == NULL) + goto out; + + memcpy(user_tios,tios,sizeof(struct termios)); + } + + result = OK; + +out: + + return(result); +} diff --git a/library/termios_tcsendbreak.c b/library/termios_tcsendbreak.c new file mode 100755 index 0000000..04cc25b --- /dev/null +++ b/library/termios_tcsendbreak.c @@ -0,0 +1,108 @@ +/* + * $Id: termios_tcsendbreak.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +/* + * tcsendbreak() has a rather odd time specification. + * If duration is 0, it will send a BREAK for 0.25-0.5 seconds + * and if duration is non-zero... + * Linux asserts BREAK for N*duration where N is somewhere between 0.25 and 0.5 seconds. + * Solaris calls tcdrain() instead. (According to the manual) + * Let us try the Solaris way and see how it goes. + * + * If the file descriptor does not referr to a serial port, no action is needed. + */ + +int +tcsendbreak(int file_descriptor,int duration) +{ + int result = ERROR; + struct fd *fd; + struct termios *tios; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWVALUE(duration); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL || FLAG_IS_CLEAR(fd->fd_Flags,FDF_TERMIOS)) + { + __set_errno(EBADF); + goto out; + } + + assert( fd->fd_Aux != NULL ); + + tios = fd->fd_Aux; + + switch(tios->type) + { + case TIOST_CONSOLE: + + result = OK; + break; + + case TIOST_SERIAL: + + if(duration == 0) + { + /* TODO */ + result = OK; + } + else + { + result = tcdrain(file_descriptor); + } + + break; + + default: + + SHOWMSG("Invalid tios type in tcsendbreak."); + goto out; + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/termios_tcsetattr.c b/library/termios_tcsetattr.c new file mode 100755 index 0000000..92f1af5 --- /dev/null +++ b/library/termios_tcsetattr.c @@ -0,0 +1,156 @@ +/* + * $Id: termios_tcsetattr.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TERMIOS_HEADERS_H +#include "termios_headers.h" +#endif /* _TERMIOS_HEADERS_H */ + +/****************************************************************************/ + +static int +set_console_termios(struct fd *fd,struct termios *new_tios) +{ + struct termios *old_tios; + int result = ERROR; + + /* TODO: Check for some "impossible" combinations here? */ + + old_tios = __get_termios(fd); + if(old_tios == NULL) + goto out; + + if(old_tios->type != TIOST_CONSOLE) + goto out; + + if(FLAG_IS_CLEAR(new_tios->c_lflag,ICANON)) + { + SetMode(fd->fd_DefaultFile,DOSTRUE); /* Set Raw = Non-Canonical mode. */ + + SET_FLAG(fd->fd_Flags,FDF_NON_BLOCKING); + } + else + { + SetMode(fd->fd_DefaultFile,DOSFALSE); /* Set Cooked = Canonical mode. */ + + CLEAR_FLAG(fd->fd_Flags,FDF_NON_BLOCKING); + } + + /* Most of the processing (except raw/cooked mode switch) is handled in the hook. */ + memcpy(old_tios,new_tios,offsetof(struct termios,type)); + + result = OK; + + out: + + return(result); +} + +/****************************************************************************/ + +int +tcsetattr(int file_descriptor,int how,struct termios *tios) +{ + int result = ERROR; + struct fd *fd_Term; + struct termios new_tios; + int type; + + if(tios == NULL) + { + __set_errno(EFAULT); + goto out; + } + + fd_Term = __get_file_descriptor(file_descriptor); + if(fd_Term == NULL) + { + SHOWMSG("tcsetattr() was not called with a file descriptor.\n"); + + __set_errno(EBADF); + goto out; + } + + /* The following is in case the termios structure was manually constructed. (it should have been zero:ed in that case) */ + if(tios->type == TIOST_INVALID) + { + if(tcgetattr(file_descriptor,&new_tios) != OK) + goto out; /* Pass errno from tcgetattr() */ + + type = new_tios.type; + + memcpy(&new_tios,tios,sizeof(struct termios)); + + new_tios.c_ispeed = B9600; + new_tios.c_ospeed = B9600; + + new_tios.type = type; + + tios = &new_tios; + } + + if(tios->type == TIOST_SERIAL) + { + __set_errno(ENXIO); /* Unimplemented (for now). */ + goto out; + } + else if (tios->type == TIOST_CONSOLE) + { + if(how == TCSADRAIN) + { + if(tcdrain(file_descriptor) != OK) + goto out; + } + else if (how == TCSAFLUSH) + { + if(tcflush(file_descriptor,TCIOFLUSH) != OK) + goto out; + } + + if(set_console_termios(fd_Term,tios) != OK) + { + __set_errno(EIO); + goto out; + } + } + else + { + __set_errno(ENOTTY); + goto out; + } + + result = OK; + +out: + + return(result); +} diff --git a/library/unistd_ttyname.c b/library/unistd_ttyname.c new file mode 100755 index 0000000..dd77e88 --- /dev/null +++ b/library/unistd_ttyname.c @@ -0,0 +1,73 @@ +/* + * $Id: unistd_ttyname.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* + * Just a quick kludge. + */ + +char * +ttyname(int file_descriptor) +{ + char * result = NULL; + struct fd *fd; + + ENTER(); + + SHOWVALUE(file_descriptor); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + __set_errno(EBADF); + goto out; + } + + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_INTERACTIVE)) + { + __set_errno(ENOTTY); + goto out; + } + + result = "CONSOLE:"; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_ttyname_r.c b/library/unistd_ttyname_r.c new file mode 100755 index 0000000..d5f49c1 --- /dev/null +++ b/library/unistd_ttyname_r.c @@ -0,0 +1,81 @@ +/* + * $Id: unistd_ttyname_r.c,v 1.1 2005-06-04 10:46:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* + * Just a quick kludge, really. + */ + +int +ttyname_r(int file_descriptor,char *name,size_t buflen) +{ + struct fd *fd; + int result; + + ENTER(); + + SHOWVALUE(file_descriptor); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + result = EBADF; + goto out; + } + + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_INTERACTIVE)) + { + result = ENOTTY; + goto out; + } + + if(buflen < _POSIX_TTY_NAME_MAX) /* XXX Should this be _POSIX_PATH_MAX? */ + { + result = ERANGE; + goto out; + } + + strcpy(name,"CONSOLE:"); /* The buffer is at least 9 bytes, so this is ok. */ + + result = OK; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unix.lib_rev.h b/library/unix.lib_rev.h index 1b34d6a..6076c81 100644 --- a/library/unix.lib_rev.h +++ b/library/unix.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 192 -#define DATE "12.5.2005" -#define VERS "unix.lib 1.192" -#define VSTRING "unix.lib 1.192 (12.5.2005)\r\n" -#define VERSTAG "\0$VER: unix.lib 1.192 (12.5.2005)" +#define REVISION 193 +#define DATE "4.6.2005" +#define VERS "unix.lib 1.193" +#define VSTRING "unix.lib 1.193 (4.6.2005)\r\n" +#define VERSTAG "\0$VER: unix.lib 1.193 (4.6.2005)" diff --git a/library/unix.lib_rev.rev b/library/unix.lib_rev.rev index 86a0307..2455a46 100644 --- a/library/unix.lib_rev.rev +++ b/library/unix.lib_rev.rev @@ -1 +1 @@ -192 +193