linux c编程疑问之一-----关于open,read
先贴代码:
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#define PERMS 06666
#define DUMMY 0
#define BUFSIZE 1024
int main()
{
char **argv;
char *test = "test.txt";
char *bytest = "testcopy.txt";
int source_fd, target_fd, num;
char iobuffer[BUFSIZE];
argv[1] = test;
argv[2] = bytest;
/*
if(argc != 3)
{
printf("Usage: copy Sourcefile Targetfile\n");
return 1;
}
*/
if(source_fd = open(*(argv+1), O_RDONLY, DUMMY) == -1)
{
printf("Source file open error!\n");
return 2;
}
if((target_fd = open(*(argv + 2), O_WRONLY|O_CREAT, PERMS)) == -1)
{
printf("Target file open error!\n");
return 3;
}
while((num = read(source_fd, iobuffer, BUFSIZE)) > 0)
if(write(target_fd, iobuffer, num) != num)
{
printf("Target file write error!\n");
return 4;
}
close(source_fd);
close(target_fd);
return 0;
}
程序的目的是将test.txt 中的内容复制到testcopy.txt,gcc -g -o copy copy.c(程序名是copy.c)后,gdb copy,单步运行到while((num = read(source_fd, iobuffer, BUFSIZE)) > 0)一句时程序卡住不动,为什么呢,静待高手指点.....