diff options
author | uema2 <uema2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-04-26 05:25:30 +0000 |
---|---|---|
committer | uema2 <uema2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-04-26 05:25:30 +0000 |
commit | 5f0df5186540dd5a6f11063f6e420c86636b235d (patch) | |
tree | 1330399ba14a2e9a26cba8c40db9ebd54ba95441 /wince/wince.c | |
parent | 6068cd754095d7f0742438ffd21d201775eda229 (diff) |
* wince/ : files removed.
(config, dll.mak, exe.mak, mswince-ruby17.def,
io.c, process.c, signal.c, string.c, time.c)
* wince/ : files added.
(assert.c, Makefile.sub, mkexports.rb, io_wce.c,
process_wce.c, signal_wce.c, string_wce.c,
time_wce.c)
* wince/configure.bat : like mswin32 style.
* wince/direct.c : remove "static" at _currentdir.
* wince/io.h : change definition.
* wince/stdio.c : _fdopen -> fdopen.
* wince/process.h : add_P_OVERLAY.
* wince/time.h : change definition.
* wince/wincemain.c : add wce_SetCurrentDir.
* wince/wince.c : add wce_SetCurrentDir and wce_fopen.
fix GetModuleFileNameA to return correct "lpFileName".
* wince/wince.h : remove #ifdef.
* wince/sys/utime.h, utime.c : rename _utime to utime.
* wince/sys/stat.c : expand relative directory in stat.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'wince/wince.c')
-rw-r--r-- | wince/wince.c | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/wince/wince.c b/wince/wince.c index e227fe528e..c1a950c1c1 100644 --- a/wince/wince.c +++ b/wince/wince.c @@ -15,6 +15,8 @@ /* global for GetCommandLineA */ char *_commandLine; +extern char _currentdir[]; + /* make up Win32API except wce_* functions. */ DWORD GetModuleFileNameA( @@ -23,18 +25,18 @@ DWORD GetModuleFileNameA( { LPWSTR lpFileNameW; LPSTR mb; - size_t len; + size_t ret; + + if( size==0 ) return 0; lpFileNameW = (LPWSTR)malloc( size*sizeof(wchar_t) ); - GetModuleFileNameW( hModule, lpFileNameW, size ); + ret = GetModuleFileNameW( hModule, lpFileNameW, size ); mb = wce_wctomb(lpFileNameW); - len = min(strlen(mb),size); - strncpy(lpFileName, mb, len); - lpFileName[len-1] = '\0'; + strcpy(lpFileName, mb); free(mb); free(lpFileNameW); - return 0; + return ret; } #if _WIN32_WCE < 300 @@ -48,7 +50,7 @@ FARPROC GetProcAddressA(HMODULE hModule, LPCSTR lpProcName) free( lpwProcName ); return p; } -#endif +#endif char * GetCommandLineA(void) { @@ -448,6 +450,9 @@ HINSTANCE LoadLibraryA(LPCSTR libname) HINSTANCE h; LPWSTR wlibname; + // if starts ".\", replace current directory. +// wlibname = wce_replaceRelativeDir(libname); + wlibname = wce_mbtowc(libname); h = LoadLibraryW(wlibname); free(wlibname); @@ -461,6 +466,8 @@ HINSTANCE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, LPWSTR wlibname; wlibname = wce_mbtowc(lpLibFileName); +// wlibname = wce_replaceRelativeDir(lpLibFileName); + #if _WIN32_WCE < 300 h = LoadLibraryW(wlibname); #else @@ -503,6 +510,47 @@ int ReadDataPending() } /*---------------- helper functions. ---------------------------- */ +FILE *wce_fopen( const char *fname, const char *mode ) +{ + TCHAR* tfname = wce_replaceRelativeDir(fname); + TCHAR* tmode = wce_mbtowc(mode); + FILE* fp = _tfopen(tfname, tmode); + free(tfname); free(tmode); + return fp; +} + +void wce_SetCurrentDir() +{ + WCHAR tbuf[MAX_PATH+1]={0}; + WCHAR *tp; + char *buf; + + GetModuleFileNameW( NULL, tbuf, MAX_PATH ); + tp = _tcsrchr( tbuf, '\\' ); + if( tp!=NULL ) *tp=_T('\0'); + buf = wce_wctomb(tbuf); + strcpy( _currentdir, buf ); + free(buf); +} + +TCHAR *wce_replaceRelativeDir(const char* str) +{ + TCHAR *tbuf; + + if( 2<=strlen(str) && str[0]=='.' && + (str[1]=='/' || str[1]=='\\') ) + { + char *buf; + int len = strlen(str) + strlen(_currentdir); + buf = malloc( len+1 ); + sprintf(buf, "%s%s", _currentdir, &str[1]); + tbuf = wce_mbtowc(buf); + free(buf); + } + else + tbuf = wce_mbtowc(str); + return tbuf; +} /* char -> wchar_t */ wchar_t* wce_mbtowc(const char* a) |