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 );
192 #ifdef SHPAPI_WINDOWS
198 const wchar_t* Utf8ToWideChar(
const char *pszFilename )
201 wchar_t *pwszFileName;
203 nMulti = strlen(pszFilename) + 1;
204 nWide = MultiByteToWideChar( CP_UTF8, 0, pszFilename, nMulti, 0, 0);
209 pwszFileName = (
wchar_t*)
malloc(nWide *
sizeof(
wchar_t));
210 if ( pwszFileName ==
NULL )
214 if( MultiByteToWideChar( CP_UTF8, 0, pszFilename, nMulti, pwszFileName, nWide ) == 0 )
216 free( pwszFileName );
226 SAFile SAUtf8WFOpen(
const char *pszFilename,
const char *pszAccess )
229 const wchar_t *pwszFileName, *pwszAccess;
230 pwszFileName = Utf8ToWideChar( pszFilename );
231 pwszAccess = Utf8ToWideChar( pszAccess );
232 if( pwszFileName !=
NULL && pwszFileName !=
NULL)
234 file = (
SAFile) _wfopen( pwszFileName, pwszAccess );
236 free ((
wchar_t*) pwszFileName);
237 free ((
wchar_t*) pwszAccess);
245 int SAUtf8WRemove(
const char *pszFilename )
247 const wchar_t *pwszFileName = Utf8ToWideChar( pszFilename );
249 if( pwszFileName !=
NULL )
251 rc = _wremove( pwszFileName );
253 free ((
wchar_t*) pwszFileName);
259 #ifdef SHPAPI_UTF8_HOOKS
265 void SASetupUtf8Hooks(
SAHooks *psHooks )
267 #ifdef SHPAPI_WINDOWS
268 psHooks->
FOpen = SAUtf8WFOpen;
269 psHooks->Remove = SAUtf8WRemove;
271 # error "no implementations of UTF-8 hooks available for this platform"
281 psHooks->Atof = atof;
SAOffset(* FTell)(SAFile file)
SAFile SADFOpen(const char *pszFilename, const char *pszAccess)
SAFile(* FOpen)(const char *filename, const char *path)
SAOffset SADFWrite(void *p, SAOffset size, SAOffset nmemb, SAFile file)
int(* FClose)(SAFile file)
SAOffset(* FRead)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
void SADError(const char *message)
int(* FFlush)(SAFile file)
int SADFClose(SAFile file)
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
SHP_CVSID("$Id: safileio.c,v 1.4 2008/01/16 20:05:14 bram Exp $")
void SASetupDefaultHooks(SAHooks *psHooks)
SAOffset SADFSeek(SAFile file, SAOffset offset, int whence)
SAOffset(* FSeek)(SAFile file, SAOffset offset, int whence)
int SADRemove(const char *filename)
void(* Error)(const char *message)
int SADFFlush(SAFile file)
SAOffset SADFRead(void *p, SAOffset size, SAOffset nmemb, SAFile file)
SAOffset SADFTell(SAFile file)