24 #ifdef SHPAPI_UTF8_HOOKS
26 #define WIN32_LEAN_AND_MEAN
29 #pragma comment(lib, "kernel32.lib")
33 static SAFile SADFOpen(
const char *pszFilename,
const char *pszAccess,
37 return (
SAFile)fopen(pszFilename, pszAccess);
42 return (
SAOffset)fread(p, (
size_t)size, (
size_t)nmemb, (FILE *)
file);
48 return (
SAOffset)fwrite(p, (
size_t)size, (
size_t)nmemb, (FILE *)
file);
53 #if defined(_MSC_VER) && _MSC_VER >= 1400
54 return (
SAOffset)_fseeki64((FILE *)
file, (__int64)offset, whence);
56 return (
SAOffset)fseek((FILE *)
file, (
long)offset, whence);
62 #if defined(_MSC_VER) && _MSC_VER >= 1400
71 return fflush((FILE *)
file);
76 return fclose((FILE *)
file);
79 static int SADRemove(
const char *filename,
void *pvUserData)
82 return remove(filename);
85 static void SADError(
const char *message)
87 fprintf(stderr,
"%s\n", message);
92 psHooks->
FOpen = SADFOpen;
93 psHooks->
FRead = SADFRead;
94 psHooks->
FWrite = SADFWrite;
95 psHooks->
FSeek = SADFSeek;
96 psHooks->
FTell = SADFTell;
97 psHooks->
FFlush = SADFFlush;
98 psHooks->
FClose = SADFClose;
99 psHooks->
Remove = SADRemove;
101 psHooks->
Error = SADError;
102 psHooks->
Atof = atof;
106 #ifdef SHPAPI_WINDOWS
108 static wchar_t *Utf8ToWideChar(
const char *pszFilename)
110 const int nMulti = (int)strlen(pszFilename) + 1;
112 MultiByteToWideChar(CP_UTF8, 0, pszFilename, nMulti, 0, 0);
116 wchar_t *pwszFileName = (
wchar_t *)
malloc(nWide *
sizeof(
wchar_t));
117 if (pwszFileName ==
NULL) {
120 if (MultiByteToWideChar(CP_UTF8, 0, pszFilename, nMulti, pwszFileName,
132 static SAFile SAUtf8WFOpen(
const char *pszFilename,
const char *pszAccess,
137 wchar_t *pwszFileName = Utf8ToWideChar(pszFilename);
138 wchar_t *pwszAccess = Utf8ToWideChar(pszAccess);
139 if (pwszFileName !=
NULL && pwszAccess !=
NULL) {
140 file = (
SAFile)_wfopen(pwszFileName, pwszAccess);
147 static int SAUtf8WRemove(
const char *pszFilename,
void *pvUserData)
150 wchar_t *pwszFileName = Utf8ToWideChar(pszFilename);
152 if (pwszFileName !=
NULL) {
153 rc = _wremove(pwszFileName);
161 #ifdef SHPAPI_UTF8_HOOKS
162 #ifndef SHPAPI_WINDOWS
163 #error "no implementations of UTF-8 hooks available for this platform"
166 void SASetupUtf8Hooks(
SAHooks *psHooks)
168 psHooks->
FOpen = SAUtf8WFOpen;
169 psHooks->
Remove = SAUtf8WRemove;
170 psHooks->
FRead = SADFRead;
171 psHooks->
FWrite = SADFWrite;
172 psHooks->
FSeek = SADFSeek;
173 psHooks->
FTell = SADFTell;
174 psHooks->
FFlush = SADFFlush;
175 psHooks->
FClose = SADFClose;
177 psHooks->
Error = SADError;
178 psHooks->
Atof = atof;
void SASetupDefaultHooks(SAHooks *psHooks)
void(* Error)(const char *message)
SAOffset(* FTell)(SAFile file)
int(* FFlush)(SAFile file)
SAFile(* FOpen)(const char *filename, const char *access, void *pvUserData)
double(* Atof)(const char *str)
SAOffset(* FWrite)(const void *p, SAOffset size, SAOffset nmemb, SAFile file)
int(* FClose)(SAFile file)
int(* Remove)(const char *filename, void *pvUserData)
SAOffset(* FRead)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
SAOffset(* FSeek)(SAFile file, SAOffset offset, int whence)