User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 330,029 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,723 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 135 | Replies: 7
Reply
Join Date: Oct 2006
Posts: 78
Reputation: edek is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
edek's Avatar
edek edek is offline Offline
Junior Poster in Training

ftell() fclose() and FILE* f = NULL

  #1  
4 Days Ago
  1. FILE* f = NULL;
  2. fclose(f);
Terminates with: 'No source available for "fclose@@GLIBC_2.1() " '

  1. FILE* f = NULL;
  2. 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?
Last edited by edek : 4 Days Ago at 8:58 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Location: Seattle
Posts: 379
Reputation: jephthah is on a distinguished road 
Rep Power: 1
Solved Threads: 26
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Whiz

Re: ftell() fclose() and FILE* f = NULL

  #2  
3 Days Ago
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.



.
Last edited by jephthah : 3 Days Ago at 12:52 pm.
Reply With Quote  
Join Date: Dec 2005
Posts: 2,627
Reputation: Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold 
Rep Power: 16
Solved Threads: 273
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: ftell() fclose() and FILE* f = NULL

  #3  
3 Days Ago
> 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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Reply With Quote  
Join Date: Feb 2008
Location: Seattle
Posts: 379
Reputation: jephthah is on a distinguished road 
Rep Power: 1
Solved Threads: 26
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Whiz

Re: ftell() fclose() and FILE* f = NULL

  #4  
3 Days Ago
well, i just learned something.
Reply With Quote  
Join Date: Oct 2006
Posts: 78
Reputation: edek is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
edek's Avatar
edek edek is offline Offline
Junior Poster in Training

Re: ftell() fclose() and FILE* f = NULL

  #5  
3 Days Ago
Originally Posted by Salem View Post
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).
Last edited by edek : 3 Days Ago at 8:29 am.
Reply With Quote  
Join Date: Dec 2005
Posts: 2,627
Reputation: Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold Salem is a splendid one to behold 
Rep Power: 16
Solved Threads: 273
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: ftell() fclose() and FILE* f = NULL

  #6  
3 Days Ago
> Actually, it terminates in release build.
Is that because it detected NULL and cleanly exited, or dereferenced NULL and bombed?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Reply With Quote  
Join Date: Oct 2006
Posts: 78
Reputation: edek is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
edek's Avatar
edek edek is offline Offline
Junior Poster in Training

Re: ftell() fclose() and FILE* f = NULL

  #7  
3 Days Ago
Originally Posted by Salem View Post
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.
Reply With Quote  
Join Date: Oct 2006
Posts: 78
Reputation: edek is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
edek's Avatar
edek edek is offline Offline
Junior Poster in Training

Re: ftell() fclose() and FILE* f = NULL

  #8  
2 Days Ago
I've found something like (http://www.stanford.edu/~thathoo/cur...io.h/code.html line 204):

  1. /*This function is a possible cancellation point and therefore not marked with __THROW. */
  2. extern int fclose (FILE *__stream);
What does 'function is a possible cancellation point' mean?? Does it mean that it can cancel whole application on error?
Last edited by edek : 2 Days Ago at 1:21 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 10:39 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC