OSDN Git Service

Hide more
[uclinux-h8/uClibc.git] / libc / termios / tcgetattr.c
1 /* Copyright (C) 1992, 1995, 1997, 1998 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #define mempcpy __mempcpy
20
21 #include <features.h>
22 #define __USE_GNU
23 #include <string.h>
24 #include <termios.h>
25 #include <unistd.h>
26 #include <sys/ioctl.h>
27 #include <sys/types.h>
28
29 /* The difference here is that the termios structure used in the
30    kernel is not the same as we use in the libc.  Therefore we must
31    translate it here.  */
32 #include "kernel_termios.h"
33
34 /* Put the state of FD into *TERMIOS_P.  */
35 int attribute_hidden __tcgetattr (int fd, struct termios *termios_p)
36 {
37     struct __kernel_termios k_termios;
38     int retval;
39
40     retval = ioctl (fd, TCGETS, &k_termios);
41
42     termios_p->c_iflag = k_termios.c_iflag;
43     termios_p->c_oflag = k_termios.c_oflag;
44     termios_p->c_cflag = k_termios.c_cflag;
45     termios_p->c_lflag = k_termios.c_lflag;
46     termios_p->c_line = k_termios.c_line;
47 #ifdef _HAVE_C_ISPEED
48     termios_p->c_ispeed = k_termios.c_ispeed;
49 #endif
50 #ifdef _HAVE_C_OSPEED
51     termios_p->c_ospeed = k_termios.c_ospeed;
52 #endif
53
54
55     if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
56             || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
57     {
58         __memset (mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
59                     __KERNEL_NCCS * sizeof (cc_t)),
60                 _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
61 #if 0   
62         __memset ( (__memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
63                         __KERNEL_NCCS * sizeof (cc_t)) + (__KERNEL_NCCS * sizeof (cc_t))) , 
64                 _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
65 #endif
66     } else {
67         size_t cnt;
68
69         __memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
70                 __KERNEL_NCCS * sizeof (cc_t));
71
72         for (cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
73             termios_p->c_cc[cnt] = _POSIX_VDISABLE;
74     }
75
76     return retval;
77 }
78 strong_alias(__tcgetattr,tcgetattr)