]>
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
);
115 int wxCRT_Chmod(const wxChar
*WXUNUSED(name
), int WXUNUSED(how
))
123 if (CloseHandle((HANDLE
)fd
))
130 DWORD off0
= SetFilePointer((HANDLE
) fd
, 0, NULL
, FILE_CURRENT
);
131 if (off0
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
134 DWORD off1
= SetFilePointer((HANDLE
) fd
, 0, NULL
, FILE_END
);
135 if (off1
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
142 SetFilePointer((HANDLE
) fd
, off0
, NULL
, FILE_BEGIN
);
147 int wxRead(int fd
, void *buf
, unsigned int count
)
151 if (ReadFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesRead
, NULL
))
157 int wxWrite(int fd
, const void *buf
, unsigned int count
)
159 DWORD bytesWritten
= 0;
161 if (WriteFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesWritten
, NULL
))
167 __int64
wxSeek(int fd
, __int64 offset
, int origin
)
172 wxFAIL_MSG(_("unknown seek origin"));
179 method
= FILE_CURRENT
;
187 DWORD res
= SetFilePointer((HANDLE
) fd
, offset
, NULL
, method
) ;
188 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
190 wxLogSysError(_("can't seek on file descriptor %d"), fd
);
191 return wxInvalidOffset
;
197 __int64
wxTell(int fd
)
199 // WinCE apparently doesn't support lpDistanceToMoveHigh.
201 DWORD res
= SetFilePointer((HANDLE
) fd
, 0, NULL
, FILE_CURRENT
) ;
202 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
204 wxLogSysError(_("can't get seek position on file descriptor %d"), fd
);
205 return wxInvalidOffset
;
208 return res
; // + (((__int64)high) << 32);
211 int wxFsync(int WXUNUSED(fd
))