C - Proper way to close files when using both open() and fdopen()
The standard says:
The fclose() function shall perform the equivalent of a
close()
on the file descriptor that is associated with the stream pointed to by stream.
So calling fclose
is enough; it will also close the descriptor.
FILE
is a buffering object from standard C library. When you do fclose
(standard C function) it will eventually call close
(Unix system function) but only after making sure C library buffers are flushed. So, I would say, if you use fopen
andfwrite
then you should use fclose
, and not just close
, otherwise you risk loosing some data.