add -fPIC option to the C compiler, required in f31
[vsys.git] / ocaml_inotify-0.4 / test.inotify.ml
1 (* unit testing inotify *)
2
3 open Printf
4
5 let _ =
6         if Array.length Sys.argv < 2 then (
7                 eprintf "usage: %s <path>\n" Sys.argv.(0);
8                 exit 1
9         );
10
11         let fd = Inotify.init () in
12         ignore (Inotify.add_watch fd Sys.argv.(1) [ Inotify.S_Create ]);
13
14         let string_of_event ev =
15                 let wd,mask,cookie,s = ev in
16                 let mask = String.concat ":" (List.map Inotify.string_of_event mask) in
17                 let s = match s with Some s -> s | None -> "\"\"" in
18                 sprintf "wd [%u] mask[%s] cookie[%ld] %s" (Inotify.int_of_wd wd)
19                                                           mask cookie s
20                 in
21
22         let nb = ref 0 in
23         while true
24         do
25                 let _, _, _ = Unix.select [ fd ] [] [] (-1.) in
26                 let evs = Inotify.read fd in
27                 List.iter (fun ev ->
28                         printf "[%d] %s\n%!" !nb (string_of_event ev)) evs;
29                 incr nb
30         done;
31
32         Unix.close fd