unix open file for write given file descriptor
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.
精彩评论