Add test target for figfs_test.
[figfs.git] / fuse / Unix_util_stubs.c
blob13afaf95832bc8886206215dd8dd7b161b83f3ee
1 /*
2 This file is part of the "OCamlFuse" library.
4 OCamlFuse is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation (version 2 of the License).
8 OCamlFuse is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with OCamlFuse. See the file LICENSE. If you haven't received
15 a copy of the GNU General Public License, write to:
17 Free Software Foundation, Inc.,
18 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA
21 Vincenzo Ciancia
23 applejack@users.sf.net
24 vincenzo_ml@yahoo.it
27 #include <stddef.h>
28 #include <string.h>
29 #include <caml/mlvalues.h>
30 #include <caml/memory.h>
31 #include <caml/alloc.h>
32 #include <caml/fail.h>
33 #include <caml/callback.h>
34 #ifdef Custom_tag
35 #include <caml/custom.h>
36 #include <caml/bigarray.h>
37 #endif
38 #include <caml/camlidlruntime.h>
40 int c2ml_unix_error(int c_err);
42 value unix_util_read(value fd,value buf)
44 value vres=alloc(1,1); /* Ok result */
45 int res;
46 enter_blocking_section();
47 res = read(Int_val(fd), /* TODO: unsafe coercion */
48 Bigarray_val(buf)->data,Bigarray_val(buf)->dim[0]);
49 leave_blocking_section();
50 if (res >=0) Field(vres,0)=Val_int(res);
51 else
53 Tag_val(vres)=0; /* Bad result */
54 Field(vres,0)=Val_int(c2ml_unix_error(res)); /* TODO: EUNKNOWN x is a block */
56 return vres;
59 value unix_util_write(value fd,value buf)
61 value vres=alloc(1,1); /* Ok result */
62 int res;
63 enter_blocking_section();
64 res = write(Int_val(fd), /* TODO: unsafe coercion */
65 Bigarray_val(buf)->data,Bigarray_val(buf)->dim[0]);
66 leave_blocking_section();
67 if (res >=0) Field(vres,0)=Val_int(res);
68 else
70 Tag_val(vres)=0; /* Bad result */
71 Field(vres,0)=Val_int(c2ml_unix_error(res)); /* TODO: EUNKNOWN x is a block */
73 return vres;
76 value unix_util_int_of_file_descr(value fd)
78 return Val_int(Int_val(fd) /* TODO: unsafe coercion */ );
81 value unix_util_file_descr_of_int(value fd)
83 return Val_int(Int_val(fd) /* TODO: unsafe coercion */ );