您的位置:首页 > 其它

创建文件&复制文件&删除文件

2017-06-21 22:49 330 查看
#include
#include
#include
#include
#include
#include

char buf[60];
int count;

void main(int argc, char *argv[])
{
    int a = argc;
    int fd, fd1, fd2;
    int flag;
    char ch;
    
    printf("%s\n",
argv[1]);
    
   
    if(strcmp(argv[1],
"myvim") == 0)
    {
    fd = open(argv[2],
O_RDWR|O_CREAT|O_APPEND, S_IRWXU);
    close(fd);
    }
    
   
    if(strcmp(argv[1],
"mycp") == 0)
    {
    count = 0;
    fd1 = open(argv[2],
O_RDWR|O_APPEND, S_IRWXU);
   
    if(fd1 < 0)
    {
     
 printf("there is no that file!\n");
     
 return;
    }
   
    fd2 = open(argv[3],
O_RDWR|O_CREAT|O_APPEND, S_IRWXU);
   
    while( (count =
read(fd1, buf, 50)) && (count == 50) )
    {
     
 write(fd2, buf, 50);
    }
   
    if(count < 50)
    {
     
 write(fd2, buf, count);
    }
   
    close(fd);
    }

   
    if(strcmp(argv[1],
"myrm") == 0)
    {
    printf("are you sure
want to delete the file?\n");
    scanf("%c",
&ch);
    if(ch == 'y')
    flag =
unlink(argv[2]);
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: