From eeb971d1b95d5894bff1629c4c15a916646bc5d3 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Sat, 19 Sep 1998 01:12:06 +0000 Subject: [PATCH] minor g_memdup() fixups --- glib.h | 35 +++++++++++++++++------------------ glib/glib.h | 35 +++++++++++++++++------------------ glib/gstrfuncs.c | 20 ++++++++++++++------ gstrfuncs.c | 20 ++++++++++++++------ 4 files changed, 62 insertions(+), 48 deletions(-) diff --git a/glib.h b/glib.h index 0817691..c52179e 100644 --- a/glib.h +++ b/glib.h @@ -1175,39 +1175,38 @@ gdouble g_timer_elapsed (GTimer *timer, /* String utility functions */ -#define G_STR_DELIMITERS "_-|> <." -void g_strdelimit (gchar *string, +#define G_STR_DELIMITERS "_-|> <." +void g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter); -gchar* g_strdup (const gchar *str); -gchar* g_strdup_printf (const gchar *format, +gchar* g_strdup (const gchar *str); +gchar* g_strdup_printf (const gchar *format, ...) G_GNUC_PRINTF (1, 2); -gchar* g_strdup_vprintf (const gchar *format, +gchar* g_strdup_vprintf (const gchar *format, va_list args); -gchar* g_strndup (const gchar *str, +gchar* g_strndup (const gchar *str, guint n); -gchar* g_strnfill (guint length, +gchar* g_strnfill (guint length, gchar fill_char); -gchar* g_strconcat (const gchar *string1, +gchar* g_strconcat (const gchar *string1, ...); /* NULL terminated */ -gdouble g_strtod (const gchar *nptr, +gdouble g_strtod (const gchar *nptr, gchar **endptr); -gchar* g_strerror (gint errnum); -gchar* g_strsignal (gint signum); -gint g_strcasecmp (const gchar *s1, +gchar* g_strerror (gint errnum); +gchar* g_strsignal (gint signum); +gint g_strcasecmp (const gchar *s1, const gchar *s2); -void g_strdown (gchar *string); -void g_strup (gchar *string); -void g_strreverse (gchar *string); +void g_strdown (gchar *string); +void g_strup (gchar *string); +void g_strreverse (gchar *string); +gpointer g_memdup (gconstpointer mem, + guint byte_size); /* calculate a string size, guarranteed to fit format + args. */ guint g_printf_string_upper_bound (const gchar* format, va_list args); -guint8* g_memdup (const guint8 *mem, - guint len); - /* Retrive static string info */ diff --git a/glib/glib.h b/glib/glib.h index 0817691..c52179e 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -1175,39 +1175,38 @@ gdouble g_timer_elapsed (GTimer *timer, /* String utility functions */ -#define G_STR_DELIMITERS "_-|> <." -void g_strdelimit (gchar *string, +#define G_STR_DELIMITERS "_-|> <." +void g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter); -gchar* g_strdup (const gchar *str); -gchar* g_strdup_printf (const gchar *format, +gchar* g_strdup (const gchar *str); +gchar* g_strdup_printf (const gchar *format, ...) G_GNUC_PRINTF (1, 2); -gchar* g_strdup_vprintf (const gchar *format, +gchar* g_strdup_vprintf (const gchar *format, va_list args); -gchar* g_strndup (const gchar *str, +gchar* g_strndup (const gchar *str, guint n); -gchar* g_strnfill (guint length, +gchar* g_strnfill (guint length, gchar fill_char); -gchar* g_strconcat (const gchar *string1, +gchar* g_strconcat (const gchar *string1, ...); /* NULL terminated */ -gdouble g_strtod (const gchar *nptr, +gdouble g_strtod (const gchar *nptr, gchar **endptr); -gchar* g_strerror (gint errnum); -gchar* g_strsignal (gint signum); -gint g_strcasecmp (const gchar *s1, +gchar* g_strerror (gint errnum); +gchar* g_strsignal (gint signum); +gint g_strcasecmp (const gchar *s1, const gchar *s2); -void g_strdown (gchar *string); -void g_strup (gchar *string); -void g_strreverse (gchar *string); +void g_strdown (gchar *string); +void g_strup (gchar *string); +void g_strreverse (gchar *string); +gpointer g_memdup (gconstpointer mem, + guint byte_size); /* calculate a string size, guarranteed to fit format + args. */ guint g_printf_string_upper_bound (const gchar* format, va_list args); -guint8* g_memdup (const guint8 *mem, - guint len); - /* Retrive static string info */ diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index d477736..721509b 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -43,13 +43,21 @@ g_strdup (const gchar *str) return new_str; } -guint8* -g_memdup (const guint8 *mem, - guint len) +gpointer +g_memdup (gconstpointer mem, + guint byte_size) { - guint8* mem2 = g_malloc (len); - memcpy (mem2, mem, len); - return mem2; + gpointer new_mem; + + if (mem) + { + new_mem = g_malloc (byte_size); + memcpy (new_mem, mem, byte_size); + } + else + new_mem = NULL; + + return new_mem; } gchar* diff --git a/gstrfuncs.c b/gstrfuncs.c index d477736..721509b 100644 --- a/gstrfuncs.c +++ b/gstrfuncs.c @@ -43,13 +43,21 @@ g_strdup (const gchar *str) return new_str; } -guint8* -g_memdup (const guint8 *mem, - guint len) +gpointer +g_memdup (gconstpointer mem, + guint byte_size) { - guint8* mem2 = g_malloc (len); - memcpy (mem2, mem, len); - return mem2; + gpointer new_mem; + + if (mem) + { + new_mem = g_malloc (byte_size); + memcpy (new_mem, mem, byte_size); + } + else + new_mem = NULL; + + return new_mem; } gchar* -- 2.7.4