59 #include <grass/shapefil.h> 68 SHP_CVSID(
"$Id: safileio.c,v 1.4 2008-01-16 20:05:14 bram Exp $")
70 #ifdef SHPAPI_UTF8_HOOKS 71 # ifdef SHPAPI_WINDOWS 72 # define WIN32_LEAN_AND_MEAN 75 # pragma comment(lib, "kernel32.lib") 86 return (
SAFile) fopen( pszFilename, pszAccess );
96 return (
SAOffset) fread( p, (
size_t) size, (
size_t) nmemb,
107 return (
SAOffset) fwrite( p, (
size_t) size, (
size_t) nmemb,
118 return (
SAOffset) fseek( (FILE *) file, (
long) offset, whence );
128 return (
SAOffset) ftell( (FILE *) file );
138 return fflush( (FILE *) file );
148 return fclose( (FILE *) file );
158 return remove( filename );
168 fprintf( stderr,
"%s\n", message );
188 psHooks->
Atof = atof;
194 #ifdef SHPAPI_WINDOWS 200 const wchar_t* Utf8ToWideChar(
const char *pszFilename )
203 wchar_t *pwszFileName;
205 nMulti = strlen(pszFilename) + 1;
206 nWide = MultiByteToWideChar( CP_UTF8, 0, pszFilename, nMulti, 0, 0);
211 pwszFileName = (
wchar_t*)
malloc(nWide *
sizeof(
wchar_t));
212 if ( pwszFileName ==
NULL )
216 if( MultiByteToWideChar( CP_UTF8, 0, pszFilename, nMulti, pwszFileName, nWide ) == 0 )
218 free( pwszFileName );
228 SAFile SAUtf8WFOpen(
const char *pszFilename,
const char *pszAccess )
231 const wchar_t *pwszFileName, *pwszAccess;
232 pwszFileName = Utf8ToWideChar( pszFilename );
233 pwszAccess = Utf8ToWideChar( pszAccess );
234 if( pwszFileName !=
NULL && pwszFileName !=
NULL)
236 file = (
SAFile) _wfopen( pwszFileName, pwszAccess );
238 free ((
wchar_t*) pwszFileName);
239 free ((
wchar_t*) pwszAccess);
247 int SAUtf8WRemove(
const char *pszFilename )
249 const wchar_t *pwszFileName = Utf8ToWideChar( pszFilename );
251 if( pwszFileName !=
NULL )
253 rc = _wremove( pwszFileName );
255 free ((
wchar_t*) pwszFileName);
261 #ifdef SHPAPI_UTF8_HOOKS 267 void SASetupUtf8Hooks(
SAHooks *psHooks )
269 #ifdef SHPAPI_WINDOWS 270 psHooks->
FOpen = SAUtf8WFOpen;
271 psHooks->
Remove = SAUtf8WRemove;
273 # error "no implementations of UTF-8 hooks available for this platform" 283 psHooks->
Atof = atof;
int(* Remove)(const char *filename)
SAOffset(* FTell)(SAFile file)
SAFile SADFOpen(const char *pszFilename, const char *pszAccess)
SAOffset SADFWrite(void *p, SAOffset size, SAOffset nmemb, SAFile file)
int(* FFlush)(SAFile file)
SAOffset(* FSeek)(SAFile file, SAOffset offset, int whence)
void SADError(const char *message)
int SADFClose(SAFile file)
void SASetupDefaultHooks(SAHooks *psHooks)
SAOffset SADFSeek(SAFile file, SAOffset offset, int whence)
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
SAFile(* FOpen)(const char *filename, const char *access)
int SADRemove(const char *filename)
void(* Error)(const char *message)
#define SHP_CVSID(string)
double(* Atof)(const char *str)
int SADFFlush(SAFile file)
SAOffset SADFRead(void *p, SAOffset size, SAOffset nmemb, SAFile file)
SAOffset(* FRead)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
SAOffset SADFTell(SAFile file)
int(* FClose)(SAFile file)