diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2002-06-18 13:01:26 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2002-06-18 13:01:26 +0000 |
commit | 51e7c409ef46a0800e82966b188869558d070e08 (patch) | |
tree | 0711804b65382c2754859462e31fce12430eaf61 /otherlibs/win32unix | |
parent | dde21583f7f0d760ee02c3e70eb297e218e0d586 (diff) |
Reecrit en pur Win32, on court-circuite la lib C
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4931 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/win32unix')
-rw-r--r-- | otherlibs/win32unix/windir.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/otherlibs/win32unix/windir.c b/otherlibs/win32unix/windir.c index cdd99d8e6..13a7edec3 100644 --- a/otherlibs/win32unix/windir.c +++ b/otherlibs/win32unix/windir.c @@ -2,7 +2,7 @@ /* */ /* Objective Caml */ /* */ -/* Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */ /* */ /* Copyright 1996 Institut National de Recherche en Informatique et */ /* en Automatique. All rights reserved. This file is distributed */ @@ -23,23 +23,28 @@ CAMLprim value win_findfirst(name) value name; { - int h; + HANDLE h; value v; - struct _finddata_t fileinfo; + WIN32_FIND_DATA fileinfo; value valname = Val_unit; + value valh = Val_unit; - Begin_root (valname); - h = _findfirst(String_val(name),&fileinfo); - if (h == -1) { - if (errno == ENOENT) + Begin_roots2 (valname,valh); + h = FindFirstFile(String_val(name),&fileinfo); + if (h == INVALID_HANDLE_VALUE) { + DWORD err = GetLastError(); + if (err == ERROR_NO_MORE_FILES) raise_end_of_file(); - else + else { + win32_maperr(err); uerror("opendir", Nothing); + } } - valname = copy_string(fileinfo.name); + valname = copy_string(fileinfo.cFileName); + valh = win_alloc_handle(h); v = alloc_small(2, 0); Field(v,0) = valname; - Field(v,1) = Val_int(h); + Field(v,1) = valh; End_roots(); return v; } @@ -47,18 +52,29 @@ CAMLprim value win_findfirst(name) CAMLprim value win_findnext(valh) value valh; { - int retcode; - struct _finddata_t fileinfo; + WIN32_FIND_DATA fileinfo; + BOOL retcode; - retcode = _findnext(Int_val(valh), &fileinfo); - if (retcode != 0) raise_end_of_file(); - return copy_string(fileinfo.name); + retcode = FindNextFile(Handle_val(valh), &fileinfo); + if (!retcode) { + DWORD err = GetLastError(); + if (err == ERROR_NO_MORE_FILES) + raise_end_of_file(); + else { + win32_maperr(err); + uerror("readdir", Nothing); + } + } + return copy_string(fileinfo.cFileName); } CAMLprim value win_findclose(valh) value valh; { - if (_findclose(Int_val(valh)) != 0) uerror("closedir", Nothing); + if (! FindClose(Handle_val(valh))) { + win32_maperr(GetLastError()); + uerror("closedir", Nothing); + } return Val_unit; } |