1 /***************************************************************
7 You can freely use, copy, modify, and redistribute
9 ***************************************************************/
17 #include "wince.h" /* for wce_mbtowc */
22 int _rename(const char *oldname
, const char *newname
)
27 wold
= wce_mbtowc(oldname
);
28 wnew
= wce_mbtowc(newname
);
30 /* replace with MoveFile. */
31 rc
= MoveFileW(wold
, wnew
);
36 return rc
==TRUE
? 0 : -1;
39 int _unlink(const char *file
)
44 /* replace with DeleteFile. */
45 wfile
= wce_mbtowc(file
);
46 rc
= DeleteFileW(wfile
);
49 return rc
==TRUE
? 0 : -1;
52 /* replace "open" with "CreateFile", etc. */
53 int _open(const char *file
, int mode
, va_list arg
)
56 DWORD access
=0, share
=0, create
=0;
59 if( (mode
&_O_RDWR
) != 0 )
60 access
= GENERIC_READ
|GENERIC_WRITE
;
61 else if( (mode
&_O_RDONLY
) != 0 )
62 access
= GENERIC_READ
;
63 else if( (mode
&_O_WRONLY
) != 0 )
64 access
= GENERIC_WRITE
;
66 if( (mode
&_O_CREAT
) != 0 )
67 create
= CREATE_ALWAYS
;
71 wfile
= wce_mbtowc(file
);
73 h
= CreateFileW(wfile
, access
, share
, NULL
,
82 CloseHandle( (HANDLE
)fd
);
86 int _read(int fd
, void *buffer
, int length
)
89 ReadFile( (HANDLE
)fd
, buffer
, length
, &dw
, NULL
);
93 int _write(int fd
, const void *buffer
, unsigned count
)
96 WriteFile( (HANDLE
)fd
, buffer
, count
, &dw
, NULL
);
100 long _lseek(int handle
, long offset
, int origin
)
106 case SEEK_SET
: flag
= FILE_BEGIN
; break;
107 case SEEK_CUR
: flag
= FILE_CURRENT
; break;
108 case SEEK_END
: flag
= FILE_END
; break;
109 default: flag
= FILE_CURRENT
; break;
112 ret
= SetFilePointer( (HANDLE
)handle
, offset
, NULL
, flag
);
113 return ret
==0xFFFFFFFF ? -1 : 0;
116 /* _findfirst, _findnext, _findclose. */
117 /* replace them with FindFirstFile, etc. */
118 long _findfirst( char *file
, struct _finddata_t
*fi
)
121 WIN32_FIND_DATAA fda
;
123 h
= FindFirstFileA( file
, &fda
);
126 errno
= EINVAL
; return -1;
129 fi
->attrib
= fda
.dwFileAttributes
;
130 fi
->time_create
= wce_FILETIME2time_t( &fda
.ftCreationTime
);
131 fi
->time_access
= wce_FILETIME2time_t( &fda
.ftLastAccessTime
);
132 fi
->time_write
= wce_FILETIME2time_t( &fda
.ftLastWriteTime
);
133 fi
->size
= fda
.nFileSizeLow
+ (fda
.nFileSizeHigh
<<32);
134 strcpy( fi
->name
, fda
.cFileName
);
139 int _findnext( long handle
, struct _finddata_t
*fi
)
141 WIN32_FIND_DATAA fda
;
144 b
= FindNextFileA( (HANDLE
)handle
, &fda
);
148 errno
= ENOENT
; return -1;
151 fi
->attrib
= fda
.dwFileAttributes
;
152 fi
->time_create
= wce_FILETIME2time_t( &fda
.ftCreationTime
);
153 fi
->time_access
= wce_FILETIME2time_t( &fda
.ftLastAccessTime
);
154 fi
->time_write
= wce_FILETIME2time_t( &fda
.ftLastWriteTime
);
155 fi
->size
= fda
.nFileSizeLow
+ (fda
.nFileSizeHigh
<<32);
156 strcpy( fi
->name
, fda
.cFileName
);
161 int _findclose( long handle
)
164 b
= FindClose( (HANDLE
)handle
);
165 return b
==FALSE
? -1 : 0;
168 /* below functions unsupported... */
169 /* I have no idea how to replace... */
170 int _chsize(int handle
, long size
)
176 int _umask(int cmask
)
181 int _chmod(const char *path
, int mode
)
186 /* WinCE doesn't have dup and dup2. */
187 /* so, we cannot use missing/dup2.c. */
188 int dup( int handle
)
194 int dup2( int handle1, int handle2 )
202 if( fd
==(int)_fileno(stdin
) ||
203 fd
==(int)_fileno(stdout
)||
204 fd
==(int)_fileno(stderr
) )
210 int _pipe(int *phandles
, unsigned int psize
, int textmode
)
215 int _access(const char *filename
, int flags
)
220 int _open_osfhandle( long osfhandle
, int flags
)
223 return (int)osfhandle
;
226 long _get_osfhandle( int filehandle
)
229 return (long)filehandle
;