I would like to have a FILE*
type to use fprintf
.
I need to use fdopen
to get a FILE*
instead of open
that returns an int
.
But can we do the same with fdopen
and open
? (I never used fdopen
)
I would like to do a fdopen
that does the same as :
open("my_file", 0_CREAT | O_RDWR | O_TRUNC, 0644);
fdopen
takes a file descriptor that could be previously returned byopen
, so that is not a problem.Just
open
your file getting the descriptor, and thenfdopen
that descriptor.fdopen
simply creates a userspace-buffered stream, taking any kind of descriptor that supports theread
andwrite
operations.