Skip to content
Newer
Older
100644 231 lines (187 sloc) 4.21 KB
4d6d2ae WinCE patch merged
matz authored Dec 2, 2002
1 /***************************************************************
2 io.c
3
4 author : uema2
5 date : Nov 30, 2002
6
7 You can freely use, copy, modify, and redistribute
8 the whole contents.
9 ***************************************************************/
10
11 #include <windows.h>
12 #include <stdlib.h>
13 #include <io.h>
14 #include <fcntl.h>
15 #include <time.h>
16 #include <errno.h>
17 #include "wince.h" /* for wce_mbtowc */
18
19 extern int _errno;
20
21
22 int _rename(const char *oldname, const char *newname)
23 {
24 wchar_t *wold, *wnew;
25 BOOL rc;
26
27 wold = wce_mbtowc(oldname);
28 wnew = wce_mbtowc(newname);
29
30 /* replace with MoveFile. */
31 rc = MoveFileW(wold, wnew);
32
33 free(wold);
34 free(wnew);
35
36 return rc==TRUE ? 0 : -1;
37 }
38
39 int _unlink(const char *file)
40 {
41 wchar_t *wfile;
42 BOOL rc;
43
44 /* replace with DeleteFile. */
45 wfile = wce_mbtowc(file);
46 rc = DeleteFileW(wfile);
47 free(wfile);
48
49 return rc==TRUE ? 0 : -1;
50 }
51
52 /* replace "open" with "CreateFile", etc. */
53 int _open(const char *file, int mode, va_list arg)
54 {
55 wchar_t *wfile;
56 DWORD access=0, share=0, create=0;
57 HANDLE h;
58
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;
65
66 if( (mode&_O_CREAT) != 0 )
67 create = CREATE_ALWAYS;
68 else
69 create = OPEN_ALWAYS;
70
71 wfile = wce_mbtowc(file);
72
73 h = CreateFileW(wfile, access, share, NULL,
74 create, 0, NULL );
75
76 free(wfile);
77 return (int)h;
78 }
79
61e00f2 * wince/ : files removed.
uema2 authored Apr 26, 2003
80 int close(int fd)
4d6d2ae WinCE patch merged
matz authored Dec 2, 2002
81 {
82 CloseHandle( (HANDLE)fd );
83 return 0;
84 }
85
86 int _read(int fd, void *buffer, int length)
87 {
88 DWORD dw;
89 ReadFile( (HANDLE)fd, buffer, length, &dw, NULL );
90 return (int)dw;
91 }
92
93 int _write(int fd, const void *buffer, unsigned count)
94 {
95 DWORD dw;
96 WriteFile( (HANDLE)fd, buffer, count, &dw, NULL );
97 return (int)dw;
98 }
99
100 long _lseek(int handle, long offset, int origin)
101 {
102 DWORD flag, ret;
103
104 switch(origin)
105 {
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;
110 }
111
112 ret = SetFilePointer( (HANDLE)handle, offset, NULL, flag );
113 return ret==0xFFFFFFFF ? -1 : 0;
114 }
115
116 /* _findfirst, _findnext, _findclose. */
117 /* replace them with FindFirstFile, etc. */
118 long _findfirst( char *file, struct _finddata_t *fi )
119 {
120 HANDLE h;
121 WIN32_FIND_DATAA fda;
122
123 h = FindFirstFileA( file, &fda );
124 if( h==NULL )
125 {
126 errno = EINVAL; return -1;
127 }
128
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 );
135
136 return (long)h;
137 }
138
139 int _findnext( long handle, struct _finddata_t *fi )
140 {
141 WIN32_FIND_DATAA fda;
142 BOOL b;
143
144 b = FindNextFileA( (HANDLE)handle, &fda );
145
146 if( b==FALSE )
147 {
148 errno = ENOENT; return -1;
149 }
150
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 );
157
158 return 0;
159 }
160
161 int _findclose( long handle )
162 {
163 BOOL b;
164 b = FindClose( (HANDLE)handle );
165 return b==FALSE ? -1 : 0;
166 }
167
168 /* below functions unsupported... */
169 /* I have no idea how to replace... */
170 int _chsize(int handle, long size)
171 {
172 errno = EACCES;
173 return -1;
174 }
175
176 int _umask(int cmask)
177 {
178 return 0;
179 }
180
181 int _chmod(const char *path, int mode)
182 {
183 return 0;
184 }
185
41aa784 * wince/sys : add stat.c, stat.h, timeb.c, timeb.h,
uema2 authored Dec 14, 2002
186 /* WinCE doesn't have dup and dup2. */
187 /* so, we cannot use missing/dup2.c. */
61e00f2 * wince/ : files removed.
uema2 authored Apr 26, 2003
188 int dup( int handle )
4d6d2ae WinCE patch merged
matz authored Dec 2, 2002
189 {
190 errno = EBADF;
191 return -1;
192 }
61e00f2 * wince/ : files removed.
uema2 authored Apr 26, 2003
193 /*
41aa784 * wince/sys : add stat.c, stat.h, timeb.c, timeb.h,
uema2 authored Dec 14, 2002
194 int dup2( int handle1, int handle2 )
195 {
196 errno = EBADF;
197 return -1;
198 }
61e00f2 * wince/ : files removed.
uema2 authored Apr 26, 2003
199 */
4d6d2ae WinCE patch merged
matz authored Dec 2, 2002
200 int _isatty(int fd)
201 {
202 if( fd==(int)_fileno(stdin) ||
203 fd==(int)_fileno(stdout)||
204 fd==(int)_fileno(stderr) )
205 return 1;
206 else
207 return 0;
208 }
209
210 int _pipe(int *phandles, unsigned int psize, int textmode)
211 {
212 return -1;
213 }
214
215 int _access(const char *filename, int flags)
216 {
217 return 0;
218 }
219
220 int _open_osfhandle( long osfhandle, int flags)
221 {
222 /* return 0; */
223 return (int)osfhandle;
224 }
225
226 long _get_osfhandle( int filehandle )
227 {
228 /* return 0; */
229 return (long)filehandle;
230 }
Something went wrong with that request. Please try again.