Linux文件复制
来源:互联网 发布:win7无法识别网络 编辑:程序博客网 时间:2024/05/16 01:04
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define BUFFER_SIZE 1024
int main(int argc,char *argv[])
{
int from_fd;
int to_fd;
int bytes_read;
int bytes_write;
char buffer[BUFFER_SIZE];
char *ptr;
if(argc != 3)
{
printf("error");
exit(1);
}
if((from_fd = open(argv[1],O_RDONLY)) == -1)
{
printf("from file open failure\n");
exit(1);
}
if((to_fd = open(argv[2],O_WRONLY | O_CREAT,S_IRUSR | S_IWUSR)) == -1)
{
printf("to_file open failure\n");
exit(1);
}
while(bytes_read = read(from_fd,buffer,BUFFER_SIZE))
{
if( (bytes_read == -1))break;
else if(bytes_read > 0)
{
ptr = buffer;
while(bytes_write = write(to_fd,ptr,bytes_read))
{
if(bytes_write == -1)break;
else if(bytes_write == bytes_read) break;
else if(bytes_write > 0)
{
ptr += bytes_write;
bytes_read -= bytes_write;
}
}
if(bytes_write == -1)break;
}
}
close(from_fd);
close(to_fd);
exit(0);
}
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define BUFFER_SIZE 1024
int main(int argc,char *argv[])
{
int from_fd;
int to_fd;
int bytes_read;
int bytes_write;
char buffer[BUFFER_SIZE];
char *ptr;
if(argc != 3)
{
printf("error");
exit(1);
}
if((from_fd = open(argv[1],O_RDONLY)) == -1)
{
printf("from file open failure\n");
exit(1);
}
if((to_fd = open(argv[2],O_WRONLY | O_CREAT,S_IRUSR | S_IWUSR)) == -1)
{
printf("to_file open failure\n");
exit(1);
}
while(bytes_read = read(from_fd,buffer,BUFFER_SIZE))
{
if( (bytes_read == -1))break;
else if(bytes_read > 0)
{
ptr = buffer;
while(bytes_write = write(to_fd,ptr,bytes_read))
{
if(bytes_write == -1)break;
else if(bytes_write == bytes_read) break;
else if(bytes_write > 0)
{
ptr += bytes_write;
bytes_read -= bytes_write;
}
}
if(bytes_write == -1)break;
}
}
close(from_fd);
close(to_fd);
exit(0);
}
0 0
- Linux隐藏文件复制
- linux 局域网 复制文件
- linux 文件复制
- Linux文件复制
- Linux文件的复制
- Linux cp --复制文件
- Linux 多线程文件复制
- Linux文件的复制
- Linux文件复制
- Linux 复制文件
- linux文件复制命令
- Linux cp 复制文件或复制文件夹
- LINUX CP 复制文件 命令
- linux大量文件的复制
- linux 文件内容的复制
- linux主机间复制文件
- Linux文件剪切复制粘贴
- Linux文件和文件夹复制
- sql的图片批量上传
- 重庆集训1 BY 巴蜀
- centos web服务器 流量监控+防火墙规则
- cuteftp实现windows和linux之间互传文件配置说明
- Linux / Mac 下 基本的 bash shell 命令详解(touch 、cp、mv、rm)
- Linux文件复制
- 练习题目-LPL
- 欢迎使用CSDN-markdown编辑器
- 【Android】Android中设置Toast字体颜色及弹出的位置
- Windows下搭建IOS开发环境
- 二叉树的性质
- hit or miss 解题报告
- Android Dialog样式的Activity的实现
- 在ssm中发布Apache CXF WebService