下面的程序为什么会出现:Error3: : Bad file descriptor
ff.txt文件已经存在
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define BUFFERSIZE 8192
int main(void)
{
int handle_from, handle_to, len;
char buf[BUFFERSIZE];
if ((handle_from = open("d:\\today\\ff.txt", O_RDONLY)) == -1)
{
perror("Error1: ");
exit(1);
}
if ((handle_to = open("d:\\today\\gg.txt", O_CREAT, O_WRONLY, O_TRUNC)) == -1)
{
perror("Error2: ");
exit(1);
}
while ((len = read(handle_from, buf, BUFFERSIZE)) > 0)
{
if (write(handle_to, buf, len) != len)
{
perror("Error3: ");
exit(1);
}
}
close(handle_from);
close(handle_to);
exit(0);
}