book@100ask:~/linux/sys/20201201$ ls
open.c
book@100ask:~/linux/sys/20201201$ sudo gcc -o open open.c
book@100ask:~/linux/sys/20201201$ ./open
File open error
book@100ask:~/linux/sys/20201201$ ls
open open.c
book@100ask:~/linux/sys/20201201$ sudo ./open
File length = 692
List file content
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int srcid,dstid;
unsigned char buf[1024];
int readlen;
memset(buf,0x00,1024);
srcid = open("/home/book/linux/sys/20201201/open.c",O_RDONLY);
if(srcid<0)
{
printf("File open error \n");
return 0;
}
dstid = open("/home/book/linux/sys/20201201/open.c.bak",O_WRONLY|O_CREAT);
if(dstid<0)
{
printf("File open error \n");
return 0;
}
readlen = read(srcid,buf,1024);
printf("File length = %d\n
Linux系统编程 - 24. 文件IO之 Open/Write
最新推荐文章于 2024-08-20 19:05:22 发布
本文深入探讨Linux系统编程中关于文件IO的Open和Write函数使用,特别是强调了每次最大写入尺寸限制为1024字节这一关键点。
摘要由CSDN通过智能技术生成