Back to index

glibc  2.9
tcsetattr.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991,95,96,2000,01,02 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 <termios.h>
00022 
00023 static int bad_speed (speed_t speed);
00024 
00025 /* Set the state of FD to *TERMIOS_P.  */
00026 int
00027 tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
00028 {
00029   if (fd < 0)
00030     {
00031       __set_errno (EBADF);
00032       return -1;
00033     }
00034   if (termios_p == NULL)
00035     {
00036       __set_errno (EINVAL);
00037       return -1;
00038     }
00039   switch (optional_actions)
00040     {
00041     case TCSANOW:
00042     case TCSADRAIN:
00043     case TCSAFLUSH:
00044       break;
00045     default:
00046       __set_errno (EINVAL);
00047       return -1;
00048     }
00049 
00050   if (bad_speed(termios_p->__ospeed) ||
00051       bad_speed(termios_p->__ispeed == 0 ?
00052               termios_p->__ospeed : termios_p->__ispeed))
00053     {
00054       __set_errno (EINVAL);
00055       return -1;
00056     }
00057 
00058   __set_errno (ENOSYS);
00059   return -1;
00060 }
00061 libc_hidden_def (tcsetattr)
00062 
00063 /* Strychnine checking.  */
00064 static int
00065 bad_speed (speed_t speed)
00066 {
00067   switch (speed)
00068     {
00069     case B0:
00070     case B50:
00071     case B75:
00072     case B110:
00073     case B134:
00074     case B150:
00075     case B200:
00076     case B300:
00077     case B600:
00078     case B1200:
00079     case B1800:
00080     case B2400:
00081     case B4800:
00082     case B9600:
00083     case B19200:
00084     case B38400:
00085     case B57600:
00086     case B115200:
00087     case B230400:
00088     case B460800:
00089     case B500000:
00090     case B576000:
00091     case B921600:
00092     case B1000000:
00093     case B1152000:
00094     case B1500000:
00095     case B2000000:
00096     case B2500000:
00097     case B3000000:
00098     case B3500000:
00099     case B4000000:
00100       return 0;
00101     default:
00102       return 1;
00103     }
00104 }
00105 
00106 
00107 stub_warning (tcsetattr)
00108 #include <stub-tag.h>