1996-09-04 07:17:43 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
2011-07-27 07:17:02 -07:00
|
|
|
/* OCaml */
|
1996-09-04 07:17:43 -07:00
|
|
|
/* */
|
2002-06-18 06:01:26 -07:00
|
|
|
/* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
1996-09-04 07:17:43 -07:00
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1996-09-04 07:17:43 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <memory.h>
|
1996-09-05 06:32:25 -07:00
|
|
|
#include <errno.h>
|
1996-09-04 07:17:43 -07:00
|
|
|
#include <alloc.h>
|
2002-06-07 02:49:45 -07:00
|
|
|
#include <fail.h>
|
1996-09-04 07:17:43 -07:00
|
|
|
#include "unixsupport.h"
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value win_findfirst(name)
|
1996-09-04 07:17:43 -07:00
|
|
|
value name;
|
|
|
|
{
|
2002-06-18 06:01:26 -07:00
|
|
|
HANDLE h;
|
1996-09-04 07:17:43 -07:00
|
|
|
value v;
|
2002-06-18 06:01:26 -07:00
|
|
|
WIN32_FIND_DATA fileinfo;
|
1997-05-26 10:16:31 -07:00
|
|
|
value valname = Val_unit;
|
2002-06-18 06:01:26 -07:00
|
|
|
value valh = Val_unit;
|
1997-05-26 10:16:31 -07:00
|
|
|
|
2002-06-18 06:01:26 -07:00
|
|
|
Begin_roots2 (valname,valh);
|
|
|
|
h = FindFirstFile(String_val(name),&fileinfo);
|
|
|
|
if (h == INVALID_HANDLE_VALUE) {
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
if (err == ERROR_NO_MORE_FILES)
|
1997-05-26 10:16:31 -07:00
|
|
|
raise_end_of_file();
|
2002-06-18 06:01:26 -07:00
|
|
|
else {
|
2002-07-23 07:12:03 -07:00
|
|
|
win32_maperr(err);
|
1997-05-26 10:16:31 -07:00
|
|
|
uerror("opendir", Nothing);
|
2002-06-18 06:01:26 -07:00
|
|
|
}
|
1997-05-26 10:16:31 -07:00
|
|
|
}
|
2002-06-18 06:01:26 -07:00
|
|
|
valname = copy_string(fileinfo.cFileName);
|
|
|
|
valh = win_alloc_handle(h);
|
1998-10-26 11:19:32 -08:00
|
|
|
v = alloc_small(2, 0);
|
1997-05-26 10:16:31 -07:00
|
|
|
Field(v,0) = valname;
|
2002-06-18 06:01:26 -07:00
|
|
|
Field(v,1) = valh;
|
1997-05-26 10:16:31 -07:00
|
|
|
End_roots();
|
1996-09-04 07:17:43 -07:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value win_findnext(valh)
|
1996-09-04 07:17:43 -07:00
|
|
|
value valh;
|
|
|
|
{
|
2002-06-18 06:01:26 -07:00
|
|
|
WIN32_FIND_DATA fileinfo;
|
|
|
|
BOOL retcode;
|
1996-09-04 07:17:43 -07:00
|
|
|
|
2002-06-18 06:01:26 -07:00
|
|
|
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);
|
1997-05-19 08:42:21 -07:00
|
|
|
}
|
1996-09-04 07:17:43 -07:00
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value win_findclose(valh)
|
1997-05-19 08:42:21 -07:00
|
|
|
value valh;
|
1996-09-04 07:17:43 -07:00
|
|
|
{
|
2002-06-18 06:01:26 -07:00
|
|
|
if (! FindClose(Handle_val(valh))) {
|
|
|
|
win32_maperr(GetLastError());
|
|
|
|
uerror("closedir", Nothing);
|
|
|
|
}
|
1996-09-04 07:17:43 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|