Подтвердить что ты не робот

Как получить поток FILE * из дескриптора файла?

Мы можем получить файловый дескриптор из потока FILE *, используя функцию fileno. Есть ли функция для получения потока FILE * из дескриптора файла без повторного открытия файла?

4b9b3361

Ответ 1

   FILE *fdopen(int fd, const char *mode);

См. fdopen(3), но он должен быть на той же странице, что и fopen(3)

   The fdopen() function  associates  a  stream  with  the  existing  file
   descriptor,  fd.   The mode of the stream (one of the values "r", "r+",
   "w", "w+", "a", "a+") must be compatible with  the  mode  of  the  file
   descriptor.   The  file  position indicator of the new stream is set to
   that belonging to fd, and the  error  and  end-of-file  indicators  are
   cleared.   Modes  "w" or "w+" do not cause truncation of the file.  The
   file descriptor is not dup’ed, and will be closed when the stream  cre‐
   ated  by  fdopen()  is  closed.   The  result of applying fdopen() to a
   shared memory object is undefined.