- #include
- void main()
- {
- char *ptr;
- int c;
- while((c = getchar()) != EOF)
- putchar(c);
- }
# strace ./example1
- ...
- read(0, 123456
- "123456\n"..., 1024) = 7
- fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
- mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb80a9000
- write(1, "123456\n"..., 7123456
- ) = 7
- ...
example2.c
- #include
- void main()
- {
- char *ptr;
- int c;
- setbuf(stdout, NULL);
- while((c = getchar()) != EOF)
- putchar(c);
- }
#strace ./example2
- ...
- read(0, 123456
- "123456\n"..., 1024) = 7
- write(1, "1"..., 11) = 1
- write(1, "2"..., 12) = 1
- write(1, "3"..., 13) = 1
- write(1, "4"..., 14) = 1
- write(1, "5"..., 15) = 1
- write(1, "6"..., 16) = 1
- write(1, "\n"..., 1
- ) = 1
- ...
example3:
- #include
- void main()
- {
- char buf[1024];
- char *ptr;
- while((ptr = gets(buf)) != EOF)
- puts(buf);
- }
#strace ./example3
- ...
- read(0, 123456
- "123456\n"..., 1024) = 7
- fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
- mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb8027000
- write(1, "123456\n"..., 7123456
- ) = 7
- ...
example4:
- #include <stdio.h>
- void main()
- {
- char buf[1024];
- char *ptr;
- setbuf(stdout, NULL);
- while((ptr = gets(buf)) != EOF)
- puts(buf);
- }
- ...
- read(0, 123456
- "123456\n"..., 1024) = 7
- write(1, "123456"..., 6123456) = 6
- write(1, "\n"..., 1
- ) = 1
- ...