]>
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
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
35 #include "wx/msw/wince/missing.h"
37 int wxCRT_Open(const wxChar
*filename
, int oflag
, int WXUNUSED(pmode
))
41 DWORD disposition
= 0;
43 if ((oflag
& (O_RDONLY
| O_WRONLY
| O_RDWR
)) == O_RDONLY
)
45 access
= GENERIC_READ
;
46 shareMode
= FILE_SHARE_READ
|FILE_SHARE_WRITE
;
47 disposition
= OPEN_EXISTING
;
49 else if ((oflag
& (O_RDONLY
| O_WRONLY
| O_RDWR
)) == O_WRONLY
)
51 access
= GENERIC_WRITE
;
52 disposition
= OPEN_ALWAYS
;
54 else if ((oflag
& (O_RDONLY
| O_WRONLY
| O_RDWR
)) == O_RDWR
)
56 access
= GENERIC_READ
|GENERIC_WRITE
;
57 disposition
= OPEN_ALWAYS
;
62 if ( wxFile::Exists(filename
) )
64 access
|= GENERIC_WRITE
;
65 shareMode
= FILE_SHARE_READ
;
66 disposition
= OPEN_EXISTING
;
75 access
|= GENERIC_WRITE
;
77 disposition
= oflag
& O_CREAT
? CREATE_ALWAYS
: TRUNCATE_EXISTING
;
79 else if (oflag
& O_CREAT
)
81 access
|= GENERIC_WRITE
;
83 disposition
= CREATE_NEW
;
85 else if (oflag
& O_EXCL
)
87 access
|= GENERIC_WRITE
;
89 disposition
= TRUNCATE_EXISTING
;
93 HANDLE fileHandle
= ::CreateFile(filename
, access
, shareMode
, NULL
,
94 disposition
, FILE_ATTRIBUTE_NORMAL
, 0);
95 if (fileHandle
== INVALID_HANDLE_VALUE
)
98 fd
= (int) fileHandle
;
103 int wxCRT_Access(const wxChar
*name
, int WXUNUSED(how
))
105 HANDLE fileHandle
= ::CreateFile(name
, 0, FILE_SHARE_DELETE
| FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
106 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0);
108 if (fileHandle
== INVALID_HANDLE_VALUE
)
111 CloseHandle(fileHandle
);
118 if (CloseHandle((HANDLE
)fd
))
125 DWORD off0
= SetFilePointer((HANDLE
) fd
, 0, NULL
, FILE_CURRENT
);
126 if (off0
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
129 DWORD off1
= SetFilePointer((HANDLE
) fd
, 0, NULL
, FILE_END
);
130 if (off1
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
137 SetFilePointer((HANDLE
) fd
, off0
, NULL
, FILE_BEGIN
);
142 int wxRead(int fd
, void *buf
, unsigned int count
)
146 if (ReadFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesRead
, NULL
))
152 int wxWrite(int fd
, const void *buf
, unsigned int count
)
154 DWORD bytesWritten
= 0;
156 if (WriteFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesWritten
, NULL
))
162 __int64
wxSeek(int fd
, __int64 offset
, int origin
)
167 wxFAIL_MSG(_("unknown seek origin"));
174 method
= FILE_CURRENT
;
182 DWORD res
= SetFilePointer((HANDLE
) fd
, offset
, NULL
, method
) ;
183 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
185 wxLogSysError(_("can't seek on file descriptor %d"), fd
);
186 return wxInvalidOffset
;
192 __int64
wxTell(int fd
)
194 // WinCE apparently doesn't support lpDistanceToMoveHigh.
196 DWORD res
= SetFilePointer((HANDLE
) fd
, 0, NULL
, FILE_CURRENT
) ;
197 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
199 wxLogSysError(_("can't get seek position on file descriptor %d"), fd
);
200 return wxInvalidOffset
;
203 return res
; // + (((__int64)high) << 32);
206 int wxFsync(int WXUNUSED(fd
))