summaryrefslogtreecommitdiffstats
path: root/otherlibs/win32unix/open.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>1997-09-03 14:38:02 +0000
committerXavier Leroy <xavier.leroy@inria.fr>1997-09-03 14:38:02 +0000
commit1e664b94467a65841e63d2dea50cd1f64e8a3258 (patch)
tree377f874869769eb40984803bcc6b6648a06b68e4 /otherlibs/win32unix/open.c
parent47745356d34649ee4c531fea679e3a008cf90197 (diff)
Implementation du type file_descr par le type HANDLE de Win32. Court-circuite la libc de MSVC.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1700 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/win32unix/open.c')
-rw-r--r--otherlibs/win32unix/open.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/otherlibs/win32unix/open.c b/otherlibs/win32unix/open.c
index 248e7018b..63e370392 100644
--- a/otherlibs/win32unix/open.c
+++ b/otherlibs/win32unix/open.c
@@ -16,22 +16,37 @@
#include "unixsupport.h"
#include <fcntl.h>
-static int open_flag_table[] = {
- O_RDONLY, O_WRONLY, O_RDWR, 0, O_APPEND, O_CREAT, O_TRUNC, O_EXCL, 0, 0
+static int open_access_flags[10] = {
+ GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE, 0, 0, 0, 0, 0, 0, 0
};
-static int open_text_flag_table[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
+static int open_create_flags[10] = {
+ 0, 0, 0, 0, 0, O_CREAT, O_TRUNC, O_EXCL, 0, 0
};
-value unix_open(path, flags, perm) /* ML */
- value path, flags, perm;
+value unix_open(value path, value flags, value perm) /* ML */
{
- int fl, ret;
+ int fileaccess, createflags, fileattrib;
+ HANDLE h;
- fl = convert_flag_list(flags, open_flag_table);
- if (convert_flag_list(flags, open_text_flag_table) == 0) fl |= O_BINARY;
- ret = open(String_val(path), fl, Int_val(perm));
- if (ret == -1) uerror("open", path);
- return Val_int(ret);
+ fileaccess = convert_flag_list(flags, open_access_flags);
+ createflags = convert_flag_list(flags, open_create_flags);
+ if ((createflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
+ filecreate = CREATE_NEW;
+ else if ((createflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC))
+ filecreate = CREATE_ALWAYS;
+ else if (createflags & O_TRUNC)
+ filecreate = TRUNCATE_EXISTING;
+ else if (createflags & O_CREAT)
+ filecreate = OPEN_ALWAYS;
+ else
+ filecreate = OPEN_EXISTING;
+ if ((createflags & O_CREAT) && (Int_val(perm) & 0200) == 0)
+ fileattrib = FILE_ATTRIBUTE_READONLY;
+ else
+ fileattrib = FILE_ATTRIBUTE_NORMAL;
+ h = CreateFile(String_val(path), fileaccess, 0, NULL,
+ filecreate, fileattrib, NULL);
+ if (h == INVALID_HANDLE_VALUE) uerror("open", path);
+ return win_alloc_handle(h);
}