操作系统实验之文件拷贝

实验要求

使用系统调用(open, read, write,close等函数)编写文件拷贝程序.

实验环境

LinuxMax OS X

实验代码

#include 
#include 
#include 
#include 
#include 
#include 

int main(int argc, char** argv){
    if(argc != 3){
        fprintf(stderr, "You must need a source file and destination file\n");
        exit(0);
    }
    int so = open(argv[1], O_RDONLY|O_CREAT, 0644);
    int de = open(argv[2], O_WRONLY|O_CREAT, 0644);
    char c;
    while(read(so, &c, 1)){
        write(de, &c, 1);
    }
    close(so);
    close(de);
    printf("copy over\n");
    return 0;
}

你可能感兴趣的:(操作系统)