tcgetattr函数的实现(glibc)
来源:互联网 发布:description软件 编辑:程序博客网 时间:2024/06/05 08:17
/* Copyright (C) 1992-2014 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, see
16 <http://www.gnu.org/licenses/>. */
17
18 #include <errno.h>
19 #include <string.h>
20 #include <termios.h>
21 #include <unistd.h>
22 #include <sys/ioctl.h>
23 #include <sys/types.h>
24 #include <sysdep.h>
25
26 /* The difference here is that the termios structure used in the
27 kernel is not the same as we use in the libc. Therefore we must
28 translate it here. */
29 #include <kernel_termios.h>
30
31 /* Put the state of FD into *TERMIOS_P. */
32 int
33 __tcgetattr (fd, termios_p)
34 int fd;
35 structtermios *termios_p;
36 {
37 struct __kernel_termios k_termios;
38 int retval;
39
40 retval =INLINE_SYSCALL (ioctl, 3, fd,TCGETS, &k_termios);
41
42 if (__glibc_likely (retval == 0))
43 {
44 termios_p->c_iflag = k_termios.c_iflag;
45 termios_p->c_oflag = k_termios.c_oflag;
46 termios_p->c_cflag = k_termios.c_cflag;
47 termios_p->c_lflag = k_termios.c_lflag;
48 termios_p->c_line = k_termios.c_line;
49 #ifdef _HAVE_STRUCT_TERMIOS_C_ISPEED
50 # ifdef _HAVE_C_ISPEED
51 termios_p->c_ispeed = k_termios.c_ispeed;
52 # else
53 termios_p->c_ispeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
54 # endif
55 #endif
56 #ifdef _HAVE_STRUCT_TERMIOS_C_OSPEED
57 # ifdef _HAVE_C_OSPEED
58 termios_p->c_ospeed = k_termios.c_ospeed;
59 # else
60 termios_p->c_ospeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
61 # endif
62 #endif
63 if (sizeof (cc_t) == 1 ||_POSIX_VDISABLE == 0
64 || (unsigned char)_POSIX_VDISABLE == (unsigned char) -1)
65 memset (__mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
66 __KERNEL_NCCS * sizeof (cc_t)),
67 _POSIX_VDISABLE, (NCCS -__KERNEL_NCCS) * sizeof (cc_t));
68 else
69 {
70 memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
71 __KERNEL_NCCS * sizeof (cc_t));
72
73 for (size_t cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
74 termios_p->c_cc[cnt] = _POSIX_VDISABLE;
75 }
76 }
77
78 return retval;
79 }
80
81 weak_alias (__tcgetattr,tcgetattr)
0 0
- tcgetattr函数的实现(glibc)
- tcgetattr函数的说明
- tcgetattr函数的说明
- 关于glibc的system函数调用实现
- glibc中字符串处理的几个函数实现分析
- glibc对malloc的实现
- Glibc 中malloc的实现
- tcgetattr函数与tcsetattr函数
- tcgetattr
- tcgetattr
- tcgetattr
- glibc中strcpy,strcat,strcmp,memcpy等函数的实现和分析
- Glibc中strlen的汇编实现
- glibc的qsort迭代实现源码
- glibc 实现代码的注释之翻译
- 串口----tcgetattr函数与tcsetattr函数
- tcgetattr函数与tcsetattr函数控制终端
- glibc 系列之strlen()函数
- [IOS]IOS8下地图定位的使用方法
- UVA130 HDU1628 Roman Roulette【vector】【约瑟夫问题】
- cocos2d-x 3.0 引用第三方库 及编译成apk时android mk文件写法
- 第十五周项目——oj d
- Java计算字符串和文件的MD5与SHA1
- tcgetattr函数的实现(glibc)
- MyEclipse环境下如何采用Maven导入ojdbc14.jar和ojdbc6.jar
- ASP.net 不能加载一个托管dll使用的非托管dll
- HDU——2058 The sum problem
- 在Ubuntu12.04和14.04用root用户登录
- Opensuse的静态IP设置
- Pow(x, n)
- Android开发 如何快速调用系统设置
- jquery修改css样式