文件复制系统调用版
来源:互联网 发布:淘宝动漫店 编辑:程序博客网 时间:2024/04/30 07:38
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
int main()
{
char buffer[512] = "Hello Linux\n";
char buf_read[512] = {0};
int fd_read;
int fd_write;
ssize_t nbytes;
char run_data[10] = {0};
int i;
fd_write = open("/home/aa", O_WRONLY);
if (-1 == fd_write)
{
perror("open");
return -1;
}
fd_read = open("/home/bb", O_RDONLY);
if (-1 == fd_read)
{
perror("open");
return -1;
}
printf("Open FIFO success...\n");
while (1)
{
nbytes = write(fd_write, buffer, strlen(buffer));
if (-1 == nbytes)
{
perror("write");
return -1;
}
printf("write %d bytes\n", nbytes);
memset (buffer, 0, sizeof(buffer));
memset(buf_read, 0, sizeof(buf_read));
nbytes = read(fd_read, buf_read, sizeof(buf_read));
if (-1 == nbytes)
{
perror("read");
return -1;
}
printf("Read %d bytes, the content is %s\n", nbytes, buf_read);
fgets(buffer, 10, stdin);
if (strncmp("over", run_data, 4) == 0)
{
break;
}
}
return 0;
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
int main()
{
char buffer[512] = "Hello Linux\n";
char buf_read[512] = {0};
int fd_read;
int fd_write;
ssize_t nbytes;
char run_data[10] = {0};
int i;
fd_write = open("/home/aa", O_WRONLY);
if (-1 == fd_write)
{
perror("open");
return -1;
}
fd_read = open("/home/bb", O_RDONLY);
if (-1 == fd_read)
{
perror("open");
return -1;
}
printf("Open FIFO success...\n");
while (1)
{
nbytes = write(fd_write, buffer, strlen(buffer));
if (-1 == nbytes)
{
perror("write");
return -1;
}
printf("write %d bytes\n", nbytes);
memset (buffer, 0, sizeof(buffer));
memset(buf_read, 0, sizeof(buf_read));
nbytes = read(fd_read, buf_read, sizeof(buf_read));
if (-1 == nbytes)
{
perror("read");
return -1;
}
printf("Read %d bytes, the content is %s\n", nbytes, buf_read);
fgets(buffer, 10, stdin);
if (strncmp("over", run_data, 4) == 0)
{
break;
}
}
return 0;
}
阅读全文
0 0
- 文件复制系统调用版
- 调用系统对话框复制文件
- C++系统调用复制文件
- 利用read/write系统调用复制文件
- Linux系统调用实现文件复制
- Linux系统调用实现文件复制
- Linux文件系统编程 系统调用 文件复制
- C#调用系统的复制、移动、删除文件对话框
- C#调用系统的复制、移动、删除文件对话框
- 2010-07-21 使用系统调用实现文件复制
- C#调用系统的复制、移动、删除文件对话框
- 龙芯汇编语言-利用系统调用复制文件
- Winform调用系统的剪切,复制,粘贴文件功能
- C#调用系统的复制、移动、删除文件对话框
- 系统调用 7--综合实例1(文件复制)
- linux应用编程笔记(5)系统调用文件编程方法实现文件复制
- 系统调用,将一个文件复=中的内容复制到另一个文件中去
- linux下用c库和系统调用实现文件的复制
- JS的条件与循环语句简介
- jQuery选择器(全)
- Shell脚本查看占用cpu过高的线程信息
- 计算器
- 问题 N: 字母排列
- 文件复制系统调用版
- HTTP协议
- 第三方yum仓库搭建
- 数据结构——链表
- NYOJ 70: 阶乘因式分解(二)
- GUI数字游戏
- 使用webpack.DllPlugin与webpack.DllReferencePlugin解决webpack打包慢问题
- TCP服务器、客户端的简单实现
- AOP切点的合并