[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH v4 1/8] Add safe_strndup call.



-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
>From 11b218e89b620940bd374630600acce508e24b15 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones redhat com>
Date: Tue, 17 Aug 2010 11:26:26 +0100
Subject: [PATCH 1/8] Add safe_strndup call.

---
 src/guestfs-internal.h |    2 ++
 src/guestfs.c          |    8 ++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 12ca0ec..d0fc3ca 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -141,6 +141,7 @@ extern void guestfs_perrorf (guestfs_h *g, const char *fs, ...)
   __attribute__((format (printf,2,3)));
 extern void *guestfs_safe_realloc (guestfs_h *g, void *ptr, int nbytes);
 extern char *guestfs_safe_strdup (guestfs_h *g, const char *str);
+extern char *guestfs_safe_strndup (guestfs_h *g, const char *str, size_t n);
 extern void *guestfs_safe_memdup (guestfs_h *g, void *ptr, size_t size);
 extern int guestfs___set_busy (guestfs_h *g);
 extern int guestfs___end_busy (guestfs_h *g);
@@ -157,6 +158,7 @@ extern int guestfs___accept_from_daemon (guestfs_h *g);
 #define safe_malloc guestfs_safe_malloc
 #define safe_realloc guestfs_safe_realloc
 #define safe_strdup guestfs_safe_strdup
+#define safe_strndup guestfs_safe_strndup
 #define safe_memdup guestfs_safe_memdup
 
 #endif /* GUESTFS_INTERNAL_H_ */
diff --git a/src/guestfs.c b/src/guestfs.c
index c54462d..871d713 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -397,6 +397,14 @@ guestfs_safe_strdup (guestfs_h *g, const char *str)
   return s;
 }
 
+char *
+guestfs_safe_strndup (guestfs_h *g, const char *str, size_t n)
+{
+  char *s = strndup (str, n);
+  if (!s) g->abort_cb ();
+  return s;
+}
+
 void *
 guestfs_safe_memdup (guestfs_h *g, void *ptr, size_t size)
 {
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]