Under Linux I use this code to redirect stdout and stderr on a file, as shown in the code the file is opened using fopen(f) and is it closed using close(fd). My question is whether the close(fd) statement closes all file descriptors, or is it necessary to use fclose(f) as well ? Answer The rule is to close the outermost
Tag: fclose
Proper error handling for fclose impossible (according to manpage)?
So I’m studying fclose manpage for quite I while and my conclusion is that if fclose is interrupted by some signal, according to the manpage there is no way to recover…? Am I missing some point? Usually, with unbuffered POSIX functions (open, close, write, etc…) there is ALWAYS a way to recover from signal interruption (EINTR) by restarting the call;
Why glibc’s fclose(NULL) cause segmentation fault instead of returning error?
According to man page fclose(3): RETURN VALUE Upon successful completion 0 is returned. Otherwise, EOF is returned and the global variable errno is set to indicate the error. In either case any further access (including another call to fclose()) to the stream results in undefined behavior. ERRORS EBADF The file descriptor underlying fp is not valid. The fclose() function may