From: Richard Jones Date: Tue, 17 Aug 2010 10:26:26 +0000 (+0100) Subject: Add safe_strndup call. X-Git-Tag: 1.5.3~8 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=3905cc7ab496549b6ca0a0f67ec61d1d16968c33;p=libguestfs.git Add safe_strndup call. --- 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) {