Linux系统编程 - 24. 文件IO之 Open/Write

本文深入探讨Linux系统编程中关于文件IO的Open和Write函数使用,特别是强调了每次最大写入尺寸限制为1024字节这一关键点。
摘要由CSDN通过智能技术生成
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值