From 02eb2bb9cd33f08e542ed22175dcf8388cad5b79 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Move C string truncation function to general utils module. --- lib/virt_mem_utils.ml | 10 ++++++++++ lib/virt_mem_utsname.ml | 20 +++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/virt_mem_utils.ml b/lib/virt_mem_utils.ml index 0a3b687..a1eab8f 100644 --- a/lib/virt_mem_utils.ml +++ b/lib/virt_mem_utils.ml @@ -117,6 +117,16 @@ let pad width str = if n >= width then str else (* if n < width then *) str ^ String.make (width-n) ' ' +(* Truncate an OCaml string at the first ASCII NUL character, ie. as + * if it were a C string. + *) +let truncate_c_string str = + try + let i = String.index str '\000' in + String.sub str 0 i + with + Not_found -> str + (** General binary tree type. Data 'a is stored in the leaves and 'b is stored in the nodes. *) type ('a,'b) binary_tree = diff --git a/lib/virt_mem_utsname.ml b/lib/virt_mem_utsname.ml index 084ba92..33ee969 100644 --- a/lib/virt_mem_utsname.ml +++ b/lib/virt_mem_utsname.ml @@ -24,16 +24,6 @@ open Virt_mem_utils open Virt_mem_types open Virt_mem_mmap -(* Truncate an OCaml string at the first ASCII NUL character, ie. as - * if it were a C string. - *) -let truncate str = - try - let i = String.index str '\000' in - String.sub str 0 i - with - Not_found -> str - let parse_utsname bits = (* Expect the first (sysname) field to always be "Linux", which is * also a good way to tell if we're synchronized to the right bit of @@ -48,11 +38,11 @@ let parse_utsname bits = domainname : 65*8 : string } -> Some { kernel_name = "Linux"; - nodename = truncate nodename; - kernel_release = truncate release; - kernel_version = truncate version; - machine = truncate machine; - domainname = truncate domainname + nodename = truncate_c_string nodename; + kernel_release = truncate_c_string release; + kernel_version = truncate_c_string version; + machine = truncate_c_string machine; + domainname = truncate_c_string domainname } | { _ } -> None -- 1.8.3.1