summaryrefslogtreecommitdiff
path: root/ruby_1_8_5/wince/sys
diff options
context:
space:
mode:
Diffstat (limited to 'ruby_1_8_5/wince/sys')
-rw-r--r--ruby_1_8_5/wince/sys/stat.c102
-rw-r--r--ruby_1_8_5/wince/sys/stat.h68
-rw-r--r--ruby_1_8_5/wince/sys/timeb.c25
-rw-r--r--ruby_1_8_5/wince/sys/timeb.h26
-rw-r--r--ruby_1_8_5/wince/sys/types.h60
-rw-r--r--ruby_1_8_5/wince/sys/utime.c44
-rw-r--r--ruby_1_8_5/wince/sys/utime.h27
7 files changed, 352 insertions, 0 deletions
diff --git a/ruby_1_8_5/wince/sys/stat.c b/ruby_1_8_5/wince/sys/stat.c
new file mode 100644
index 0000000000..5d51dbf426
--- /dev/null
+++ b/ruby_1_8_5/wince/sys/stat.c
@@ -0,0 +1,102 @@
+/***************************************************************
+ 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);
+ wfilename = wce_replaceRelativeDir(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;
+}
+
diff --git a/ruby_1_8_5/wince/sys/stat.h b/ruby_1_8_5/wince/sys/stat.h
new file mode 100644
index 0000000000..e3cdf8b8e7
--- /dev/null
+++ b/ruby_1_8_5/wince/sys/stat.h
@@ -0,0 +1,68 @@
+#ifndef SYS_STAT_H
+#define SYS_STAT_H 1
+
+#include <sys/types.h>
+
+#define _S_IFMT 0170000 /* file type mask */
+#define _S_IFDIR 0040000 /* directory */
+#define _S_IFCHR 0020000 /* character special */
+#define _S_IFIFO 0010000 /* pipe */
+#define _S_IFREG 0100000 /* regular */
+#define _S_IREAD 0000400 /* read permission, owner */
+#define _S_IWRITE 0000200 /* write permission, owner */
+#define _S_IEXEC 0000100 /* execute/search permission, owner */
+
+#define S_IFMT _S_IFMT
+#define S_IFREG _S_IFREG
+#define S_IFCHR _S_IFCHR
+#define S_IFDIR _S_IFDIR
+#define S_IREAD _S_IREAD
+#define S_IWRITE _S_IWRITE
+#define S_IEXEC _S_IEXEC
+
+#ifndef S_ISDIR
+#define S_ISDIR(X) (((X) & S_IFMT) == S_IFDIR)
+#endif
+#ifndef S_ISREG
+#define S_ISREG(X) (((X) & S_IFMT) == S_IFREG)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// in sys/types.h
+//typedef unsigned int _dev_t;
+//typedef long _off_t;
+//typedef unsigned short _ino_t;
+
+#ifndef _STAT_DEFINED
+struct stat
+{
+ dev_t st_dev;
+ ino_t st_ino;
+ unsigned short st_mode;
+ short st_nlink;
+ short st_uid;
+ short st_gid;
+ dev_t st_rdev;
+ off_t st_size;
+ time_t st_atime;
+ time_t st_mtime;
+ time_t st_ctime;
+};
+#define _STAT_DEFINED
+#endif /* _STAT_DEFINED */
+
+#define _stat stat
+
+int _stat(const char *filename, struct _stat *stat);
+int fstat(int file, struct stat *sbuf);
+
+
+#ifdef __cplusplus
+};
+#endif
+
+
+#endif
diff --git a/ruby_1_8_5/wince/sys/timeb.c b/ruby_1_8_5/wince/sys/timeb.c
new file mode 100644
index 0000000000..838ae0798d
--- /dev/null
+++ b/ruby_1_8_5/wince/sys/timeb.c
@@ -0,0 +1,25 @@
+/***************************************************************
+ timeb.c
+***************************************************************/
+
+#include <windows.h>
+#include <time.h>
+#include <sys/timeb.h>
+
+
+int ftime(struct timeb *tp)
+{
+ SYSTEMTIME s;
+ FILETIME f;
+
+ GetLocalTime(&s);
+ SystemTimeToFileTime( &s, &f );
+
+ tp->dstflag = 0;
+ tp->timezone = _timezone/60;
+ tp->time = wce_FILETIME2time_t(&f);
+ tp->millitm = s.wMilliseconds;
+
+ return 0;
+}
+
diff --git a/ruby_1_8_5/wince/sys/timeb.h b/ruby_1_8_5/wince/sys/timeb.h
new file mode 100644
index 0000000000..e051b9058c
--- /dev/null
+++ b/ruby_1_8_5/wince/sys/timeb.h
@@ -0,0 +1,26 @@
+#ifndef SYS_TIMEB_H
+#define SYS_TIMEB_H 1
+
+#include <sys/types.h>
+
+struct _timeb {
+ time_t time;
+ unsigned short millitm;
+ short timezone;
+ short dstflag;
+};
+
+#define timeb _timeb
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int ftime(struct timeb *tp);
+
+#ifdef __cplusplus
+};
+#endif
+
+
+#endif
diff --git a/ruby_1_8_5/wince/sys/types.h b/ruby_1_8_5/wince/sys/types.h
new file mode 100644
index 0000000000..541d5e8361
--- /dev/null
+++ b/ruby_1_8_5/wince/sys/types.h
@@ -0,0 +1,60 @@
+#ifndef SYS_TYPES_H
+#define SYS_TYPES_H 1
+
+#define BIG_ENDIAN 1234
+#define LITTLE_ENDIAN 4321
+
+#ifdef MIPS
+#define BYTE_ORDER LITTLE_ENDIAN
+#endif
+
+//#if UNDER_CE > 201
+// typedef unsigned long time_t;
+// #define _TIME_T_DEFINED_
+//#endif
+typedef unsigned long dev_t;
+typedef unsigned long ino_t;
+#ifndef _MODE_T_DEFINED_
+ typedef unsigned long mode_t;
+ #define _MODE_T_DEFINED_
+#endif
+
+typedef long clock_t;
+
+#ifndef _PTRDIFF_T_DEFINED
+typedef long ptrdiff_t;
+#define _PTRDIFF_T_DEFINED
+#endif
+
+typedef long off_t;
+
+//typedef unsigned char u_char;
+//typedef unsigned short u_short;
+
+#ifndef _CADDR_T_DEFINED_
+typedef unsigned char * caddr_t;
+#define _CADDR_T_DEFINED_
+#endif
+
+#ifndef _SIZE_T_DEFINED_
+typedef unsigned int size_t;
+#define _SIZE_T_DEFINED_
+#endif
+
+//typedef unsigned char u_int8_t;
+
+//typedef short int16_t;
+//typedef unsigned short u_int16_t;
+
+//typedef int int32_t;
+//typedef unsigned int u_int32_t;
+
+//typedef unsigned long u_long;
+//typedef unsigned int u_int;
+
+//#ifndef _TIME_T_DEFINED_
+//typedef unsigned long time_t;
+//#define _TIME_T_DEFINED_
+//#endif
+
+#endif
diff --git a/ruby_1_8_5/wince/sys/utime.c b/ruby_1_8_5/wince/sys/utime.c
new file mode 100644
index 0000000000..0139c13828
--- /dev/null
+++ b/ruby_1_8_5/wince/sys/utime.c
@@ -0,0 +1,44 @@
+/***************************************************************
+ utime.c
+***************************************************************/
+
+#include <windows.h>
+#include <sys/utime.h>
+#include "..\wince.h" /* for wce_mbtowc */
+
+
+#ifdef _WIN32_WCE
+ #if _WIN32_WCE < 300
+ #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
+/* #define Int32x32To64(a, b) ((__int64)((LONG)(a)) * (__int64)((LONG)(b))) */
+ #endif
+#endif
+
+int utime(const char *f, struct utimbuf *t)
+{
+ HANDLE h;
+ FILETIME atime={0}, mtime={0};
+ __int64 time64;
+ BOOL rc;
+ wchar_t *w;
+
+ w = wce_mbtowc(f);
+ h = CreateFileW(w, GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, 0, 0);
+ free(w);
+
+ if( h==INVALID_HANDLE_VALUE )
+ return -1;
+
+ time64 = Int32x32To64(t->actime, 10000000) + 116444736000000000;
+ atime.dwLowDateTime = (DWORD)time64;
+ atime.dwHighDateTime = (DWORD)(time64 >> 32);
+ time64 = Int32x32To64(t->modtime, 10000000) + 116444736000000000;
+ mtime.dwLowDateTime = (DWORD)time64;
+ mtime.dwHighDateTime = (DWORD)(time64 >> 32);
+
+ rc = SetFileTime(h, NULL, &atime, &mtime);
+ return rc==TRUE ? 0 : -1;
+}
+
diff --git a/ruby_1_8_5/wince/sys/utime.h b/ruby_1_8_5/wince/sys/utime.h
new file mode 100644
index 0000000000..b644f02a61
--- /dev/null
+++ b/ruby_1_8_5/wince/sys/utime.h
@@ -0,0 +1,27 @@
+#ifndef SYS_UTIME_H
+#define SYS_UTIME_H 1
+
+#include <time.h>
+
+struct utimbuf
+{
+ time_t actime;
+ time_t modtime;
+};
+
+#define _utimbuf utimbuf
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int utime(const char *f, struct utimbuf *t);
+
+#ifdef __cplusplus
+};
+#endif
+
+//#define utime _utime
+
+#endif