cposixmkstemp

How to get a FILE pointer from a file descriptor?


I'm playing around with mkstemp(), which provides a file descriptor, but I want to generate formatted output via fprintf(). Is there an easy way to transform the file descriptor provided by mkstemp() into a FILE * structure that is suitable for use with fprintf()?


Solution

  • Use fdopen():

    FILE* fp = fdopen(fd, "w");