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 | 009f78761d729b18ac34749136f1474d89d54a69 (patch) | |
tree | c26991efff67368cda5153751d797893b796fc80 /wince/sys/stat.c | |
parent | c79e87783658aa264c3939497a1855942b0e6c5b (diff) |
* 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: svn+ssh://ci.ruby-lang.org/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 0000000000..f898a69f40 --- /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; +} + |