|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tfile_io.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <windows.h></windows.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <assert.h></assert.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
|
2fc36c |
static LPSTR AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars, UINT acp) {
|
|
Shinya Kitaoka |
120a6e |
assert(lpw != NULL);
|
|
Shinya Kitaoka |
120a6e |
assert(lpa != NULL);
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
verify that no illegal character present
|
|
Shinya Kitaoka |
120a6e |
since lpa was allocated based on the size of lpw
|
|
Shinya Kitaoka |
120a6e |
don t worry about the number of chars
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
lpa[0] = '\0';
|
|
Shinya Kitaoka |
120a6e |
WideCharToMultiByte(acp, 0, lpw, -1, lpa, nChars, NULL, NULL);
|
|
Shinya Kitaoka |
120a6e |
return lpa;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
char *convertWCHAR2CHAR(const wchar_t *fname) {
|
|
Shinya Kitaoka |
120a6e |
int size = 0;
|
|
Shinya Kitaoka |
120a6e |
LPCWSTR lpw = fname;
|
|
Shinya Kitaoka |
120a6e |
char *name = NULL;
|
|
Shinya Kitaoka |
120a6e |
char *outName = 0;
|
|
Shinya Kitaoka |
120a6e |
if (lpw) {
|
|
Shinya Kitaoka |
120a6e |
LPSTR pStr = 0;
|
|
Shinya Kitaoka |
120a6e |
size = (lstrlenW(lpw) + 1) * 2;
|
|
Shinya Kitaoka |
120a6e |
pStr = (LPSTR)malloc(size * sizeof(char));
|
|
Shinya Kitaoka |
120a6e |
name = AtlW2AHelper(pStr, lpw, size, 0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return name;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#include <stdlib.h></stdlib.h>
|
|
Shinya Kitaoka |
120a6e |
char *convertWCHAR2CHAR(const wchar_t *wc) {
|
|
Shinya Kitaoka |
120a6e |
int count = 0;
|
|
Shinya Kitaoka |
120a6e |
const wchar_t *ptr = wc;
|
|
Shinya Kitaoka |
120a6e |
char *c = 0;
|
|
Shinya Kitaoka |
120a6e |
char *buff;
|
|
Shinya Kitaoka |
120a6e |
while ((*ptr) != '\0') {
|
|
Shinya Kitaoka |
120a6e |
++count;
|
|
Shinya Kitaoka |
120a6e |
++ptr;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
c = (char *)malloc((count + 1) * sizeof(char));
|
|
Shinya Kitaoka |
120a6e |
buff = c;
|
|
Shinya Kitaoka |
120a6e |
ptr = wc;
|
|
Shinya Kitaoka |
120a6e |
while ((*ptr) != '\0') {
|
|
Shinya Kitaoka |
120a6e |
*c = *ptr;
|
|
Shinya Kitaoka |
120a6e |
++c;
|
|
Shinya Kitaoka |
120a6e |
++ptr;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
*c = 0;
|
|
Shinya Kitaoka |
120a6e |
return buff;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
#if defined(MACOSX) || defined(LINUX)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FILE *_wfopen(const wchar_t *fname, const wchar_t *mode) {
|
|
Shinya Kitaoka |
120a6e |
char *cfname = convertWCHAR2CHAR(fname);
|
|
Shinya Kitaoka |
120a6e |
char *cmode = convertWCHAR2CHAR(mode);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FILE *f = fopen(cfname, cmode);
|
|
Shinya Kitaoka |
120a6e |
free(cfname);
|
|
Shinya Kitaoka |
120a6e |
free(cmode);
|
|
Shinya Kitaoka |
120a6e |
return f;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int _wstat(const wchar_t *fname, struct stat *buf) {
|
|
Shinya Kitaoka |
120a6e |
char *cfname = convertWCHAR2CHAR(fname);
|
|
Shinya Kitaoka |
120a6e |
int rc = stat(cfname, buf);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
free(cfname);
|
|
Shinya Kitaoka |
120a6e |
return rc;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int _wremove(const wchar_t *fname) {
|
|
Shinya Kitaoka |
120a6e |
char *cfname = convertWCHAR2CHAR(fname);
|
|
Shinya Kitaoka |
120a6e |
int rc = remove(cfname);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
free(cfname);
|
|
Shinya Kitaoka |
120a6e |
return rc;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|