(note: This question is for some schoolwork I'm doing. I don't need to know how to implement this, just need to know if it's possible and how can I learn more about it)
I'd like to use a user level buffer for a file using only a file descriptor and not using a FILE*. I know stdio.h
has, at least, 1 fifo user level buffer for all *printf()
and *scanf()
functions.
My question:
I was asked to do a system that uses the write()
linux function. That function is a system call. The objective here is to complete a small extra challenge I was given by the professor which is:
Use or make a user level buffer for the writting of those files.
Because I use the function write and I use file descriptors I cannot use any of the fprintf()
functions because it is documented that mixing system calls (write and *fprintf) has an undefined result.
Is there an alternative way to use the same buffer as stdio or is there an equivalent buffer "offered" by linux's libraries to write to that file? (Note: I also need to know how to flush that buffer)
I don't have special problems making a fifo buffer, but If I can save some work, that'll be useful.
Note: My code is for linux. If there is portable code possible for this, please tell me about the portable code. If there isn't any portable code, then please give me linux's way.