summaryrefslogtreecommitdiffstats
path: root/sparsify/utils.ml
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-11-22 09:39:54 +0000
committerRichard W.M. Jones <rjones@redhat.com>2011-11-22 09:43:49 +0000
commit342b4a55d056734a0344db8b4bcf1a90104a8a59 (patch)
tree4d65a311fdccc94c77dcc95947a874054c81c5c3 /sparsify/utils.ml
parent0cdd9444744e7ae0d82fe4c94d13e9ddd00e8e2d (diff)
downloadlibguestfs-342b4a55d056734a0344db8b4bcf1a90104a8a59.tar.gz
libguestfs-342b4a55d056734a0344db8b4bcf1a90104a8a59.tar.xz
libguestfs-342b4a55d056734a0344db8b4bcf1a90104a8a59.zip
sparsify: Add auto-detection of .vdi files.
Note that for this to work properly, it requires a patch to the 'file' command. See: https://www.redhat.com/archives/libguestfs/2011-November/msg00120.html
Diffstat (limited to 'sparsify/utils.ml')
-rw-r--r--sparsify/utils.ml19
1 files changed, 19 insertions, 0 deletions
diff --git a/sparsify/utils.ml b/sparsify/utils.ml
index 4f5631d6..b7c531d8 100644
--- a/sparsify/utils.ml
+++ b/sparsify/utils.ml
@@ -57,6 +57,25 @@ let string_prefix str prefix =
let n = String.length prefix in
String.length str >= n && String.sub str 0 n = prefix
+let rec string_find s sub =
+ let len = String.length s in
+ let sublen = String.length sub in
+ let rec loop i =
+ if i <= len-sublen then (
+ let rec loop2 j =
+ if j < sublen then (
+ if s.[i+j] = sub.[j] then loop2 (j+1)
+ else -1
+ ) else
+ i (* found *)
+ in
+ let r = loop2 0 in
+ if r = -1 then loop (i+1) else r
+ ) else
+ -1 (* not found *)
+ in
+ loop 0
+
let string_random8 =
let chars = "abcdefghijklmnopqrstuvwxyz0123456789" in
fun () ->