Back to index

glibc  2.9
tcgetattr.c
Go to the documentation of this file.
00001 /* Copyright (C) 1992, 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <stddef.h>
00021 #include <sysv_termio.h>
00022 #include <termios.h>
00023 #include <sys/ioctl.h>
00024 
00025 /* Put the state of FD into *TERMIOS_P.  */
00026 int
00027 __tcgetattr (fd, termios_p)
00028      int fd;
00029      struct termios *termios_p;
00030 {
00031   struct __sysv_termio buf;
00032 
00033   if (termios_p == NULL)
00034     {
00035       __set_errno (EINVAL);
00036       return -1;
00037     }
00038 
00039   if (__ioctl (fd, _TCGETA, &buf) < 0)
00040     return -1;
00041 
00042   termios_p->c_cflag &= ~0x000f0000;
00043   termios_p->c_cflag |= (termios_p->c_cflag & 0xf) << 16;
00044 
00045   termios_p->c_iflag = 0;
00046   if (buf.c_iflag & _SYSV_IGNBRK)
00047     termios_p->c_iflag |= IGNBRK;
00048   if (buf.c_iflag & _SYSV_BRKINT)
00049     termios_p->c_iflag |= BRKINT;
00050   if (buf.c_iflag & _SYSV_IGNPAR)
00051     termios_p->c_iflag |= IGNPAR;
00052   if (buf.c_iflag & _SYSV_PARMRK)
00053     termios_p->c_iflag |= PARMRK;
00054   if (buf.c_iflag & _SYSV_INPCK)
00055     termios_p->c_iflag |= INPCK;
00056   if (buf.c_iflag & _SYSV_ISTRIP)
00057     termios_p->c_iflag |= ISTRIP;
00058   if (buf.c_iflag & _SYSV_INLCR)
00059     termios_p->c_iflag |= INLCR;
00060   if (buf.c_iflag & _SYSV_IGNCR)
00061     termios_p->c_iflag |= IGNCR;
00062   if (buf.c_iflag & _SYSV_ICRNL)
00063     termios_p->c_iflag |= ICRNL;
00064   if (buf.c_iflag & _SYSV_IXON)
00065     termios_p->c_iflag |= IXON;
00066   if (buf.c_iflag & _SYSV_IXOFF)
00067     termios_p->c_iflag |= IXOFF;
00068   if (buf.c_iflag & _SYSV_IXANY)
00069     termios_p->c_iflag |= IXANY;
00070   if (buf.c_iflag & _SYSV_IMAXBEL)
00071     termios_p->c_iflag |= IMAXBEL;
00072 
00073   termios_p->c_oflag = 0;
00074   if (buf.c_oflag & OPOST)
00075     termios_p->c_oflag |= OPOST;
00076   if (buf.c_oflag & ONLCR)
00077     termios_p->c_oflag |= ONLCR;
00078   termios_p->c_cflag = 0;
00079   switch (buf.c_cflag & _SYSV_CSIZE)
00080     {
00081     case _SYSV_CS5:
00082       termios_p->c_cflag |= CS5;
00083       break;
00084     case _SYSV_CS6:
00085       termios_p->c_cflag |= CS6;
00086       break;
00087     case _SYSV_CS7:
00088       termios_p->c_cflag |= CS7;
00089       break;
00090     case _SYSV_CS8:
00091       termios_p->c_cflag |= CS8;
00092       break;
00093     }
00094   if (buf.c_cflag & _SYSV_CSTOPB)
00095     termios_p->c_cflag |= CSTOPB;
00096   if (buf.c_cflag & _SYSV_CREAD)
00097     termios_p->c_cflag |= CREAD;
00098   if (buf.c_cflag & _SYSV_PARENB)
00099     termios_p->c_cflag |= PARENB;
00100   if (buf.c_cflag & _SYSV_PARODD)
00101     termios_p->c_cflag |= PARODD;
00102   if (buf.c_cflag & _SYSV_HUPCL)
00103     termios_p->c_cflag |= HUPCL;
00104   if (buf.c_cflag & _SYSV_CLOCAL)
00105     termios_p->c_cflag |= CLOCAL;
00106   termios_p->c_lflag = 0;
00107   if (buf.c_lflag & _SYSV_ISIG)
00108     termios_p->c_lflag |= ISIG;
00109   if (buf.c_lflag & _SYSV_ICANON)
00110     termios_p->c_lflag |= ICANON;
00111   if (buf.c_lflag & _SYSV_ECHO)
00112     termios_p->c_lflag |= ECHO;
00113   if (buf.c_lflag & _SYSV_ECHOE)
00114     termios_p->c_lflag |= ECHOE;
00115   if (buf.c_lflag & _SYSV_ECHOK)
00116     termios_p->c_lflag |= ECHOK;
00117   if (buf.c_lflag & _SYSV_ECHONL)
00118     termios_p->c_lflag |= ECHONL;
00119   if (buf.c_lflag & _SYSV_NOFLSH)
00120     termios_p->c_lflag |= NOFLSH;
00121   if (buf.c_lflag & _SYSV_TOSTOP)
00122     termios_p->c_lflag |= TOSTOP;
00123   if (buf.c_lflag & _SYSV_ECHOKE)
00124     termios_p->c_lflag |= ECHOKE;
00125   if (buf.c_lflag & _SYSV_ECHOPRT)
00126     termios_p->c_lflag |= ECHOPRT;
00127   if (buf.c_lflag & _SYSV_ECHOCTL)
00128     termios_p->c_lflag |= ECHOCTL;
00129   if (buf.c_lflag & _SYSV_FLUSHO)
00130     termios_p->c_lflag |= FLUSHO;
00131   if (buf.c_lflag & _SYSV_PENDIN)
00132     termios_p->c_lflag |= PENDIN;
00133   if (buf.c_lflag & _SYSV_IEXTEN)
00134     termios_p->c_lflag |= IEXTEN;
00135 
00136   termios_p->c_cc[VEOF] = buf.c_cc[_SYSV_VEOF];
00137   termios_p->c_cc[VEOL] = buf.c_cc[_SYSV_VEOL];
00138   termios_p->c_cc[VEOL2] = buf.c_cc[_SYSV_VEOL2];
00139   termios_p->c_cc[VERASE] = buf.c_cc[_SYSV_VERASE];
00140   termios_p->c_cc[VKILL] = buf.c_cc[_SYSV_VKILL];
00141   termios_p->c_cc[VINTR] = buf.c_cc[_SYSV_VINTR];
00142   termios_p->c_cc[VQUIT] = buf.c_cc[_SYSV_VQUIT];
00143   termios_p->c_cc[VSTART] = '\021'; /* XON (^Q).  */
00144   termios_p->c_cc[VSTOP] = '\023'; /* XOFF (^S).  */
00145   termios_p->c_cc[VSUSP] = '\0'; /* System V release 3 lacks job control.  */
00146   termios_p->c_cc[VMIN] = buf.c_cc[_SYSV_VMIN];
00147   termios_p->c_cc[VTIME] = buf.c_cc[_SYSV_VTIME];
00148 
00149   return 0;
00150 }
00151 
00152 weak_alias (__tcgetattr, tcgetattr)