#include
#include
#include
#include
#include
#include
#define BUFSIZE 100
int
main(void)
{
int fd, n;
char buf[BUFSIZE];
char t[] = "the text to write!";
if ((fd = open("test", O_RDWR)) == -1)
perror("cannot open\n");
while ( (n = read(fd, buf, BUFSIZE) ) > 0)
if ( write(STDOUT_FILENO, buf, n) != n)
perror("write error!\n");
if (lseek(fd, 20, SEEK_SET) == -1)
perror("cannot seek\n");
if (write( fd, t, sizeof(t) ) != sizeof(t) )
perror("write error!\n");
while ( (n = read(fd, buf, BUFSIZE) ) > 0)
if ( write(STDOUT_FILENO, buf, n) != n)
perror("write error!\n");
close(fd); //没这个会产生僵尸的。。。
exit(0);
}
阅读(1908) | 评论(0) | 转发(0) |