]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/wince/filefnwce.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/wince/filefn.cpp
3 // Purpose: File- and directory-related functions
4 // Author: Julian Smart
7 // Copyright: (c) 1998 Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
34 #include "wx/msw/wince/missing.h"
36 int wxCRT_Open(const wxChar
*filename
, int oflag
, int WXUNUSED(pmode
))
40 DWORD disposition
= 0;
42 if ((oflag
& (O_RDONLY
| O_WRONLY
| O_RDWR
)) == O_RDONLY
)
44 access
= GENERIC_READ
;
45 shareMode
= FILE_SHARE_READ
|FILE_SHARE_WRITE
;
46 disposition
= OPEN_EXISTING
;
48 else if ((oflag
& (O_RDONLY
| O_WRONLY
| O_RDWR
)) == O_WRONLY
)
50 access
= GENERIC_WRITE
;
51 disposition
= OPEN_ALWAYS
;
53 else if ((oflag
& (O_RDONLY
| O_WRONLY
| O_RDWR
)) == O_RDWR
)
55 access
= GENERIC_READ
|GENERIC_WRITE
;
56 disposition
= OPEN_ALWAYS
;
61 if ( wxFile::Exists(filename
) )
63 access
|= GENERIC_WRITE
;
64 shareMode
= FILE_SHARE_READ
;
65 disposition
= OPEN_EXISTING
;
74 access
|= GENERIC_WRITE
;
76 disposition
= oflag
& O_CREAT
? CREATE_ALWAYS
: TRUNCATE_EXISTING
;
78 else if (oflag
& O_CREAT
)
80 access
|= GENERIC_WRITE
;
82 disposition
= CREATE_NEW
;
84 else if (oflag
& O_EXCL
)
86 access
|= GENERIC_WRITE
;
88 disposition
= TRUNCATE_EXISTING
;
92 HANDLE fileHandle
= ::CreateFile(filename
, access
, shareMode
, NULL
,
93 disposition
, FILE_ATTRIBUTE_NORMAL
, 0);
94 if (fileHandle
== INVALID_HANDLE_VALUE
)
97 fd
= (int) fileHandle
;
102 int wxCRT_Access(const wxChar
*name
, int WXUNUSED(how
))
104 HANDLE fileHandle
= ::CreateFile(name
, 0, FILE_SHARE_DELETE
| FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
105 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0);
107 if (fileHandle
== INVALID_HANDLE_VALUE
)
110 CloseHandle(fileHandle
);
117 if (CloseHandle((HANDLE
)fd
))
124 DWORD off0
= SetFilePointer((HANDLE
) fd
, 0, NULL
, FILE_CURRENT
);
125 if (off0
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
128 DWORD off1
= SetFilePointer((HANDLE
) fd
, 0, NULL
, FILE_END
);
129 if (off1
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
136 SetFilePointer((HANDLE
) fd
, off0
, NULL
, FILE_BEGIN
);
141 int wxRead(int fd
, void *buf
, unsigned int count
)
145 if (ReadFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesRead
, NULL
))
151 int wxWrite(int fd
, const void *buf
, unsigned int count
)
153 DWORD bytesWritten
= 0;
155 if (WriteFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesWritten
, NULL
))
161 __int64
wxSeek(int fd
, __int64 offset
, int origin
)
166 wxFAIL_MSG(_("unknown seek origin"));
173 method
= FILE_CURRENT
;
181 DWORD res
= SetFilePointer((HANDLE
) fd
, offset
, NULL
, method
) ;
182 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
184 wxLogSysError(_("can't seek on file descriptor %d"), fd
);
185 return wxInvalidOffset
;
191 __int64
wxTell(int fd
)
193 // WinCE apparently doesn't support lpDistanceToMoveHigh.
195 DWORD res
= SetFilePointer((HANDLE
) fd
, 0, NULL
, FILE_CURRENT
) ;
196 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
198 wxLogSysError(_("can't get seek position on file descriptor %d"), fd
);
199 return wxInvalidOffset
;
202 return res
; // + (((__int64)high) << 32);
205 int wxFsync(int WXUNUSED(fd
))