Back to index

glibc  2.9
speed.c
Go to the documentation of this file.
00001 /* `struct termios' speed frobnication functions.  AIX version.
00002    Copyright (C) 2000, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stddef.h>
00021 #include <errno.h>
00022 #include <termios.h>
00023 
00024 /* Return the output baud rate stored in *TERMIOS_P.  */
00025 speed_t
00026 cfgetospeed (termios_p)
00027      const struct termios *termios_p;
00028 {
00029   return termios_p->c_cflag & 0x0000000f;
00030 }
00031 
00032 /* Return the input baud rate stored in *TERMIOS_P.  */
00033 speed_t
00034 cfgetispeed (termios_p)
00035      const struct termios *termios_p;
00036 {
00037   return (termios_p->c_cflag & 0x000f0000) >> 16;
00038 }
00039 
00040 /* Set the output baud rate stored in *TERMIOS_P to SPEED.  */
00041 int
00042 cfsetospeed (termios_p, speed)
00043      struct termios *termios_p;
00044      speed_t speed;
00045 {
00046   if (termios_p == NULL)
00047     {
00048       __set_errno (EINVAL);
00049       return -1;
00050     }
00051 
00052   termios_p->c_cflag &= ~0x0000000f;
00053   termios_p->c_cflag |= speed & 0x0000000f;
00054   return 0;
00055 }
00056 libc_hidden_def (cfsetospeed)
00057 
00058 
00059 /* Set the input baud rate stored in *TERMIOS_P to SPEED.  */
00060 int
00061 cfsetispeed (termios_p, speed)
00062      struct termios *termios_p;
00063      speed_t speed;
00064 {
00065   if (termios_p == NULL)
00066     {
00067       __set_errno (EINVAL);
00068       return -1;
00069     }
00070 
00071   termios_p->c_cflag &= ~0x000f0000;
00072   termios_p->c_cflag |= (speed << 16) & ~0x000f0000;
00073   return 0;
00074 }
00075 libc_hidden_def (cfsetispeed)