diff options
author | Peter S. Mazinger <ps.m@gmx.net> | 2006-01-14 00:58:03 +0000 |
---|---|---|
committer | Peter S. Mazinger <ps.m@gmx.net> | 2006-01-14 00:58:03 +0000 |
commit | af0172162f7c653cad6a11ed1c1a5459bc154465 (patch) | |
tree | 70031dad1e7286d58762da7b9e3d3f93d043c278 /libc/termios | |
parent | c8609543a9a8bf6559c2931dbbef6b3c41b3fbf2 (diff) |
hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing headers, other jump relocs removed
Diffstat (limited to 'libc/termios')
-rw-r--r-- | libc/termios/Makefile.in | 30 | ||||
-rw-r--r-- | libc/termios/cfmakeraw.c | 31 | ||||
-rw-r--r-- | libc/termios/cfsetspeed.c | 164 | ||||
-rw-r--r-- | libc/termios/isatty.c | 32 | ||||
-rw-r--r-- | libc/termios/speed.c | 97 | ||||
-rw-r--r-- | libc/termios/tcdrain.c | 30 | ||||
-rw-r--r-- | libc/termios/tcflow.c | 30 | ||||
-rw-r--r-- | libc/termios/tcflush.c | 31 | ||||
-rw-r--r-- | libc/termios/tcgetattr.c | 20 | ||||
-rw-r--r-- | libc/termios/tcgetpgrp.c | 36 | ||||
-rw-r--r-- | libc/termios/tcgetsid.c | 24 | ||||
-rw-r--r-- | libc/termios/tcsendbrk.c | 48 | ||||
-rw-r--r-- | libc/termios/tcsetattr.c | 14 | ||||
-rw-r--r-- | libc/termios/tcsetpgrp.c | 30 | ||||
-rw-r--r-- | libc/termios/termios.c | 327 | ||||
-rw-r--r-- | libc/termios/ttyname.c | 58 |
16 files changed, 601 insertions, 401 deletions
diff --git a/libc/termios/Makefile.in b/libc/termios/Makefile.in index 415f32192..77f15c6fa 100644 --- a/libc/termios/Makefile.in +++ b/libc/termios/Makefile.in @@ -6,36 +6,14 @@ # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. # -CSRC:=tcgetattr.c tcgetsid.c tcsetattr.c ttyname.c - -MSRC:= termios.c -MOBJ:= tcdrain.o tcflow.o tcflush.o tcsendbreak.o tcsetpgrp.o tcgetpgrp.o \ - isatty.o cfgetospeed.o cfgetispeed.o cfsetospeed.o cfsetispeed.o \ - cfmakeraw.o cfsetspeed.o - TERMIOS_DIR:=$(top_srcdir)libc/termios TERMIOS_OUT:=$(top_builddir)libc/termios -TERMIOS_SRC:=$(patsubst %.c,$(TERMIOS_DIR)/%.c,$(CSRC)) -TERMIOS_OBJ:=$(patsubst %.c,$(TERMIOS_OUT)/%.o,$(CSRC)) - -TERMIOS_MSRC:=$(patsubst %.c,$(TERMIOS_DIR)/%.c,$(MSRC)) -TERMIOS_MOBJ:=$(patsubst %.o,$(TERMIOS_OUT)/%.o,$(MOBJ)) -TERMIOS_DEF:=$(patsubst %,-DL_%,$(subst .o,,$(notdir $(TERMIOS_MOBJ)))) - -TERMIOS_OBJS:=$(TERMIOS_OBJ) $(TERMIOS_MOBJ) - -$(TERMIOS_MOBJ): $(TERMIOS_MSRC) - $(compile.m) - -$(TERMIOS_MOBJ:.o=.os): $(TERMIOS_MSRC) - $(compile.m) - -libc-a-y+=$(TERMIOS_OBJS) -libc-so-y+=$(TERMIOS_OBJS:.o=.os) +TERMIOS_SRC:=$(wildcard $(TERMIOS_DIR)/*.c) +TERMIOS_OBJ:=$(patsubst $(TERMIOS_DIR)/%.c,$(TERMIOS_OUT)/%.o,$(TERMIOS_SRC)) -CFLAGS-multi-y+=$(TERMIOS_DEF) -libc-multi-y+=$(TERMIOS_SRC) $(TERMIOS_MSRC) +libc-a-y+=$(TERMIOS_OBJ) +libc-so-y+=$(TERMIOS_OBJ:.o=.os) objclean-y+=termios_objclean diff --git a/libc/termios/cfmakeraw.c b/libc/termios/cfmakeraw.c new file mode 100644 index 000000000..bf2012489 --- /dev/null +++ b/libc/termios/cfmakeraw.c @@ -0,0 +1,31 @@ +/* Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <termios.h> + +/* Set *T to indicate raw mode. */ +void cfmakeraw (struct termios *t) +{ + t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + t->c_oflag &= ~OPOST; + t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + t->c_cflag &= ~(CSIZE|PARENB); + t->c_cflag |= CS8; + t->c_cc[VMIN] = 1; /* read returns when one char is available. */ + t->c_cc[VTIME] = 0; +} diff --git a/libc/termios/cfsetspeed.c b/libc/termios/cfsetspeed.c new file mode 100644 index 000000000..e71c5e461 --- /dev/null +++ b/libc/termios/cfsetspeed.c @@ -0,0 +1,164 @@ +/* Copyright (C) 1992,93,96,97,98,2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <termios.h> +#include <errno.h> +#include <stddef.h> + +libc_hidden_proto(cfsetispeed) +libc_hidden_proto(cfsetospeed) + +struct speed_struct +{ + speed_t value; + speed_t internal; +}; + +static const struct speed_struct speeds[] = + { +#ifdef B0 + { 0, B0 }, +#endif +#ifdef B50 + { 50, B50 }, +#endif +#ifdef B75 + { 75, B75 }, +#endif +#ifdef B110 + { 110, B110 }, +#endif +#ifdef B134 + { 134, B134 }, +#endif +#ifdef B150 + { 150, B150 }, +#endif +#ifdef B200 + { 200, B200 }, +#endif +#ifdef B300 + { 300, B300 }, +#endif +#ifdef B600 + { 600, B600 }, +#endif +#ifdef B1200 + { 1200, B1200 }, +#endif +#ifdef B1200 + { 1200, B1200 }, +#endif +#ifdef B1800 + { 1800, B1800 }, +#endif +#ifdef B2400 + { 2400, B2400 }, +#endif +#ifdef B4800 + { 4800, B4800 }, +#endif +#ifdef B9600 + { 9600, B9600 }, +#endif +#ifdef B19200 + { 19200, B19200 }, +#endif +#ifdef B38400 + { 38400, B38400 }, +#endif +#ifdef B57600 + { 57600, B57600 }, +#endif +#ifdef B76800 + { 76800, B76800 }, +#endif +#ifdef B115200 + { 115200, B115200 }, +#endif +#ifdef B153600 + { 153600, B153600 }, +#endif +#ifdef B230400 + { 230400, B230400 }, +#endif +#ifdef B307200 + { 307200, B307200 }, +#endif +#ifdef B460800 + { 460800, B460800 }, +#endif +#ifdef B500000 + { 500000, B500000 }, +#endif +#ifdef B576000 + { 576000, B576000 }, +#endif +#ifdef B921600 + { 921600, B921600 }, +#endif +#ifdef B1000000 + { 1000000, B1000000 }, +#endif +#ifdef B1152000 + { 1152000, B1152000 }, +#endif +#ifdef B1500000 + { 1500000, B1500000 }, +#endif +#ifdef B2000000 + { 2000000, B2000000 }, +#endif +#ifdef B2500000 + { 2500000, B2500000 }, +#endif +#ifdef B3000000 + { 3000000, B3000000 }, +#endif +#ifdef B3500000 + { 3500000, B3500000 }, +#endif +#ifdef B4000000 + { 4000000, B4000000 }, +#endif + }; + + +/* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */ +int cfsetspeed (struct termios *termios_p, speed_t speed) +{ + size_t cnt; + + for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt) + if (speed == speeds[cnt].internal) + { + cfsetispeed (termios_p, speed); + cfsetospeed (termios_p, speed); + return 0; + } + else if (speed == speeds[cnt].value) + { + cfsetispeed (termios_p, speeds[cnt].internal); + cfsetospeed (termios_p, speeds[cnt].internal); + return 0; + } + + __set_errno (EINVAL); + + return -1; +} diff --git a/libc/termios/isatty.c b/libc/termios/isatty.c new file mode 100644 index 000000000..7532f334b --- /dev/null +++ b/libc/termios/isatty.c @@ -0,0 +1,32 @@ +/* Copyright (C) 1991, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <unistd.h> +#include <termios.h> + +libc_hidden_proto(isatty) +libc_hidden_proto(tcgetattr) + +/* Return 1 if FD is a terminal, 0 if not. */ +int isatty (int fd) +{ + struct termios term; + + return tcgetattr (fd, &term) == 0; +} +libc_hidden_def(isatty) diff --git a/libc/termios/speed.c b/libc/termios/speed.c new file mode 100644 index 000000000..52647b9cc --- /dev/null +++ b/libc/termios/speed.c @@ -0,0 +1,97 @@ +/* `struct termios' speed frobnication functions. Linux version. + Copyright (C) 1991,1992,1993,1995,1996,1997,1998,2000,2002,2003 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stddef.h> +#include <errno.h> +#include <termios.h> + +libc_hidden_proto(cfsetispeed) +libc_hidden_proto(cfsetospeed) + +/* This is a gross hack around a kernel bug. If the cfsetispeed functions + is called with the SPEED argument set to zero this means use the same + speed as for output. But we don't have independent input and output + speeds and therefore cannot record this. + + We use an unused bit in the `c_iflag' field to keep track of this + use of `cfsetispeed'. The value here must correspond to the one used + in `tcsetattr.c'. */ +#define IBAUD0 020000000000 + + +/* Return the output baud rate stored in *TERMIOS_P. */ +speed_t cfgetospeed (const struct termios *termios_p) +{ + return termios_p->c_cflag & (CBAUD | CBAUDEX); +} + +/* Return the input baud rate stored in *TERMIOS_P. + Although for Linux there is no difference between input and output + speed, the numerical 0 is a special case for the input baud rate. It + should set the input baud rate to the output baud rate. */ +speed_t cfgetispeed (const struct termios *termios_p) +{ + return ((termios_p->c_iflag & IBAUD0) + ? 0 : termios_p->c_cflag & (CBAUD | CBAUDEX)); +} + +/* Set the output baud rate stored in *TERMIOS_P to SPEED. */ +int cfsetospeed (struct termios *termios_p, speed_t speed) +{ + if ((speed & ~CBAUD) != 0 + && (speed < B57600 || speed > __MAX_BAUD)) + { + __set_errno (EINVAL); + return -1; + } + + termios_p->c_cflag &= ~(CBAUD | CBAUDEX); + termios_p->c_cflag |= speed; + + return 0; +} +libc_hidden_def (cfsetospeed) + + +/* Set the input baud rate stored in *TERMIOS_P to SPEED. + Although for Linux there is no difference between input and output + speed, the numerical 0 is a special case for the input baud rate. It + should set the input baud rate to the output baud rate. */ +int cfsetispeed (struct termios *termios_p, speed_t speed) +{ + if ((speed & ~CBAUD) != 0 + && (speed < B57600 || speed > __MAX_BAUD)) + { + __set_errno (EINVAL); + return -1; + } + + if (speed == 0) + termios_p->c_iflag |= IBAUD0; + else + { + termios_p->c_iflag &= ~IBAUD0; + termios_p->c_cflag &= ~(CBAUD | CBAUDEX); + termios_p->c_cflag |= speed; + } + + return 0; +} +libc_hidden_def (cfsetispeed) diff --git a/libc/termios/tcdrain.c b/libc/termios/tcdrain.c new file mode 100644 index 000000000..62bbd9179 --- /dev/null +++ b/libc/termios/tcdrain.c @@ -0,0 +1,30 @@ +/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <termios.h> +#include <sys/ioctl.h> + +libc_hidden_proto(ioctl) + +/* Wait for pending output to be written on FD. */ +int __libc_tcdrain (int fd) +{ + return ioctl(fd, TCSBRK, 1); +} +weak_alias (__libc_tcdrain, tcdrain) diff --git a/libc/termios/tcflow.c b/libc/termios/tcflow.c new file mode 100644 index 000000000..63f96a860 --- /dev/null +++ b/libc/termios/tcflow.c @@ -0,0 +1,30 @@ +/* tcflow -- Suspend or restart transmission on termios file descriptor. + Copyright (C) 1993,1997,2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <termios.h> +#include <sys/ioctl.h> + +libc_hidden_proto(ioctl) + +/* Suspend or restart transmission on FD. */ +int tcflow (int fd, int action) +{ + return ioctl (fd, TCXONC, action); +} diff --git a/libc/termios/tcflush.c b/libc/termios/tcflush.c new file mode 100644 index 000000000..159231fb1 --- /dev/null +++ b/libc/termios/tcflush.c @@ -0,0 +1,31 @@ +/* tcflush -- Flush pending data on termios file descriptor. Linux version. + Copyright (C) 1993,1997,2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <termios.h> +#include <sys/ioctl.h> + +libc_hidden_proto(ioctl) + +/* Flush pending data on FD. */ +int +tcflush (int fd, int queue_selector) +{ + return ioctl (fd, TCFLSH, queue_selector); +} diff --git a/libc/termios/tcgetattr.c b/libc/termios/tcgetattr.c index 3fd6d29d6..bc160248d 100644 --- a/libc/termios/tcgetattr.c +++ b/libc/termios/tcgetattr.c @@ -16,8 +16,6 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#define mempcpy __mempcpy - #include <features.h> #define __USE_GNU #include <string.h> @@ -26,18 +24,24 @@ #include <sys/ioctl.h> #include <sys/types.h> +libc_hidden_proto(ioctl) +libc_hidden_proto(memset) +libc_hidden_proto(memcpy) +libc_hidden_proto(mempcpy) +libc_hidden_proto(tcgetattr) + /* The difference here is that the termios structure used in the kernel is not the same as we use in the libc. Therefore we must translate it here. */ #include "kernel_termios.h" /* Put the state of FD into *TERMIOS_P. */ -int attribute_hidden __tcgetattr (int fd, struct termios *termios_p) +int tcgetattr (int fd, struct termios *termios_p) { struct __kernel_termios k_termios; int retval; - retval = __ioctl (fd, TCGETS, &k_termios); + retval = ioctl (fd, TCGETS, &k_termios); termios_p->c_iflag = k_termios.c_iflag; termios_p->c_oflag = k_termios.c_oflag; @@ -55,18 +59,18 @@ int attribute_hidden __tcgetattr (int fd, struct termios *termios_p) if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0 || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1) { - __memset (mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], + memset (mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], __KERNEL_NCCS * sizeof (cc_t)), _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t)); #if 0 - __memset ( (__memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], + memset ( (memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], __KERNEL_NCCS * sizeof (cc_t)) + (__KERNEL_NCCS * sizeof (cc_t))) , _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t)); #endif } else { size_t cnt; - __memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], + memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], __KERNEL_NCCS * sizeof (cc_t)); for (cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt) @@ -75,4 +79,4 @@ int attribute_hidden __tcgetattr (int fd, struct termios *termios_p) return retval; } -strong_alias(__tcgetattr,tcgetattr) +libc_hidden_def(tcgetattr) diff --git a/libc/termios/tcgetpgrp.c b/libc/termios/tcgetpgrp.c new file mode 100644 index 000000000..241670770 --- /dev/null +++ b/libc/termios/tcgetpgrp.c @@ -0,0 +1,36 @@ +/* Copyright (C) 1991, 1997, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sys/ioctl.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> + +libc_hidden_proto(tcgetpgrp) +libc_hidden_proto(ioctl) + +/* Return the foreground process group ID of FD. */ +pid_t tcgetpgrp (int fd) +{ + int pgrp; + + if (ioctl (fd, TIOCGPGRP, &pgrp) < 0) + return (pid_t) -1; + return (pid_t) pgrp; +} +libc_hidden_def (tcgetpgrp) diff --git a/libc/termios/tcgetsid.c b/libc/termios/tcgetsid.c index e4ba87ac5..c37023e8b 100644 --- a/libc/termios/tcgetsid.c +++ b/libc/termios/tcgetsid.c @@ -2,22 +2,19 @@ This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + Lesser General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#define getsid __getsid -#define tcgetpgrp __tcgetpgrp + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ #include <errno.h> #include <termios.h> @@ -26,6 +23,9 @@ #define __USE_XOPEN_EXTENDED #include <unistd.h> +libc_hidden_proto(ioctl) +libc_hidden_proto(getsid) +libc_hidden_proto(tcgetpgrp) /* Return the session ID of FD. */ pid_t tcgetsid (int fd) @@ -40,7 +40,7 @@ pid_t tcgetsid (int fd) int serrno = errno; int sid; - if (__ioctl (fd, TIOCGSID, &sid) < 0) + if (ioctl (fd, TIOCGSID, &sid) < 0) { if (errno == EINVAL) { diff --git a/libc/termios/tcsendbrk.c b/libc/termios/tcsendbrk.c new file mode 100644 index 000000000..ae04cb947 --- /dev/null +++ b/libc/termios/tcsendbrk.c @@ -0,0 +1,48 @@ +/* Send break to terminal. + Copyright (C) 1996, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <termios.h> +#include <sys/ioctl.h> + +libc_hidden_proto(ioctl) + +/* Send zero bits on FD. */ +int +tcsendbreak (int fd, int duration) +{ + /* The break lasts 0.25 to 0.5 seconds if DURATION is zero, + and an implementation-defined period if DURATION is nonzero. + We define a positive DURATION to be number of milliseconds to break. */ + if (duration <= 0) + return ioctl (fd, TCSBRK, 0); + +#ifdef TCSBRKP + /* Probably Linux-specific: a positive third TCSBRKP ioctl argument is + defined to be the number of 100ms units to break. */ + return ioctl (fd, TCSBRKP, (duration + 99) / 100); +#else + /* ioctl can't send a break of any other duration for us. + This could be changed to use trickery (e.g. lower speed and + send a '\0') to send the break, but for now just return an error. */ + __set_errno (EINVAL); + return -1; +#endif +} diff --git a/libc/termios/tcsetattr.c b/libc/termios/tcsetattr.c index 3afa1012c..847023f86 100644 --- a/libc/termios/tcsetattr.c +++ b/libc/termios/tcsetattr.c @@ -22,6 +22,10 @@ #include <sys/ioctl.h> #include <sys/types.h> +libc_hidden_proto(tcsetattr) +libc_hidden_proto(memcpy) +libc_hidden_proto(ioctl) + /* The difference here is that the termios structure used in the kernel is not the same as we use in the libc. Therefore we must translate it here. */ @@ -47,7 +51,7 @@ /* Set the state of FD to *TERMIOS_P. */ -int attribute_hidden __tcsetattr (int fd, int optional_actions, const struct termios *termios_p) +int tcsetattr (int fd, int optional_actions, const struct termios *termios_p) { struct __kernel_termios k_termios; unsigned long int cmd; @@ -80,17 +84,17 @@ int attribute_hidden __tcsetattr (int fd, int optional_actions, const struct ter #ifdef _HAVE_C_OSPEED k_termios.c_ospeed = termios_p->c_ospeed; #endif - __memcpy (&k_termios.c_cc[0], &termios_p->c_cc[0], + memcpy (&k_termios.c_cc[0], &termios_p->c_cc[0], __KERNEL_NCCS * sizeof (cc_t)); - retval = __ioctl (fd, cmd, &k_termios); + retval = ioctl (fd, cmd, &k_termios); if (retval == 0 && cmd == TCSETS) { /* The Linux kernel has a bug which silently ignore the invalid c_cflag on pty. We have to check it here. */ int save = errno; - retval = __ioctl (fd, TCGETS, &k_termios); + retval = ioctl (fd, TCGETS, &k_termios); if (retval) { /* We cannot verify if the setting is ok. We don't return @@ -114,4 +118,4 @@ int attribute_hidden __tcsetattr (int fd, int optional_actions, const struct ter return retval; } -strong_alias(__tcsetattr,tcsetattr) +libc_hidden_def(tcsetattr) diff --git a/libc/termios/tcsetpgrp.c b/libc/termios/tcsetpgrp.c new file mode 100644 index 000000000..9bf1cdaef --- /dev/null +++ b/libc/termios/tcsetpgrp.c @@ -0,0 +1,30 @@ +/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <errno.h> +#include <unistd.h> + +libc_hidden_proto(ioctl) + +/* Set the foreground process group ID of FD set PGRP_ID. */ +int tcsetpgrp (int fd, pid_t pgrp_id) +{ + return ioctl (fd, TIOCSPGRP, &pgrp_id); +} diff --git a/libc/termios/termios.c b/libc/termios/termios.c deleted file mode 100644 index 680796e16..000000000 --- a/libc/termios/termios.c +++ /dev/null @@ -1,327 +0,0 @@ -/* Copyright (C) 1992, 1993, 1996, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - - - About the only thing remaining here fromthe original Linux-8086 C library - version by Robert de Bath <robert@mayday.compulink.co.uk>, is the general - layout. All else has been recently stolen from GNU libc, since that was - much more current. - */ - -#define tcgetattr __tcgetattr - -#include <errno.h> -#include <stddef.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <unistd.h> -#include <termios.h> - -#ifdef L_isatty -/* Return 1 if FD is a terminal, 0 if not. */ - -int attribute_hidden __isatty(int fd) -{ - struct termios term; - return (tcgetattr (fd, &term) == 0); -} -strong_alias(__isatty,isatty) -#endif - -#ifdef L_tcdrain -/* Wait for pending output to be written on FD. */ -int __libc_tcdrain (int fd) -{ - /* With an argument of 1, TCSBRK waits for the output to drain. */ - return __ioctl(fd, TCSBRK, 1); -} -weak_alias(__libc_tcdrain, tcdrain) -#endif - -#ifdef L_tcflow -/* Suspend or restart transmission on FD. */ -int tcflow ( int fd, int action) -{ - return __ioctl(fd, TCXONC, action); -} -#endif - -#ifdef L_tcflush -/* Flush pending data on FD. */ -int tcflush ( int fd, int queue_selector) -{ - return __ioctl(fd, TCFLSH, queue_selector); -} -#endif - -#ifdef L_tcsendbreak -/* Send zero bits on FD. */ -int tcsendbreak( int fd, int duration) -{ - /* The break lasts 0.25 to 0.5 seconds if DURATION is zero, - and an implementation-defined period if DURATION is nonzero. - We define a positive DURATION to be number of milliseconds to break. */ - if (duration <= 0) - return __ioctl(fd, TCSBRK, 0); - -#ifdef TCSBRKP - /* Probably Linux-specific: a positive third TCSBRKP ioctl argument is - defined to be the number of 100ms units to break. */ - return __ioctl(fd, TCSBRKP, (duration + 99) / 100); -#else - /* ioctl can't send a break of any other duration for us. - This could be changed to use trickery (e.g. lower speed and - send a '\0') to send the break, but for now just return an error. */ - __set_errno (EINVAL); - return -1; -#endif -} -#endif - -#ifdef L_tcsetpgrp -/* Set the foreground process group ID of FD set PGRP_ID. */ -int tcsetpgrp ( int fd, pid_t pgrp_id) -{ - return __ioctl (fd, TIOCSPGRP, &pgrp_id); -} -#endif - -#ifdef L_tcgetpgrp -/* Return the foreground process group ID of FD. */ -pid_t attribute_hidden __tcgetpgrp ( int fd) -{ - int pgrp; - - if (__ioctl (fd, TIOCGPGRP, &pgrp) < 0) - return (pid_t) -1; - return (pid_t) pgrp; -} -strong_alias(__tcgetpgrp,tcgetpgrp) -#endif - -/* This is a gross hack around a kernel bug. If the cfsetispeed functions is - * called with the SPEED argument set to zero this means use the same speed as - * for output. But we don't have independent input and output speeds and - * therefore cannot record this. - * - * We use an unused bit in the `c_iflag' field to keep track of this use of - * `cfsetispeed'. The value here must correspond to the one used in - * `tcsetattr.c'. */ -#define IBAUD0 020000000000 - -#ifdef L_cfgetospeed -/* Return the output baud rate stored in *TERMIOS_P. */ -speed_t cfgetospeed ( const struct termios *termios_p) -{ - return termios_p->c_cflag & (CBAUD | CBAUDEX); -} -#endif - -#ifdef L_cfgetispeed - -/* Return the input baud rate stored in *TERMIOS_P. - * Although for Linux there is no difference between input and output - * speed, the numerical 0 is a special case for the input baud rate. It - * should set the input baud rate to the output baud rate. */ -speed_t cfgetispeed (const struct termios *termios_p) -{ - return ((termios_p->c_iflag & IBAUD0) - ? 0 : termios_p->c_cflag & (CBAUD | CBAUDEX)); -} -#endif - -#ifdef L_cfsetospeed -/* Set the output baud rate stored in *TERMIOS_P to SPEED. */ -int attribute_hidden __cfsetospeed (struct termios *termios_p, speed_t speed) -{ - if ((speed & ~CBAUD) != 0 - && (speed < B57600 || speed > B460800)) - { - __set_errno(EINVAL); - return -1; - } - - termios_p->c_cflag &= ~(CBAUD | CBAUDEX); - termios_p->c_cflag |= speed; - - return 0; -} -strong_alias(__cfsetospeed,cfsetospeed) -#endif - -#ifdef L_cfsetispeed -/* Set the input baud rate stored in *TERMIOS_P to SPEED. - * Although for Linux there is no difference between input and output - * speed, the numerical 0 is a special case for the input baud rate. It - * should set the input baud rate to the output baud rate. */ -int attribute_hidden __cfsetispeed ( struct termios *termios_p, speed_t speed) -{ - if ((speed & ~CBAUD) != 0 - && (speed < B57600 || speed > B460800)) - { - __set_errno(EINVAL); - return -1; - } - - if (speed == 0) - termios_p->c_iflag |= IBAUD0; - else - { - termios_p->c_iflag &= ~IBAUD0; - termios_p->c_cflag &= ~(CBAUD | CBAUDEX); - termios_p->c_cflag |= speed; - } - - return 0; -} -strong_alias(__cfsetispeed,cfsetispeed) -#endif - -#ifdef L_cfsetspeed - -extern int __cfsetospeed (struct termios *__termios_p, speed_t __speed) __THROW attribute_hidden; -extern int __cfsetispeed (struct termios *__termios_p, speed_t __speed) __THROW attribute_hidden; - -struct speed_struct -{ - speed_t value; - speed_t internal; -}; - -static const struct speed_struct speeds[] = - { -#ifdef B0 - { 0, B0 }, -#endif -#ifdef B50 - { 50, B50 }, -#endif -#ifdef B75 - { 75, B75 }, -#endif -#ifdef B110 - { 110, B110 }, -#endif -#ifdef B134 - { 134, B134 }, -#endif -#ifdef B150 - { 150, B150 }, -#endif -#ifdef B200 - { 200, B200 }, -#endif -#ifdef B300 - { 300, B300 }, -#endif -#ifdef B600 - { 600, B600 }, -#endif -#ifdef B1200 - { 1200, B1200 }, -#endif -#ifdef B1200 - { 1200, B1200 }, -#endif -#ifdef B1800 - { 1800, B1800 }, -#endif -#ifdef B2400 - { 2400, B2400 }, -#endif -#ifdef B4800 - { 4800, B4800 }, -#endif -#ifdef B9600 - { 9600, B9600 }, -#endif -#ifdef B19200 - { 19200, B19200 }, -#endif -#ifdef B38400 - { 38400, B38400 }, -#endif -#ifdef B57600 - { 57600, B57600 }, -#endif -#ifdef B76800 - { 76800, B76800 }, -#endif -#ifdef B115200 - { 115200, B115200 }, -#endif -#ifdef B153600 - { 153600, B153600 }, -#endif -#ifdef B230400 - { 230400, B230400 }, -#endif -#ifdef B307200 - { 307200, B307200 }, -#endif -#ifdef B460800 - { 460800, B460800 }, -#endif - }; - - -/* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */ -int cfsetspeed (struct termios *termios_p, speed_t speed) -{ - size_t cnt; - - for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt) - if (speed == speeds[cnt].internal) - { - __cfsetispeed (termios_p, speed); - __cfsetospeed (termios_p, speed); - return 0; - } - else if (speed == speeds[cnt].value) - { - __cfsetispeed (termios_p, speeds[cnt].internal); - __cfsetospeed (termios_p, speeds[cnt].internal); - return 0; - } - - __set_errno (EINVAL); - - return -1; -} -#endif - -#ifdef L_cfmakeraw -/* Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. -*/ -#include <termios.h> - -/* Set *T to indicate raw mode. */ -void -cfmakeraw (struct termios *t) -{ - t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); - t->c_oflag &= ~OPOST; - t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); - t->c_cflag &= ~(CSIZE|PARENB); - t->c_cflag |= CS8; - t->c_cc[VMIN] = 1; /* read returns when one char is available. */ - t->c_cc[VTIME] = 0; -} -#endif - diff --git a/libc/termios/ttyname.c b/libc/termios/ttyname.c index 271c9a4ab..001681caa 100644 --- a/libc/termios/ttyname.c +++ b/libc/termios/ttyname.c @@ -1,17 +1,11 @@ -#define opendir __opendir -#define closedir __closedir -#define readdir __readdir -#define isatty __isatty - -#include <string.h> -#include <errno.h> -#include <assert.h> -#include <unistd.h> -#include <dirent.h> -#include <sys/stat.h> - -/* Jan 1, 2004 Manuel Novoa III +/* + * Copyright (C) Jan 1, 2004 Manuel Novoa III + * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* * Kept the same approach, but rewrote the code for the most part. * Fixed some minor issues plus (as I recall) one SUSv3 errno case. */ @@ -29,6 +23,24 @@ * * If you change this, also change _SC_TTY_NAME_MAX in libc/unistd/sysconf.c */ + +#include <string.h> +#include <errno.h> +#include <assert.h> +#include <unistd.h> +#include <dirent.h> +#include <sys/stat.h> + +libc_hidden_proto(ttyname_r) +libc_hidden_proto(fstat) +libc_hidden_proto(lstat) +libc_hidden_proto(strcpy) +libc_hidden_proto(strlen) +libc_hidden_proto(opendir) +libc_hidden_proto(closedir) +libc_hidden_proto(readdir) +libc_hidden_proto(isatty) + #define TTYNAME_BUFLEN 32 static const char dirlist[] = @@ -39,7 +51,7 @@ static const char dirlist[] = "\011/dev/pts/\0" /* and try /dev/pts next */ "\005/dev/\0"; /* and try walking through /dev last */ -int attribute_hidden __ttyname_r(int fd, char *ubuf, size_t ubuflen) +int ttyname_r(int fd, char *ubuf, size_t ubuflen) { struct dirent *d; struct stat st; @@ -51,7 +63,7 @@ int attribute_hidden __ttyname_r(int fd, char *ubuf, size_t ubuflen) size_t len; char buf[TTYNAME_BUFLEN]; - if (__fstat(fd, &st) < 0) { + if (fstat(fd, &st) < 0) { return errno; } @@ -66,7 +78,7 @@ int attribute_hidden __ttyname_r(int fd, char *ubuf, size_t ubuflen) assert(len + 2 <= TTYNAME_BUFLEN); /* dirname + 1 char + nul */ - __strcpy(buf, p); + strcpy(buf, p); s = buf + len; len = (TTYNAME_BUFLEN-2) - len; /* Available non-nul space. */ @@ -77,13 +89,13 @@ int attribute_hidden __ttyname_r(int fd, char *ubuf, size_t ubuflen) while ((d = readdir(fp)) != NULL) { /* This should never trigger for standard names, but we * check it to be safe. */ - if (__strlen(d->d_name) > len) { /* Too big? */ + if (strlen(d->d_name) > len) { /* Too big? */ continue; } - __strcpy(s, d->d_name); + strcpy(s, d->d_name); - if ((__lstat(buf, &dst) == 0) + if ((lstat(buf, &dst) == 0) #if 0 /* Stupid filesystems like cramfs fail to guarantee that * st_ino and st_dev uniquely identify a file, contrary to @@ -98,8 +110,8 @@ int attribute_hidden __ttyname_r(int fd, char *ubuf, size_t ubuflen) /* We treat NULL buf as ERANGE rather than EINVAL. */ rv = ERANGE; - if (ubuf && (__strlen(buf) <= ubuflen)) { - __strcpy(ubuf, buf); + if (ubuf && (strlen(buf) <= ubuflen)) { + strcpy(ubuf, buf); rv = 0; } goto DONE; @@ -114,11 +126,11 @@ int attribute_hidden __ttyname_r(int fd, char *ubuf, size_t ubuflen) return rv; } -strong_alias(__ttyname_r,ttyname_r) +libc_hidden_def(ttyname_r) char *ttyname(int fd) { static char name[TTYNAME_BUFLEN]; - return __ttyname_r(fd, name, TTYNAME_BUFLEN) ? NULL : name; + return ttyname_r(fd, name, TTYNAME_BUFLEN) ? NULL : name; } |