1 #include "filedatasource.h"
2 #include "cpl_error.h"
3 
FileDataSource(const char * fileName)4 FileDataSource::FileDataSource(const char * fileName)
5   : closeFile(true)
6 {
7     fp = VSIFOpenL(fileName, "rb");
8 }
9 
FileDataSource(VSILFILE * fp)10 FileDataSource::FileDataSource(VSILFILE* fp)
11 : closeFile(false)
12 {
13     this->fp = fp;
14 }
15 
~FileDataSource()16 FileDataSource::~FileDataSource()
17 {
18     if (closeFile)
19         VSIFCloseL(fp);
20 }
21 
DataSourceFread(void * lpBuf,size_t size,size_t count)22 size_t FileDataSource::DataSourceFread(void* lpBuf, size_t size, size_t count)
23 {
24     return VSIFReadL(lpBuf, size, count, (VSILFILE*)fp);
25 }
26 
DataSourceFgetc()27 int FileDataSource::DataSourceFgetc()
28 {
29     unsigned char byData;
30 
31     if( VSIFReadL( &byData, 1, 1, fp ) == 1 )
32         return byData;
33     else
34         return EOF;
35 }
36 
DataSourceUngetc(int c)37 int FileDataSource::DataSourceUngetc(int c)
38 {
39     DataSourceFseek(-1, SEEK_CUR );
40 
41     return c;
42 }
43 
DataSourceFseek(long offset,int origin)44 int FileDataSource::DataSourceFseek(long offset, int origin)
45 {
46     if (origin == SEEK_CUR && offset < 0)
47         return VSIFSeekL(fp, VSIFTellL(fp) + offset, SEEK_SET);
48     else
49         return VSIFSeekL(fp, offset, origin);
50 }
51 
DataSourceFeof()52 int FileDataSource::DataSourceFeof()
53 {
54     return VSIFEofL( fp );
55 }
56 
DataSourceFtell()57 long FileDataSource::DataSourceFtell()
58 {
59     return VSIFTellL( fp );
60 }
61