Search code examples
cfile-ioprintfposix-api

"fprintf"-like function for file descriptors (i.e. int fd instead of FILE* fp)


Maybe I'm just missing it, but isn't there a function equivalent to fprintf for file descriptors, or even a way to temporarily flip-flop between them?


Solution

  • You could look into dprintf (GNU extensions, not in C or POSIX) :

    The functions dprintf() and vdprintf() (as found in the glibc2 library) are exact analogues of fprintf() and vfprintf(), except that they output to a file descriptor fd instead of to a given stream.

    EDIT As pointed by several of you in the comments, POSIX 2008 standardized these functions.