APUE says
With fdopen, the meanings of the type argument differ slightly.
The descriptor has already been opened, so opening for writing does not truncate the file. (If the descriptor was created by the open function, for example, and the file already existed, the O_TRUNC flag would control whether the file was truncated. The fdopen function cannot simply truncate any file it opens for writing.)
Also, the standard I/O append mode cannot create the file (since the file has to exist if a descriptor refers to it).
In general, when we call fdopen()
on a file descriptor returned from open()
,
what kinds of types can we specify in fdopen()
?
Must the type specified in fdopen()
be exactly the same as the mode specified in open()
?
Can the type specified in fdopen()
be a subset, superset, or neither subset nor superset of the mode specified in open()
?
If there is no restriction on the types specified in fdopen()
with respect to the mode specified in the previous open()
, which part of the type specified in fdopen()
is valid, and which part isn't (i.e. is ignored)?
Thanks.