]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/wince/filefnwce.cpp
1 /////////////////////////////////////////////////////////////////////////////
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "filefn.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
39 #include "wx/msw/wince/missing.h"
41 int wxOpen(const wxChar
*filename
, int oflag
, int WXUNUSED(pmode
))
45 DWORD disposition
= 0;
47 if ((oflag
& (O_RDONLY
| O_WRONLY
| O_RDWR
)) == O_RDONLY
)
49 access
= GENERIC_READ
;
50 shareMode
= FILE_SHARE_READ
|FILE_SHARE_WRITE
;
51 disposition
|= OPEN_EXISTING
;
53 else if ((oflag
& (O_RDONLY
| O_WRONLY
| O_RDWR
)) == O_WRONLY
)
55 access
= GENERIC_WRITE
;
57 else if ((oflag
& (O_RDONLY
| O_WRONLY
| O_RDWR
)) == O_RDWR
)
59 access
= GENERIC_READ
|GENERIC_WRITE
;
63 if ( wxFile::Exists(filename
) )
65 access
|= GENERIC_WRITE
;
66 shareMode
= FILE_SHARE_READ
;
67 disposition
= OPEN_EXISTING
;
69 //else: fall through as write_append is the same as write if the
76 access
|= GENERIC_WRITE
;
78 disposition
= (oflag
& O_CREAT
) ? CREATE_ALWAYS
: TRUNCATE_EXISTING
;
80 else if (oflag
& O_CREAT
)
82 access
|= GENERIC_WRITE
;
84 disposition
= CREATE_NEW
;
86 else if (oflag
& O_EXCL
)
88 access
|= GENERIC_WRITE
;
90 disposition
= TRUNCATE_EXISTING
;
94 HANDLE fileHandle
= ::CreateFile(filename
, access
, shareMode
, NULL
,
95 disposition
, FILE_ATTRIBUTE_NORMAL
, 0);
96 if (fileHandle
== INVALID_HANDLE_VALUE
)
99 fd
= (int) fileHandle
;
104 int wxAccess(const wxChar
*name
, int WXUNUSED(how
))
106 HANDLE fileHandle
= ::CreateFile(name
, 0, FILE_SHARE_DELETE
| FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
107 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0);
109 if (fileHandle
== INVALID_HANDLE_VALUE
)
112 CloseHandle(fileHandle
);
119 if (CloseHandle((HANDLE
)fd
))
127 DWORD off0
= SetFilePointer((HANDLE
) fd
, 0, &high0
, FILE_CURRENT
);
128 if (off0
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
132 DWORD off1
= SetFilePointer((HANDLE
) fd
, 0, &high0
, FILE_END
);
133 if (off1
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
136 if (off0
== off1
&& high0
== high1
)
140 SetFilePointer((HANDLE
) fd
, off0
, &high0
, FILE_BEGIN
);
145 int wxRead(int fd
, void *buf
, unsigned int count
)
149 if (ReadFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesRead
, NULL
))
155 int wxWrite(int fd
, const void *buf
, unsigned int count
)
157 DWORD bytesWritten
= 0;
159 if (WriteFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesWritten
, NULL
))
165 __int64
wxSeek(int fd
, __int64 offset
, int origin
)
170 wxFAIL_MSG(_("unknown seek origin"));
177 method
= FILE_CURRENT
;
186 DWORD res
= SetFilePointer((HANDLE
) fd
, offset
, &high
, method
) ;
187 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
189 wxLogSysError(_("can't seek on file descriptor %d"), fd
);
190 return wxInvalidOffset
;
196 __int64
wxTell(int fd
)
199 DWORD res
= SetFilePointer((HANDLE
) fd
, 0, &high
, FILE_CURRENT
) ;
200 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
202 wxLogSysError(_("can't get seek position on file descriptor %d"), fd
);
203 return wxInvalidOffset
;
206 return res
+ (((__int64
)high
) << 32);
209 int wxFsync(int WXUNUSED(fd
))