FreeBASIC  0.91.0
file_size.c
Go to the documentation of this file.
1 /* file size */
2 
3 #include "fb.h"
4 
5 /*:::::*/
7 {
8  fb_off_t res = 0;
9 
10  if( !FB_HANDLE_USED(handle) )
11  return res;
12 
13  FB_LOCK();
14 
15  if (handle->hooks->pfnSeek!=NULL && handle->hooks->pfnTell!=NULL) {
16  fb_off_t old_pos;
17  /* remember old position */
18  int result = handle->hooks->pfnTell(handle, &old_pos);
19  if (result==0) {
20  /* move to end of file */
21  result = handle->hooks->pfnSeek(handle, 0, SEEK_END);
22  }
23  if (result==0) {
24  /* get size */
25  result = handle->hooks->pfnTell(handle, &res);
26  /* restore old position*/
27  handle->hooks->pfnSeek(handle, old_pos, SEEK_SET);
28  }
29  }
30 
31  FB_UNLOCK();
32 
33  return res;
34 }
35 
36 /*:::::*/
37 FBCALL long long fb_FileSize( int fnum )
38 {
39  return fb_FileSizeEx(FB_FILE_TO_HANDLE(fnum));
40 }