Is there any way to change an int
file descriptor to a FILE
struct pointer or/and change FILE*
to a file descriptor in C?
Asked
Active
Viewed 1.8k times
2 Answers
39
The function fdopen()
returns a new (FILE *) associated with an open file descriptor.
The function fileno()
returns the file descriptor associated with an open FILE *.

Kamal
- 7,160
- 2
- 21
- 12
-
3Caveat: `fdopen` takes ownership, whereas `fileno` returns a view. It is very difficult to avoid some of the edge cases even if you use `dup` in conjunction, since `fclose` modifies the underlying file descriptor. – o11c Jun 09 '18 at 16:09