]>
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
))
126 DWORD off0
= SetFilePointer((HANDLE
) fd
, 0, &high0
, FILE_CURRENT
);
127 if (off0
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
131 DWORD off1
= SetFilePointer((HANDLE
) fd
, 0, &high0
, FILE_END
);
132 if (off1
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
135 if (off0
== off1
&& high0
== high1
)
139 SetFilePointer((HANDLE
) fd
, off0
, &high0
, FILE_BEGIN
);
144 int wxRead(int fd
, void *buf
, unsigned int count
)
148 if (ReadFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesRead
, NULL
))
154 int wxWrite(int fd
, const void *buf
, unsigned int count
)
156 DWORD bytesWritten
= 0;
158 if (WriteFile((HANDLE
) fd
, buf
, (DWORD
) count
, &bytesWritten
, NULL
))
164 __int64
wxSeek(int fd
, __int64 offset
, int origin
)
169 wxFAIL_MSG(_("unknown seek origin"));
176 method
= FILE_CURRENT
;
185 DWORD res
= SetFilePointer((HANDLE
) fd
, offset
, &high
, method
) ;
186 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
188 wxLogSysError(_("can't seek on file descriptor %d"), fd
);
189 return wxInvalidOffset
;
195 __int64
wxTell(int fd
)
198 DWORD res
= SetFilePointer((HANDLE
) fd
, 0, &high
, FILE_CURRENT
) ;
199 if (res
== 0xFFFFFFFF && GetLastError() != NO_ERROR
)
201 wxLogSysError(_("can't get seek position on file descriptor %d"), fd
);
202 return wxInvalidOffset
;
205 return res
+ (((__int64
)high
) << 32);
208 int wxFsync(int WXUNUSED(fd
))