summaryrefslogtreecommitdiff
path: root/wince
diff options
context:
space:
mode:
authoruema2 <uema2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-14 05:27:35 +0000
committeruema2 <uema2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-14 05:27:35 +0000
commit009f78761d729b18ac34749136f1474d89d54a69 (patch)
treec26991efff67368cda5153751d797893b796fc80 /wince
parentc79e87783658aa264c3939497a1855942b0e6c5b (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')
-rw-r--r--wince/dll.mak20
-rw-r--r--wince/io.c8
-rw-r--r--wince/io.h1
-rw-r--r--wince/sys/stat.c101
-rw-r--r--wince/sys/stat.h68
-rw-r--r--wince/sys/timeb.c25
-rw-r--r--wince/sys/timeb.h26
-rw-r--r--wince/sys/types.h67
-rw-r--r--wince/sys/utime.c44
-rw-r--r--wince/sys/utime.h27
10 files changed, 369 insertions, 18 deletions
diff --git a/wince/dll.mak b/wince/dll.mak
index cc987d1..4fcc529 100644
--- a/wince/dll.mak
+++ b/wince/dll.mak
@@ -68,7 +68,6 @@ CLEAN :
-@erase "$(INTDIR)\dir.obj"
-@erase "$(INTDIR)\dln.obj"
-@erase "$(INTDIR)\dmyext.obj"
- -@erase "$(INTDIR)\dup2.obj"
-@erase "$(INTDIR)\enum.obj"
-@erase "$(INTDIR)\error.obj"
-@erase "$(INTDIR)\eval.obj"
@@ -108,7 +107,7 @@ CLEAN :
-@erase "$(OUTDIR)\mswince_ruby17.lib"
-@erase "$(OUTDIR)\wce\direct.obj"
-@erase "$(OUTDIR)\wce\errno.obj"
- -@erase "$(OUTDIR)\wce\ceio.obj"
+ -@erase "$(OUTDIR)\wce\io.obj"
-@erase "$(OUTDIR)\wce\parse.obj"
-@erase "$(OUTDIR)\wce\process.obj"
-@erase "$(OUTDIR)\wce\signal.obj"
@@ -116,7 +115,7 @@ CLEAN :
-@erase "$(OUTDIR)\wce\stdio.obj"
-@erase "$(OUTDIR)\wce\stdlib.obj"
-@erase "$(OUTDIR)\wce\string.obj"
- -@erase "$(OUTDIR)\wce\cetime.obj"
+ -@erase "$(OUTDIR)\wce\time.obj"
-@erase "$(OUTDIR)\wce\timeb.obj"
-@erase "$(OUTDIR)\wce\utime.obj"
-@erase "$(OUTDIR)\wce\wince.obj"
@@ -213,7 +212,6 @@ LINK32_OBJS= \
"$(INTDIR)\win32.obj" \
"$(INTDIR)\acosh.obj" \
"$(INTDIR)\crypt.obj" \
- "$(INTDIR)\dup2.obj" \
"$(INTDIR)\hypot.obj" \
"$(INTDIR)\isinf.obj" \
"$(INTDIR)\isnan.obj" \
@@ -260,7 +258,6 @@ CLEAN :
-@erase "$(INTDIR)\dir.obj"
-@erase "$(INTDIR)\dln.obj"
-@erase "$(INTDIR)\dmyext.obj"
- -@erase "$(INTDIR)\dup2.obj"
-@erase "$(INTDIR)\enum.obj"
-@erase "$(INTDIR)\error.obj"
-@erase "$(INTDIR)\eval.obj"
@@ -405,7 +402,6 @@ LINK32_OBJS= \
"$(INTDIR)\win32.obj" \
"$(INTDIR)\acosh.obj" \
"$(INTDIR)\crypt.obj" \
- "$(INTDIR)\dup2.obj" \
"$(INTDIR)\hypot.obj" \
"$(INTDIR)\isinf.obj" \
"$(INTDIR)\isnan.obj" \
@@ -452,7 +448,6 @@ CLEAN :
-@erase "$(INTDIR)\dir.obj"
-@erase "$(INTDIR)\dln.obj"
-@erase "$(INTDIR)\dmyext.obj"
- -@erase "$(INTDIR)\dup2.obj"
-@erase "$(INTDIR)\enum.obj"
-@erase "$(INTDIR)\error.obj"
-@erase "$(INTDIR)\eval.obj"
@@ -597,7 +592,6 @@ LINK32_OBJS= \
"$(INTDIR)\win32.obj" \
"$(INTDIR)\acosh.obj" \
"$(INTDIR)\crypt.obj" \
- "$(INTDIR)\dup2.obj" \
"$(INTDIR)\hypot.obj" \
"$(INTDIR)\isinf.obj" \
"$(INTDIR)\isnan.obj" \
@@ -644,7 +638,6 @@ CLEAN :
-@erase "$(INTDIR)\dir.obj"
-@erase "$(INTDIR)\dln.obj"
-@erase "$(INTDIR)\dmyext.obj"
- -@erase "$(INTDIR)\dup2.obj"
-@erase "$(INTDIR)\enum.obj"
-@erase "$(INTDIR)\error.obj"
-@erase "$(INTDIR)\eval.obj"
@@ -789,7 +782,6 @@ LINK32_OBJS= \
"$(INTDIR)\win32.obj" \
"$(INTDIR)\acosh.obj" \
"$(INTDIR)\crypt.obj" \
- "$(INTDIR)\dup2.obj" \
"$(INTDIR)\hypot.obj" \
"$(INTDIR)\isinf.obj" \
"$(INTDIR)\isnan.obj" \
@@ -1186,9 +1178,6 @@ LINK32_OBJS= \
".\config.h"\
".\wince.h"\
-..\missing\dup2.c : \
- ".\config.h"\
-
..\missing\isinf.c : \
".\config.h"\
@@ -1427,11 +1416,6 @@ SOURCE=..\missing\crypt.c
"$(INTDIR)\crypt.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
-SOURCE=..\missing\dup2.c
-
-"$(INTDIR)\dup2.obj" : $(SOURCE) "$(INTDIR)"
- $(CPP) $(CPP_PROJ) $(SOURCE)
-
SOURCE=..\missing\hypot.c
"$(INTDIR)\hypot.obj" : $(SOURCE) "$(INTDIR)"
diff --git a/wince/io.c b/wince/io.c
index 3d3f1be..4d2f21d 100644
--- a/wince/io.c
+++ b/wince/io.c
@@ -183,12 +183,20 @@ int _chmod(const char *path, int mode)
return 0;
}
+/* WinCE doesn't have dup and dup2. */
+/* so, we cannot use missing/dup2.c. */
int _dup( int handle )
{
errno = EBADF;
return -1;
}
+int dup2( int handle1, int handle2 )
+{
+ errno = EBADF;
+ return -1;
+}
+
int _isatty(int fd)
{
if( fd==(int)_fileno(stdin) ||
diff --git a/wince/io.h b/wince/io.h
index a303318..46c4a84 100644
--- a/wince/io.h
+++ b/wince/io.h
@@ -30,6 +30,7 @@ int _unlink(const char *file);
int _umask(int cmask);
int _chmod(const char *path, int mode);
int _dup( int handle );
+int dup2( int handle1, int handle2 );
int _isatty(int fd);
int _pipe(int *phandles, unsigned int psize, int textmode);
int _access(const char *filename, int flags);
diff --git a/wince/sys/stat.c b/wince/sys/stat.c
new file mode 100644
index 0000000..f898a69
--- /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;
+}
+
diff --git a/wince/sys/stat.h b/wince/sys/stat.h
new file mode 100644
index 0000000..e3cdf8b
--- /dev/null
+++ b/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/wince/sys/timeb.c b/wince/sys/timeb.c
new file mode 100644
index 0000000..838ae07
--- /dev/null
+++ b/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/wince/sys/timeb.h b/wince/sys/timeb.h
new file mode 100644
index 0000000..e051b90
--- /dev/null
+++ b/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/wince/sys/types.h b/wince/sys/types.h
new file mode 100644
index 0000000..214bd4a
--- /dev/null
+++ b/wince/sys/types.h
@@ -0,0 +1,67 @@
+#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 unsigned short gid_t;
+//typedef unsigned short uid_t;
+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
+
+#ifndef _PID_T_DEFINED_
+typedef unsigned long pid_t;
+#define _PID_T_DEFINED_
+#endif
+
+#endif
diff --git a/wince/sys/utime.c b/wince/sys/utime.c
new file mode 100644
index 0000000..02ce275
--- /dev/null
+++ b/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/wince/sys/utime.h b/wince/sys/utime.h
new file mode 100644
index 0000000..46a4ddc
--- /dev/null
+++ b/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