开发者

unix open file for write given file descriptor

开发者 https://www.devze.com 2023-04-08 02:45 出处:网络
I want to open a file for write and I have been given the file descriptor for that file. I know开发者_运维知识库 that fdopen can be used to write to the file as follows:

I want to open a file for write and I have been given the file descriptor for that file.

I know开发者_运维知识库 that fdopen can be used to write to the file as follows:

FILE * fp;
fp = fdopen(filedes, "a+");
fwrite("\n", sizeof(char), 1, fp);

Is there any other way to achive the same, i.e., write to a file given a file descriptor?

Thanks


Is there any other way to achive the same, i.e., write to a file given a file descriptor

You can write directly using the system call write(2).

write(fd, "\n", 1);


You can write a buffer of data to a file descriptor with the write system call.

0

精彩评论

暂无评论...
验证码 换一张
取 消