验证stdin和stdout为行缓冲
2015-09-23 14:09
323 查看
一、源代码:
1 #include "apue.h"
2 int main()
3 {
4 int c;
5 while ( (c = getc(stdin)) != EOF)
6 if ( putc(c,stdout) == EOF)
7 err_sys("putc error");
8 if (ferror(stdin))
9 err_sys("getc error");
10 exit(0);
11 }
二、gdb调试:
<bldc:/home/tingbinz/apue.3e/SBSCODE/5>R*_*G:gdb intoout
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.5.1"...
(gdb) l
1 #include "apue.h"
2 int main()
3 {
4 int c;
5 while ( (c = getc(stdin)) != EOF)
6 if ( putc(c,stdout) == EOF)
7 err_sys("putc error");
8 if (ferror(stdin))
9 err_sys("getc error");
10 exit(0);
(gdb) break 4
Breakpoint 1 at 0x10d44: file 5_4.c, line 4.
(gdb) break 5
Note: breakpoint 1 also set at pc 0x10d44.
Breakpoint 2 at 0x10d44: file 5_4.c, line 5.
(gdb) run
Starting program: /home/tingbinz/apue.3e/SBSCODE/5/intoout
Breakpoint 1, main () at 5_4.c:5
5 while ( (c = getc(stdin)) != EOF)
(gdb) n
hello
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
hello
三、源代码 换为stderr
<bldc:/home/tingbinz/apue.3e/SBSCODE/5>R*_*G:vim 5_4a.c
#include "apue.h"
int main()
{
int c;
while ( (c = getc(stdin)) != EOF)
if ( putc(c,stderr) == EOF)
err_sys("putc error");
if (ferror(stdin))
err_sys("getc error");
exit(0);
}
四、编译:
<bldc:/home/tingbinz/apue.3e/SBSCODE/5>R*_*G:gcc -Wall -ggdb3 -o intoerr 5_4a.c
In file included from apue.h:132,
from 5_4a.c:1:
error.c: In function `err_doit':
error.c:121: warning: implicit declaration of function `vsnprintf'
error.c:123: warning: implicit declaration of function `snprintf'
五、gdb调试结果:
<bldc:/home/tingbinz/apue.3e/SBSCODE/5>R*_*G:gdb intoerr
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.5.1"...
(gdb) l
1 #include "apue.h"
2 int main()
3 {
4 int c;
5 while ( (c = getc(stdin)) != EOF)
6 if ( putc(c,stderr) == EOF)
7 err_sys("putc error");
8 if (ferror(stdin))
9 err_sys("getc error");
10 exit(0);
(gdb) break 5
Breakpoint 1 at 0x10d44: file 5_4a.c, line 5.
(gdb) run
Starting program: /home/tingbinz/apue.3e/SBSCODE/5/intoerr
Breakpoint 1, main () at 5_4a.c:5
5 while ( (c = getc(stdin)) != EOF)
(gdb) n
hello
6 if ( putc(c,stderr) == EOF)
(gdb) n
h6 if ( putc(c,stderr) == EOF)
(gdb) n
e6 if ( putc(c,stderr) == EOF)
(gdb) n
l6 if ( putc(c,stderr) == EOF)
(gdb) n
l6 if ( putc(c,stderr) == EOF)
(gdb) n
o6 if ( putc(c,stderr) == EOF)
(gdb) n
world
6 if ( putc(c,stderr) == EOF)
(gdb) n
w6 if ( putc(c,stderr) == EOF)
(gdb)
1 #include "apue.h"
2 int main()
3 {
4 int c;
5 while ( (c = getc(stdin)) != EOF)
6 if ( putc(c,stdout) == EOF)
7 err_sys("putc error");
8 if (ferror(stdin))
9 err_sys("getc error");
10 exit(0);
11 }
二、gdb调试:
<bldc:/home/tingbinz/apue.3e/SBSCODE/5>R*_*G:gdb intoout
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.5.1"...
(gdb) l
1 #include "apue.h"
2 int main()
3 {
4 int c;
5 while ( (c = getc(stdin)) != EOF)
6 if ( putc(c,stdout) == EOF)
7 err_sys("putc error");
8 if (ferror(stdin))
9 err_sys("getc error");
10 exit(0);
(gdb) break 4
Breakpoint 1 at 0x10d44: file 5_4.c, line 4.
(gdb) break 5
Note: breakpoint 1 also set at pc 0x10d44.
Breakpoint 2 at 0x10d44: file 5_4.c, line 5.
(gdb) run
Starting program: /home/tingbinz/apue.3e/SBSCODE/5/intoout
Breakpoint 1, main () at 5_4.c:5
5 while ( (c = getc(stdin)) != EOF)
(gdb) n
hello
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
6 if ( putc(c,stdout) == EOF)
(gdb) n
hello
三、源代码 换为stderr
<bldc:/home/tingbinz/apue.3e/SBSCODE/5>R*_*G:vim 5_4a.c
#include "apue.h"
int main()
{
int c;
while ( (c = getc(stdin)) != EOF)
if ( putc(c,stderr) == EOF)
err_sys("putc error");
if (ferror(stdin))
err_sys("getc error");
exit(0);
}
四、编译:
<bldc:/home/tingbinz/apue.3e/SBSCODE/5>R*_*G:gcc -Wall -ggdb3 -o intoerr 5_4a.c
In file included from apue.h:132,
from 5_4a.c:1:
error.c: In function `err_doit':
error.c:121: warning: implicit declaration of function `vsnprintf'
error.c:123: warning: implicit declaration of function `snprintf'
五、gdb调试结果:
<bldc:/home/tingbinz/apue.3e/SBSCODE/5>R*_*G:gdb intoerr
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.5.1"...
(gdb) l
1 #include "apue.h"
2 int main()
3 {
4 int c;
5 while ( (c = getc(stdin)) != EOF)
6 if ( putc(c,stderr) == EOF)
7 err_sys("putc error");
8 if (ferror(stdin))
9 err_sys("getc error");
10 exit(0);
(gdb) break 5
Breakpoint 1 at 0x10d44: file 5_4a.c, line 5.
(gdb) run
Starting program: /home/tingbinz/apue.3e/SBSCODE/5/intoerr
Breakpoint 1, main () at 5_4a.c:5
5 while ( (c = getc(stdin)) != EOF)
(gdb) n
hello
6 if ( putc(c,stderr) == EOF)
(gdb) n
h6 if ( putc(c,stderr) == EOF)
(gdb) n
e6 if ( putc(c,stderr) == EOF)
(gdb) n
l6 if ( putc(c,stderr) == EOF)
(gdb) n
l6 if ( putc(c,stderr) == EOF)
(gdb) n
o6 if ( putc(c,stderr) == EOF)
(gdb) n
world
6 if ( putc(c,stderr) == EOF)
(gdb) n
w6 if ( putc(c,stderr) == EOF)
(gdb)
相关文章推荐
- CEPH浅析”系列之三——CEPH的设计思想
- LaTeX手动安装宏包(package)以及生成帮助文档的整套流程
- 每天一个linux命令(6):rmdir 命令
- 全面解读python web 程序的9种部署方式
- 驱动开发中使用安全字符串函数
- Android Activity原理以及其子类描述
- HDU 1561
- Activity的启动模式
- PHP Session可能会引起并发问题
- 队列的数组实现
- ASP.NET 数据库页面访问简单工具
- javascript js保留小数位数的方法
- 如何采用不加锁的方式实现线程同步
- 如何采用不加锁的方式实现线程同步
- TSM 修改control path
- IEtester从重要变鸡肋
- sscanf(), sscanf_s()
- BST、B树、B-树、B+树、B*树
- oracle备份还原
- 第二次作业:个人项目实践