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?

Recommended Answers

All 7 Replies

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.

well, i just learned something.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.