FILE* f = NULL;
fclose(f);

Terminates with: 'No source available for "fclose@@GLIBC_2.1() " '

FILE* f = NULL;
ftell(f);

Terminates with: 'No source available for "ftell()"'

Why those functions does not return error value but terminate whole program? How can I safely tell if file is opened in C and close it???

If variable of type 'FILE*' is passed to my function I need to know the state of the file and be able to close.
Any idea?

what did you expect it to do?

you're trying to do the close and tell function on a NULL pointer.

now think about that for a minute, and you should have your answer.

.

> Terminates with: 'No source available for "fclose@@GLIBC_2.1() " '
You get these in debug builds because the code for fclose uses assert() to validate the input parameters.

If you were in a debugger at the time, you'd know exactly where to start looking.

In this case, fclose() is likely to begin with assert( fp != NULL ); Release builds have no assert() statements, so it would just return whatever the spec says fclose() should return if passed NULL.

Release builds have no assert() statements, so it would just return whatever the spec says fclose() should return if passed NULL.

Actually, it terminates in release build. It should return error value, though. It might be some internal inconsistency of the implementation of C lib I am using (glibc2.1).

> Actually, it terminates in release build.
Is that because it detected NULL and cleanly exited, or dereferenced NULL and bombed?

Is that because it detected NULL and cleanly exited, or dereferenced NULL and bombed?

It seems to cleanly exit with the value -1. It does not return value to indicate error, it exits the whole application with value -1.

This article has been dead for over six months. Start a new discussion instead.