小白笔记--------------linux下的cp命令
2016-03-25 16:35
483 查看
#include<stdio.h> #include<unistd.h> #include<fcntl.h> #include<stdlib.h> #define COPYMODE 0644 #define BUFFSIZE 4096 main(int ac, char ** av){ int in_fd,out_fd; char n_chars; char buff[BUFFSIZE]; if((in_fd = open(av[1],O_RDONLY)) == -1){ oops("cannot open",av[1]); } if((out_fd = creat(av[2],COPYMODE))== -1){ oops("cannot creat",av[2]); } while((n_chars = read(in_fd,buff,BUFFSIZE))> 0){ if(write(out_fd,buff,n_chars) != n_chars){ oops("wirte error to ",av[2]); } } if(n_chars == -1){ oops("read error from",av[1]); } if(close(in_fd) == -1 || close(out_fd) == -1){ oops("error closing files",""); } } oops(char *s1,char *s2){ fprintf(stderr,"error is : %s",s1); perror(s2); exit(1); }
相关文章推荐
- linux的ip地址排序
- Linux系统iNode耗尽硬盘无法写入文件怎么办?
- linux高端内存映射
- 史上最全面最精华的Linux内存相关资料
- Linux的僵尸进程处理2
- Linux文件权限
- 理解linux 的 inode 解决inode耗尽问题
- 官网 Centos 6.5 Setting up Icinga 2 -- Setting up Icinga Web 2
- linux学习总结?
- CentOS6.6安装CloudStack4.8
- centos关闭selinux
- Linux安全学习总结
- [JIRA] 最新Linux安装版本jira6.3.6安装破解以及数据导入的详细步骤
- Centos7安装共享Samba win访问linux
- linux下使用select实现精确定时器
- linuxcnc编译
- 【lLinux驱动】linux内核源码目录结构
- 在linux中添加ftp用户,并设置相应的权限
- Linux makefile 教程
- Centos 6.5 升级系统到 Centos 7.0