psss / rpms / libguestfs

Forked from rpms/libguestfs 5 years ago
Clone
Blob Blame History Raw
From 8421edcf024f7328da721a8ac52f349290ed5714 Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <rjones@redhat.com>
Date: Sat, 9 Mar 2013 19:25:33 +0000
Subject: [PATCH 36/36] EPEL 5: Custom replacement for 'Unix.isatty stdout'.

Unix.isatty missing on RHEL 5-era OCaml.
---
 resize/progress-c.c |   10 ++++++++++
 resize/progress.ml  |    3 ++-
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/resize/progress-c.c b/resize/progress-c.c
index 2f25bbc..2813d0c 100644
--- a/resize/progress-c.c
+++ b/resize/progress-c.c
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
+#include <unistd.h>
 #include <locale.h>
 
 #include <caml/alloc.h>
@@ -103,3 +104,12 @@ virt_resize_progress_bar_set (value barv,
 
   CAMLreturn (Val_unit);
 }
+
+/* RHEL 5-era ocaml didn't have Unix.isatty. */
+value
+virt_resize_isatty_stdout (value unitv)
+{
+  CAMLparam1 (unitv);
+
+  CAMLreturn (isatty(1) ? Val_true : Val_false);
+}
diff --git a/resize/progress.ml b/resize/progress.ml
index 7a94c6c..1ff73c2 100644
--- a/resize/progress.ml
+++ b/resize/progress.ml
@@ -28,12 +28,13 @@ external progress_bar_reset : progress_bar -> unit
   = "virt_resize_progress_bar_reset"
 external progress_bar_set : progress_bar -> int64 -> int64 -> unit
   = "virt_resize_progress_bar_set"
+external isatty_stdout : unit -> bool = "virt_resize_isatty_stdout"
 
 let set_up_progress_bar ?(machine_readable = false) (g : Guestfs.guestfs) =
   (* Only display progress bars if the machine_readable flag is set or
    * the output is a tty.
    *)
-  if machine_readable || isatty stdout then (
+  if machine_readable || isatty_stdout () then (
     (* Initialize the C mini library. *)
     let bar = progress_bar_init ~machine_readable in
 
-- 
1.7.4.1