summaryrefslogtreecommitdiffstats
path: root/otherlibs/win32unix/windir.c
blob: cdd99d8e6d44d1c72fae7e8811aee94bbaaf2dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/***********************************************************************/
/*                                                                     */
/*                           Objective Caml                            */
/*                                                                     */
/*             Pascal Cuoq, projet Cristal, INRIA Rocquencourt         */
/*                                                                     */
/*  Copyright 1996 Institut National de Recherche en Informatique et   */
/*  en Automatique.  All rights reserved.  This file is distributed    */
/*  under the terms of the GNU Library General Public License, with    */
/*  the special exception on linking described in file ../../LICENSE.  */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

#include <mlvalues.h>
#include <memory.h>
#include <errno.h>
#include <alloc.h>
#include <fail.h>
#include "unixsupport.h"

CAMLprim value win_findfirst(name)
     value name;
{
  int h;
  value v;
  struct _finddata_t fileinfo;
  value valname = Val_unit;

  Begin_root (valname);
    h = _findfirst(String_val(name),&fileinfo);
    if (h == -1) {
      if (errno == ENOENT)
        raise_end_of_file();
      else
        uerror("opendir", Nothing);
    }
    valname = copy_string(fileinfo.name);
    v = alloc_small(2, 0);
    Field(v,0) = valname;
    Field(v,1) = Val_int(h);
  End_roots();
  return v;
}

CAMLprim value win_findnext(valh)
     value valh;
{
  int retcode;
  struct _finddata_t fileinfo;

  retcode = _findnext(Int_val(valh), &fileinfo);
  if (retcode != 0) raise_end_of_file();
  return copy_string(fileinfo.name);
}

CAMLprim value win_findclose(valh)
     value valh;
{
  if (_findclose(Int_val(valh)) != 0) uerror("closedir", Nothing);
  return Val_unit;
}