- int flags = O_BINARY;
-
- switch ( mode ) {
- case read:
- flags |= O_RDONLY;
- break;
-
- case write:
- flags |= O_WRONLY | O_CREAT | O_TRUNC;
- break;
-
- case write_append:
- flags |= O_WRONLY | O_APPEND;
- break;
-
- case read_write:
- flags |= O_RDWR;
- break;
- }
-
- int fd = open(szFileName, flags, access);
-
- if ( fd == -1 ) {
- wxLogSysError("can't open file '%s'", szFileName);
- return FALSE;
- }
- else {
- Attach(fd);
- return TRUE;
- }
+#ifdef __WXWINCE__
+ DWORD access = 0;
+ DWORD shareMode = 0;
+ DWORD disposition = 0;
+
+ int flags = O_BINARY;
+
+ switch ( mode )
+ {
+ case read:
+ access = GENERIC_READ;
+ shareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
+ disposition = OPEN_EXISTING;
+ break;
+
+ case write_append:
+ if ( wxFile::Exists(szFileName) )
+ {
+ access = GENERIC_READ|GENERIC_WRITE;
+ shareMode = FILE_SHARE_READ;
+ disposition = 0;
+ break;
+ }
+ //else: fall through as write_append is the same as write if the
+ // file doesn't exist
+
+ case write:
+ access = GENERIC_WRITE;
+ shareMode = 0;
+ disposition = TRUNCATE_EXISTING;
+ break;
+
+ case write_excl:
+ access = GENERIC_WRITE;
+ shareMode = 0;
+ disposition = TRUNCATE_EXISTING;
+ break;
+
+ case read_write:
+ access = GENERIC_READ|GENERIC_WRITE;
+ shareMode = 0;
+ disposition = 0;
+ break;
+ }
+
+ int fd = 0;
+ HANDLE fileHandle = ::CreateFile(szFileName, access, shareMode, NULL,
+ disposition, FILE_ATTRIBUTE_NORMAL, 0);
+ if (fileHandle == INVALID_HANDLE_VALUE)
+ fd = -1;
+ else
+ fd = (int) fileHandle;
+#else
+ int flags = O_BINARY;
+
+ switch ( mode )
+ {
+ case read:
+ flags |= O_RDONLY;
+ break;
+
+ case write_append:
+ if ( wxFile::Exists(szFileName) )
+ {
+ flags |= O_WRONLY | O_APPEND;
+ break;
+ }
+ //else: fall through as write_append is the same as write if the
+ // file doesn't exist
+
+ case write:
+ flags |= O_WRONLY | O_CREAT | O_TRUNC;
+ break;
+
+ case write_excl:
+ flags |= O_WRONLY | O_CREAT | O_EXCL;
+ break;
+
+ case read_write:
+ flags |= O_RDWR;
+ break;
+ }
+
+ int fd = wxOpen( szFileName, flags ACCESS(accessMode));
+#endif
+ if ( fd == -1 )
+ {
+ wxLogSysError(_("can't open file '%s'"), szFileName);
+ return FALSE;
+ }
+ else {
+ Attach(fd);
+ return TRUE;
+ }