FreeBASIC  0.91.0
dev_file_size.c
Go to the documentation of this file.
1 /* file device size calc */
2 
3 #include "fb.h"
4 
5 int fb_hDevFileSeekStart( FILE *fp, int mode, FB_FILE_ENCOD encod, int seek_zero )
6 {
7  /* skip the BOM if in UTF-mode */
8  size_t ofs;
9 
10  switch( encod )
11  {
12  case FB_FILE_ENCOD_UTF8:
13  ofs = 3;
14  break;
15 
17  ofs = sizeof( UTF_16 );
18  break;
19 
21  ofs = sizeof( UTF_32 );
22  break;
23 
24  default:
25  if( seek_zero == FALSE )
26  return 0;
27 
28  ofs = 0;
29  }
30 
31  return fseeko( fp, ofs, SEEK_SET );
32 }
33 
34 fb_off_t fb_DevFileGetSize( FILE *fp, int mode, FB_FILE_ENCOD encod, int seek_back )
35 {
36  fb_off_t size = 0;
37 
38  switch( mode )
39  {
42  case FB_FILE_MODE_INPUT:
43 
44  if( fseeko( fp, 0, SEEK_END ) != 0 )
45  return -1;
46 
47  size = ftello( fp );
48 
49  if( seek_back )
50  fb_hDevFileSeekStart( fp, mode, encod, TRUE );
51 
52  break;
53 
55  size = ftello( fp );
56  }
57 
58  return size;
59 }