Back to index

glibc  2.9
tcgetattr.c
Go to the documentation of this file.
00001 /* Copyright (C) 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 <termios.h>
00021 #include "aix-termios.h"
00022 
00023 int
00024 tcgetattr (fd, linuxtermios_p)
00025      int fd;
00026      struct termios *linuxtermios_p;
00027 {
00028   struct aixtermios aixtermios;
00029   int result;
00030 
00031   result = /* make syscall */;
00032 
00033   if (result != -1)
00034     {
00035       /* Convert the result.  */
00036 
00037       linuxtermios_p->c_cc[VINTR] = aixtermios.c_cc[AIX_VINTR];
00038       linuxtermios_p->c_cc[VQUIT] = aixtermios.c_cc[AIX_VQUIT];
00039       linuxtermios_p->c_cc[VERASE] = aixtermios.c_cc[AIX_VERASE];
00040       linuxtermios_p->c_cc[VKILL] = aixtermios.c_cc[AIX_VKILL];
00041       linuxtermios_p->c_cc[VEOF] = aixtermios.c_cc[AIX_VEOF];
00042       // XXX VMIN has the same value as VEOF !?
00043       linuxtermios_p->c_cc[VEOL] = aixtermios.c_cc[AIX_VEOL];
00044       // XXX VTIME has the same value as VEOL !?
00045       linuxtermios_p->c_cc[VEOL2] = aixtermios.c_cc[AIX_VEOL2];
00046       linuxtermios_p->c_cc[VSTART] = aixtermios.c_cc[AIX_VSTART];
00047       linuxtermios_p->c_cc[VSTOP] = aixtermios.c_cc[AIX_VSTOP];
00048       linuxtermios_p->c_cc[VSUSP] = aixtermios.c_cc[AIX_VSUSP];
00049       // XXX No Linux equivalent for VDSUSP !?
00050       linuxtermios_p->c_cc[VREPRINT] = aixtermios.c_cc[AIX_VREPRINT];
00051       linuxtermios_p->c_cc[VDISCARD] = aixtermios.c_cc[AIX_VDISCARD];
00052       linuxtermios_p->c_cc[VWERASE] = aixtermios.c_cc[AIX_VWERASE];
00053       linuxtermios_p->c_cc[VLNEXT] = aixtermios.c_cc[AIX_VLNEXT];
00054 
00055       linuxtermios_p->c_cflag = aixtermios.c_c_flag & AIX_CBAUD;
00056 
00057       /* Only the IUCLC, IXANY, and IMAXBEL values are different in the
00058         c_iflag member.  */
00059       linuxtermios_p->c_iflag = aixtermios.c_iflag & 0x7ff;
00060       if (aixtermios.c_iflag & AIX_IXANY)
00061        linuxtermios_p->c_iflag |= IXANY;
00062       if (aixtermios.c_iflag & AIX_IUCLC)
00063        linuxtermios_p->c_iflag |= IUCLC;
00064       if (aixtermios.c_iflag & AIX_IMAXBEL)
00065        linuxtermios_p->c_iflag |= IMAXBEL;
00066 
00067       /* Many of the c_oflag files differ.  Bummer.  */
00068       linuxtermios_p->c_oflag = (aixtermios.c_oflag
00069                              & (OPOST | OCRNL | ONOCR | ONLRET | OFILL
00070                                 | OFDEL | TABDLY));
00071       if (aixtermios.c_oflag & AIX_OLCUC)
00072        linuxtermios_p->c_oflag |= OLCUC;
00073       if (aixtermios.c_oflag & AIX_ONLCR)
00074        linuxtermios_p->c_oflag |= ONLCR;
00075       if (aixtermiosc_oflag & AIX_NLDLY)
00076        linuxtermios_p->c_oflag |= NL1;
00077 
00078       if (aixtermiosc_oflag.c_oflag & AIX_TABDLY)
00079        {
00080 #define offset 2
00081 #if AIX_TAB1 << offset != TAB1 || AIX_TAB3 << offset != TAB3
00082 # error "Check the offset"
00083 #endif
00084          linuxtermios_p->c_oflag |= (aixtermios.c_oflag >> offset) & TABDLY;
00085 #undef offset
00086        }
00087       if (aixtermios.c_oflag & AIX_FFDLY)
00088        linuxtermios_p->c_oflag |= FF1;
00089       if (aixtermios.c_oflag & AIX_BSDLY)
00090        linuxtermios_p->c_oflag |= BS1;
00091       if (aixtermios.c_oflag & AIX_VTDLY)
00092        linuxtermios_p->c_oflag |= VT1;
00093 
00094       /* A lot of the c_cflag member is also different.  */
00095       if (aixtermios.c_cflag & AIX_CSIZE)
00096        {
00097 #define offset 4
00098 #if CSIZE >> offset != AIX_CSIZE
00099 # error "Check the offset"
00100 #endif
00101          linuxtermios_p->c_cflag |= (aixtermios.c_cflag >> offset) & CSIZE;
00102 #undef offset
00103        }
00104 
00105       if (aixtermios.c_cflag & AIX_STOPB)
00106        linuxtermios_p->c_cflag |= STOPB;
00107       if (aixtermios.c_cflag & AIX_CREAD)
00108        linuxtermios_p->c_cflag |= CREAD;
00109       if (aixtermios.cflag & AIX_PARENB)
00110        linuxtermios_p->c_cflag |= PARENB;
00111       if (aixtermios.cflag & AIX_PARODD)
00112        linuxtermios_p->c_cflag |= PARODD;
00113       if (aixtermios.c_cflag & AIX_HUPCL)
00114        linuxtermios_p->c_cflag |= HUPCL;
00115       if (aixtermios.c_cflag & AIX_CLOCAL)
00116        linuxtermios_p->c_cflag |= CLOCAL;
00117 
00118       /* The c_lflag is information is also different.  */
00119       aixtermios.c_lflag = 0;
00120       if (aixtermios.c_lflag & AIX_ISIG)
00121        linuxtermios_p->c_lflag |= ISIG;
00122       if (aixtermios.c_lflag & AIX_ICANON)
00123        linuxtermios_p->c_lflag |= ICANON;
00124       if (aixtermios.c_lflag & AIX_XCASE)
00125        linuxtermios_p->c_lflag |= XCASE;
00126       if (aixtermios.c_lflag & AIX_ECHO)
00127        linuxtermios_p->c_lflag |= ECHO;
00128       if (aixtermios.c_lflag & AIX_ECHOE)
00129        linuxtermios_p->c_lflag |= ECHOE;
00130       if (aixtermios.c_lflag & AIX_ECHOK)
00131        linuxtermios_p->c_lflag |= ECHOK;
00132       if (aixtermios.c_lflag & AIX_ECHONL)
00133        linuxtermios_p->c_lflag |= ECHONL;
00134       if (aixtermios.c_lflag & AIX_NOFLSH)
00135        linuxtermios_p->c_lflag |= NOFLSH;
00136       if (aixtermios.c_lflag & AIX_TOSTOP)
00137        linuxtermios_p->c_lflag |= TOSTOP;
00138       if (aixtermios.c_lflag & AIX_ECHOCTL)
00139        linuxtermios_p->c_lflag |= ECHOCTL;
00140       if (aixtermios.c_lflag & AIX_ECHOPRT)
00141        linuxtermios_p->c_lflag |= ECHOPRT;
00142       if (aixtermios.c_lflag & AIX_ECHOKE)
00143        linuxtermios_p->c_lflag |= ECHOKE;
00144       if (aixtermios.c_lflag & AIX_FLUSHO)
00145        linuxtermios_p->c_lflag |= FLUSHO;
00146       if (aixtermios.c_lflag & AIX_PENDIN)
00147        linuxtermios_p->c_lflag |= PENDIN;
00148       if (aixtermios->c_lflag & AIX_IEXTEN)
00149        linuxtermios_p->c_lflag |= IEXTEN;
00150     }
00151   else
00152     // Convert error here or in syscall.
00153     ;
00154 
00155   return result;
00156 }