From 519435e6425cb0142d88c0a12da9c9b2cf7be923 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Wed, 2 Sep 1998 14:57:10 +0000 Subject: [PATCH] new function g_strnfill() to return a new string of specified length, Wed Aug 26 06:32:40 1998 Tim Janik * glib.h: * gstrfuncs.c: new function g_strnfill() to return a new string of specified length, filled with a specific character. --- ChangeLog | 6 ++++++ ChangeLog.pre-2-0 | 6 ++++++ ChangeLog.pre-2-10 | 6 ++++++ ChangeLog.pre-2-12 | 6 ++++++ ChangeLog.pre-2-2 | 6 ++++++ ChangeLog.pre-2-4 | 6 ++++++ ChangeLog.pre-2-6 | 6 ++++++ ChangeLog.pre-2-8 | 6 ++++++ glib.h | 4 +++- glib/glib.h | 4 +++- glib/gstrfuncs.c | 29 ++++++++++++++++++++++++----- gstrfuncs.c | 29 ++++++++++++++++++++++++----- 12 files changed, 102 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 95fb3b9b8..2a8cf973e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Aug 26 06:32:40 1998 Tim Janik + + * glib.h: + * gstrfuncs.c: new function g_strnfill() to return a new string + of specified length, filled with a specific character. + Tue Sep 1 23:46:31 1998 Josh MacDonald * testglib.c (main): Update the array tests. Reduce the number of diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 95fb3b9b8..2a8cf973e 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,9 @@ +Wed Aug 26 06:32:40 1998 Tim Janik + + * glib.h: + * gstrfuncs.c: new function g_strnfill() to return a new string + of specified length, filled with a specific character. + Tue Sep 1 23:46:31 1998 Josh MacDonald * testglib.c (main): Update the array tests. Reduce the number of diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 95fb3b9b8..2a8cf973e 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +Wed Aug 26 06:32:40 1998 Tim Janik + + * glib.h: + * gstrfuncs.c: new function g_strnfill() to return a new string + of specified length, filled with a specific character. + Tue Sep 1 23:46:31 1998 Josh MacDonald * testglib.c (main): Update the array tests. Reduce the number of diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 95fb3b9b8..2a8cf973e 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,9 @@ +Wed Aug 26 06:32:40 1998 Tim Janik + + * glib.h: + * gstrfuncs.c: new function g_strnfill() to return a new string + of specified length, filled with a specific character. + Tue Sep 1 23:46:31 1998 Josh MacDonald * testglib.c (main): Update the array tests. Reduce the number of diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 95fb3b9b8..2a8cf973e 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +Wed Aug 26 06:32:40 1998 Tim Janik + + * glib.h: + * gstrfuncs.c: new function g_strnfill() to return a new string + of specified length, filled with a specific character. + Tue Sep 1 23:46:31 1998 Josh MacDonald * testglib.c (main): Update the array tests. Reduce the number of diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 95fb3b9b8..2a8cf973e 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +Wed Aug 26 06:32:40 1998 Tim Janik + + * glib.h: + * gstrfuncs.c: new function g_strnfill() to return a new string + of specified length, filled with a specific character. + Tue Sep 1 23:46:31 1998 Josh MacDonald * testglib.c (main): Update the array tests. Reduce the number of diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 95fb3b9b8..2a8cf973e 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +Wed Aug 26 06:32:40 1998 Tim Janik + + * glib.h: + * gstrfuncs.c: new function g_strnfill() to return a new string + of specified length, filled with a specific character. + Tue Sep 1 23:46:31 1998 Josh MacDonald * testglib.c (main): Update the array tests. Reduce the number of diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 95fb3b9b8..2a8cf973e 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +Wed Aug 26 06:32:40 1998 Tim Janik + + * glib.h: + * gstrfuncs.c: new function g_strnfill() to return a new string + of specified length, filled with a specific character. + Tue Sep 1 23:46:31 1998 Josh MacDonald * testglib.c (main): Update the array tests. Reduce the number of diff --git a/glib.h b/glib.h index 601153a29..7f9826ca7 100644 --- a/glib.h +++ b/glib.h @@ -1128,7 +1128,9 @@ gchar* g_strdup_printf (const gchar *format, gchar* g_strdup_vprintf (const gchar *format, va_list args); gchar* g_strndup (const gchar *str, - gulong n); + guint n); +gchar* g_strnfill (guint length, + gchar fill_char); gchar* g_strconcat (const gchar *string1, ...); /* NULL terminated */ gdouble g_strtod (const gchar *nptr, diff --git a/glib/glib.h b/glib/glib.h index 601153a29..7f9826ca7 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -1128,7 +1128,9 @@ gchar* g_strdup_printf (const gchar *format, gchar* g_strdup_vprintf (const gchar *format, va_list args); gchar* g_strndup (const gchar *str, - gulong n); + guint n); +gchar* g_strnfill (guint length, + gchar fill_char); gchar* g_strconcat (const gchar *string1, ...); /* NULL terminated */ gdouble g_strtod (const gchar *nptr, diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index 46234dcc2..176985434 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -32,32 +32,51 @@ g_strdup (const gchar *str) { gchar *new_str; - new_str = NULL; if (str) { new_str = g_new (char, strlen (str) + 1); strcpy (new_str, str); } + else + new_str = NULL; return new_str; } gchar* -g_strndup (const gchar *str, gulong n) +g_strndup (const gchar *str, + guint n) { - char *new_str; + gchar *new_str; - new_str = NULL; if (str) { - new_str = g_new (char, n + 1); + new_str = g_new (gchar, n + 1); strncpy (new_str, str, n); new_str[n] = '\0'; } + else + new_str = NULL; return new_str; } +gchar* +g_strnfill (guint length, + gchar fill_char) +{ + register gchar *str, *s, *end; + + str = g_new (gchar, length + 1); + s = str; + end = str + length; + while (s < end) + *(s++) = fill_char; + *s = 0; + + return str; +} + gchar* g_strdup_vprintf (const gchar *format, va_list args1) diff --git a/gstrfuncs.c b/gstrfuncs.c index 46234dcc2..176985434 100644 --- a/gstrfuncs.c +++ b/gstrfuncs.c @@ -32,32 +32,51 @@ g_strdup (const gchar *str) { gchar *new_str; - new_str = NULL; if (str) { new_str = g_new (char, strlen (str) + 1); strcpy (new_str, str); } + else + new_str = NULL; return new_str; } gchar* -g_strndup (const gchar *str, gulong n) +g_strndup (const gchar *str, + guint n) { - char *new_str; + gchar *new_str; - new_str = NULL; if (str) { - new_str = g_new (char, n + 1); + new_str = g_new (gchar, n + 1); strncpy (new_str, str, n); new_str[n] = '\0'; } + else + new_str = NULL; return new_str; } +gchar* +g_strnfill (guint length, + gchar fill_char) +{ + register gchar *str, *s, *end; + + str = g_new (gchar, length + 1); + s = str; + end = str + length; + while (s < end) + *(s++) = fill_char; + *s = 0; + + return str; +} + gchar* g_strdup_vprintf (const gchar *format, va_list args1)