diff options
| author | uema2 <uema2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-12-14 05:27:35 +0000 |
|---|---|---|
| committer | uema2 <uema2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-12-14 05:27:35 +0000 |
| commit | 41aa7849ad9efa0da495802e2b0a472a1402be09 (patch) | |
| tree | c26991efff67368cda5153751d797893b796fc80 /wince/sys/stat.c | |
| parent | 65716b585693c5c6c4b536cb3c6cce4636017ef6 (diff) | |
| download | ruby-41aa7849ad9efa0da495802e2b0a472a1402be09.tar.gz ruby-41aa7849ad9efa0da495802e2b0a472a1402be09.tar.xz ruby-41aa7849ad9efa0da495802e2b0a472a1402be09.zip | |
* wince/sys : add stat.c, stat.h, timeb.c, timeb.h,
types.h, utime.c, utime.h
* wince/dll.mak : object file name changed.
* wince/io.c : add empty dup2().
* wince/io.h : add dup2 definition.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'wince/sys/stat.c')
| -rw-r--r-- | wince/sys/stat.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/wince/sys/stat.c b/wince/sys/stat.c new file mode 100644 index 000000000..f898a69f4 --- /dev/null +++ b/wince/sys/stat.c @@ -0,0 +1,101 @@ +/*************************************************************** + stat.c + + author : uema2 + date : Nov 30, 2002 + + You can freely use, copy, modify, and redistribute + the whole contents. +***************************************************************/ + +#include <windows.h> +#include <sys/stat.h> +#include <time.h> +#include "..\wince.h" /* for wce_mbtowc */ + + +int _stat(const char *filename, struct _stat *st) +{ + DWORD dwAttribute; + HANDLE h; + DWORD dwSizeLow=0, dwSizeHigh=0, dwError=0; + WIN32_FIND_DATAW fd; + wchar_t *wfilename; + + wfilename = wce_mbtowc(filename); + + dwAttribute = GetFileAttributesW(wfilename); + if(dwAttribute==0xFFFFFFFF) + { + free(wfilename); + return -1; + } + + st->st_mode = 0; + if((dwAttribute & FILE_ATTRIBUTE_DIRECTORY) != 0) + st->st_mode += S_IFDIR; + else + st->st_mode += S_IFREG; + + /* initialize */ + st->st_atime = 0; + st->st_mtime = 0; + st->st_ctime = 0; + st->st_size = 0; + st->st_dev = 0; + + h = FindFirstFileW(wfilename, &fd); + if(h == INVALID_HANDLE_VALUE) + { + if(wfilename[wcslen(wfilename)-1] == L'\\') + { + wfilename[wcslen(wfilename)-1] = L'\0'; + h = FindFirstFileW(wfilename, &fd); + if(h == INVALID_HANDLE_VALUE) + { + free(wfilename); + return 0; + } + } + else + { + free(wfilename); + return 0; + } + } + + /* FILETIME -> time_t */ + st->st_atime = wce_FILETIME2time_t(&fd.ftLastAccessTime); + st->st_mtime = wce_FILETIME2time_t(&fd.ftLastWriteTime); + st->st_ctime = wce_FILETIME2time_t(&fd.ftCreationTime); + st->st_size = fd.nFileSizeLow; + + FindClose( h ); + free(wfilename); + return 0; +} + +int fstat(int file, struct stat *sbuf) +{ + /* GetFileSize & GetFileTime */ + DWORD dwSize; + FILETIME ctime, atime, mtime; + + dwSize = GetFileSize( (HANDLE)file, NULL ); + if( dwSize == 0xFFFFFFFF ) + return -1; + + sbuf->st_size = dwSize; + sbuf->st_dev = 0; + sbuf->st_rdev = 0; + sbuf->st_mode = _S_IFREG; + sbuf->st_nlink= 1; + + GetFileTime( (HANDLE)file, &ctime, &atime, &mtime ); + sbuf->st_ctime = wce_FILETIME2time_t(&ctime); + sbuf->st_atime = wce_FILETIME2time_t(&atime); + sbuf->st_mtime = wce_FILETIME2time_t(&mtime); + + return 0; +} + |
