]>
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 wxOpen(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
; 
  53     else if ((oflag 
& (O_RDONLY 
| O_WRONLY 
| O_RDWR
)) == O_RDWR
) 
  55         access 
= GENERIC_READ
|GENERIC_WRITE
; 
  59         if ( wxFile::Exists(filename
) ) 
  61             access 
|= GENERIC_WRITE
; 
  62             shareMode 
= FILE_SHARE_READ
; 
  63             disposition 
= OPEN_EXISTING
; 
  65         //else: fall through as write_append is the same as write if the 
  72         access 
|= GENERIC_WRITE
; 
  74         disposition 
= (oflag 
& O_CREAT
) ? CREATE_ALWAYS 
: TRUNCATE_EXISTING
; 
  76     else if (oflag 
& O_CREAT
) 
  78         access 
|= GENERIC_WRITE
; 
  80         disposition 
= CREATE_NEW
; 
  82     else if (oflag 
& O_EXCL
) 
  84         access 
|= GENERIC_WRITE
; 
  86         disposition 
= TRUNCATE_EXISTING
; 
  90     HANDLE fileHandle 
= ::CreateFile(filename
, access
, shareMode
, NULL
, 
  91         disposition
, FILE_ATTRIBUTE_NORMAL
, 0); 
  92     if (fileHandle 
== INVALID_HANDLE_VALUE
) 
  95         fd 
= (int) fileHandle
; 
 100 int wxAccess(const wxChar 
*name
, int WXUNUSED(how
)) 
 102     HANDLE fileHandle 
= ::CreateFile(name
, 0, FILE_SHARE_DELETE 
| FILE_SHARE_READ 
| FILE_SHARE_WRITE
, NULL
, 
 103         OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0); 
 105     if (fileHandle 
== INVALID_HANDLE_VALUE
) 
 108     CloseHandle(fileHandle
); 
 115     if (CloseHandle((HANDLE
)fd
)) 
 123     DWORD off0 
= SetFilePointer((HANDLE
) fd
, 0, &high0
, FILE_CURRENT
); 
 124     if (off0 
== 0xFFFFFFFF && GetLastError() != NO_ERROR
) 
 128     DWORD off1 
= SetFilePointer((HANDLE
) fd
, 0, &high0
, FILE_END
); 
 129     if (off1 
== 0xFFFFFFFF && GetLastError() != NO_ERROR
) 
 132     if (off0 
== off1 
&& high0 
== high1
) 
 136         SetFilePointer((HANDLE
) fd
, off0
, &high0
, 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
; 
 182     DWORD res 
= SetFilePointer((HANDLE
) fd
, offset
, &high
, 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
) 
 195     DWORD res 
= SetFilePointer((HANDLE
) fd
, 0, &high
, 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
))