diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-06-29 11:47:07 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-06-29 11:47:07 +0100 |
commit | 826020fe18bf2eee43f8afea392874bb88c0650a (patch) | |
tree | 7c6c40758611605be29b3528da647a78a071ea1b /ocaml | |
parent | 3854bbdecd1c089959fb812a739b84a96c05fbbf (diff) | |
download | libguestfs-826020fe18bf2eee43f8afea392874bb88c0650a.tar.gz libguestfs-826020fe18bf2eee43f8afea392874bb88c0650a.tar.xz libguestfs-826020fe18bf2eee43f8afea392874bb88c0650a.zip |
Generated code for head/tail commands.
Diffstat (limited to 'ocaml')
-rw-r--r-- | ocaml/guestfs.ml | 4 | ||||
-rw-r--r-- | ocaml/guestfs.mli | 12 | ||||
-rw-r--r-- | ocaml/guestfs_c_actions.c | 114 |
3 files changed, 126 insertions, 4 deletions
diff --git a/ocaml/guestfs.ml b/ocaml/guestfs.ml index b84504e7..c631024b 100644 --- a/ocaml/guestfs.ml +++ b/ocaml/guestfs.ml @@ -287,3 +287,7 @@ external mkdtemp : t -> string -> string = "ocaml_guestfs_mkdtemp" external wc_l : t -> string -> int = "ocaml_guestfs_wc_l" external wc_w : t -> string -> int = "ocaml_guestfs_wc_w" external wc_c : t -> string -> int = "ocaml_guestfs_wc_c" +external head : t -> string -> string array = "ocaml_guestfs_head" +external head_n : t -> int -> string -> string array = "ocaml_guestfs_head_n" +external tail : t -> string -> string array = "ocaml_guestfs_tail" +external tail_n : t -> int -> string -> string array = "ocaml_guestfs_tail_n" diff --git a/ocaml/guestfs.mli b/ocaml/guestfs.mli index 4c1ef721..97180b0d 100644 --- a/ocaml/guestfs.mli +++ b/ocaml/guestfs.mli @@ -640,3 +640,15 @@ val wc_w : t -> string -> int val wc_c : t -> string -> int (** count characters in a file *) +val head : t -> string -> string array +(** return first 10 lines of a file *) + +val head_n : t -> int -> string -> string array +(** return first N lines of a file *) + +val tail : t -> string -> string array +(** return last 10 lines of a file *) + +val tail_n : t -> int -> string -> string array +(** return last N lines of a file *) + diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c index beb41d77..d8b05677 100644 --- a/ocaml/guestfs_c_actions.c +++ b/ocaml/guestfs_c_actions.c @@ -3901,9 +3901,9 @@ ocaml_guestfs_pvresize (value gv, value devicev) } CAMLprim value -ocaml_guestfs_sfdisk_N (value gv, value devicev, value nv, value cylsv, value headsv, value sectorsv, value linev) +ocaml_guestfs_sfdisk_N (value gv, value devicev, value partnumv, value cylsv, value headsv, value sectorsv, value linev) { - CAMLparam5 (gv, devicev, nv, cylsv, headsv); + CAMLparam5 (gv, devicev, partnumv, cylsv, headsv); CAMLxparam2 (sectorsv, linev); CAMLlocal1 (rv); @@ -3912,7 +3912,7 @@ ocaml_guestfs_sfdisk_N (value gv, value devicev, value nv, value cylsv, value he caml_failwith ("sfdisk_N: used handle after closing it"); const char *device = String_val (devicev); - int n = Int_val (nv); + int partnum = Int_val (partnumv); int cyls = Int_val (cylsv); int heads = Int_val (headsv); int sectors = Int_val (sectorsv); @@ -3920,7 +3920,7 @@ ocaml_guestfs_sfdisk_N (value gv, value devicev, value nv, value cylsv, value he int r; caml_enter_blocking_section (); - r = guestfs_sfdisk_N (g, device, n, cyls, heads, sectors, line); + r = guestfs_sfdisk_N (g, device, partnum, cyls, heads, sectors, line); caml_leave_blocking_section (); if (r == -1) ocaml_guestfs_raise_error (g, "sfdisk_N"); @@ -4436,3 +4436,109 @@ ocaml_guestfs_wc_c (value gv, value pathv) CAMLreturn (rv); } +CAMLprim value +ocaml_guestfs_head (value gv, value pathv) +{ + CAMLparam2 (gv, pathv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("head: used handle after closing it"); + + const char *path = String_val (pathv); + int i; + char **r; + + caml_enter_blocking_section (); + r = guestfs_head (g, path); + caml_leave_blocking_section (); + if (r == NULL) + ocaml_guestfs_raise_error (g, "head"); + + rv = caml_copy_string_array ((const char **) r); + for (i = 0; r[i] != NULL; ++i) free (r[i]); + free (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_head_n (value gv, value nrlinesv, value pathv) +{ + CAMLparam3 (gv, nrlinesv, pathv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("head_n: used handle after closing it"); + + int nrlines = Int_val (nrlinesv); + const char *path = String_val (pathv); + int i; + char **r; + + caml_enter_blocking_section (); + r = guestfs_head_n (g, nrlines, path); + caml_leave_blocking_section (); + if (r == NULL) + ocaml_guestfs_raise_error (g, "head_n"); + + rv = caml_copy_string_array ((const char **) r); + for (i = 0; r[i] != NULL; ++i) free (r[i]); + free (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_tail (value gv, value pathv) +{ + CAMLparam2 (gv, pathv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("tail: used handle after closing it"); + + const char *path = String_val (pathv); + int i; + char **r; + + caml_enter_blocking_section (); + r = guestfs_tail (g, path); + caml_leave_blocking_section (); + if (r == NULL) + ocaml_guestfs_raise_error (g, "tail"); + + rv = caml_copy_string_array ((const char **) r); + for (i = 0; r[i] != NULL; ++i) free (r[i]); + free (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_tail_n (value gv, value nrlinesv, value pathv) +{ + CAMLparam3 (gv, nrlinesv, pathv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("tail_n: used handle after closing it"); + + int nrlines = Int_val (nrlinesv); + const char *path = String_val (pathv); + int i; + char **r; + + caml_enter_blocking_section (); + r = guestfs_tail_n (g, nrlines, path); + caml_leave_blocking_section (); + if (r == NULL) + ocaml_guestfs_raise_error (g, "tail_n"); + + rv = caml_copy_string_array ((const char **) r); + for (i = 0; r[i] != NULL; ++i) free (r[i]); + free (r); + CAMLreturn (rv); +} + |