diff options
author | Richard Jones <rjones@redhat.com> | 2010-08-17 11:26:26 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-08-17 14:09:25 +0100 |
commit | 3905cc7ab496549b6ca0a0f67ec61d1d16968c33 (patch) | |
tree | 94313e6b0671d03ab5e4cd20d3895d9a7c9f8d8b /src | |
parent | 64d70228c704c49a023ab35499d003e9bb09cd73 (diff) | |
download | libguestfs-3905cc7ab496549b6ca0a0f67ec61d1d16968c33.tar.gz libguestfs-3905cc7ab496549b6ca0a0f67ec61d1d16968c33.tar.xz libguestfs-3905cc7ab496549b6ca0a0f67ec61d1d16968c33.zip |
Add safe_strndup call.
Diffstat (limited to 'src')
-rw-r--r-- | src/guestfs-internal.h | 2 | ||||
-rw-r--r-- | src/guestfs.c | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index 12ca0ecf..d0fc3ca9 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 c54462da..871d7138 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) { |