FreeBASIC  0.91.0
file_close.c
Go to the documentation of this file.
1 /* CLOSE function */
2 
3 #include "fb.h"
4 
5 /*:::::*/
7 {
8  FB_LOCK();
9 
10  if( !FB_HANDLE_USED(handle) ) {
11  FB_UNLOCK();
13  }
14 
15  /* close VFS handle */
16  DBG_ASSERT(handle->hooks->pfnClose != NULL);
17  int result = handle->hooks->pfnClose( handle );
18  if (result != 0) {
19  FB_UNLOCK();
20  return result;
21  }
22 
23  /* clear structure */
24  memset(handle, 0, sizeof(FB_FILE));
25 
26  FB_UNLOCK();
27 
28  return fb_ErrorSetNum( FB_RTERROR_OK );
29 }
30 
31 /*:::::*/
32 FBCALL int fb_FileClose( int fnum )
33 {
34  /* make CLOSE #0 return an error
35  (QBASIC quirk: return no error; old FB quirk: close all files */
36  if( fnum == 0 ) {
37  /*fb_FileReset( );*/
39  }
40  return fb_FileCloseEx( FB_FILE_TO_HANDLE(fnum) );
41 }
42 
43 /*:::::*/
45 {
46  /* As in QB: CLOSE w/o arguments closes all files */
47  fb_FileReset( );
48  return fb_ErrorSetNum( FB_RTERROR_OK );
49 }
50