From 3ae8c300bb243fb611efe8b0a3257ed163f8a834 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Wed, 21 Jan 1998 00:46:48 +0000 Subject: [PATCH] Applied patch from (Raja R Harinath ) to add function Wed Jan 21 01:13:25 1998 Tim Janik * Applied patch from (Raja R Harinath ) to add function g_snprintf. * configure.in (AC_CHECK_FUNCS): Check for vsnprintf. * glib.h: Add prototype for g_snprintf. * glibconfig.h.in: Add HAVE_VSNPRINTF. * gutils.c (g_snprintf): new function. --- glib/ChangeLog | 9 +++++++++ glib/acconfig.h | 1 + glib/configure.in | 2 +- glib/glib.h | 2 ++ glib/glibconfig.h.in | 4 ++++ glib/gutils.c | 37 ++++++++++++++++++++++++++++++++++++- 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/glib/ChangeLog b/glib/ChangeLog index 2aea31b7ff..eeba0a4a92 100644 --- a/glib/ChangeLog +++ b/glib/ChangeLog @@ -1,3 +1,12 @@ +Wed Jan 21 01:13:25 1998 Tim Janik + + * Applied patch from (Raja R Harinath ) + to add function g_snprintf. + * configure.in (AC_CHECK_FUNCS): Check for vsnprintf. + * glib.h: Add prototype for g_snprintf. + * glibconfig.h.in: Add HAVE_VSNPRINTF. + * gutils.c (g_snprintf): new function. + Sat Jan 17 23:52:40 1998 Owen Taylor * gstring.{c,h} gscanner.c: diff --git a/glib/acconfig.h b/glib/acconfig.h index 52818d41f5..90e8add005 100644 --- a/glib/acconfig.h +++ b/glib/acconfig.h @@ -39,6 +39,7 @@ #undef HAVE_SYS_SELECT_H #undef HAVE_STRERROR #undef HAVE_STRSIGNAL +#undef HAVE_VSNPRINTF #undef HAVE_VALUES_H #undef HAVE_VPRINTF diff --git a/glib/configure.in b/glib/configure.in index 7e98e9e271..2b05e41236 100644 --- a/glib/configure.in +++ b/glib/configure.in @@ -70,7 +70,7 @@ AC_CHECK_HEADERS(limits.h, AC_DEFINE(HAVE_LIMITS_H)) AC_CHECK_HEADERS(values.h, AC_DEFINE(HAVE_VALUES_H)) # Check for strerror, strsignal, and memmove functions -AC_CHECK_FUNCS(strerror strsignal memmove) +AC_CHECK_FUNCS(strerror strsignal memmove vsnprintf) # Check for sys_errlist AC_MSG_CHECKING(sys_errlist) diff --git a/glib/glib.h b/glib/glib.h index f641762c41..e929827799 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -630,6 +630,8 @@ gchar* g_strconcat (const gchar *string1, ...); /* NULL terminated */ gdouble g_strtod (const gchar *nptr, gchar **endptr); gchar* g_strerror (gint errnum); gchar* g_strsignal (gint signum); +gint g_snprintf (gchar *str, gulong n, gchar const *fmt, ...); + /* We make the assumption that if memmove isn't available, then * bcopy will do the job. This isn't safe everywhere. (bcopy can't diff --git a/glib/glibconfig.h.in b/glib/glibconfig.h.in index 1d1c6f218b..ad4a6b08ee 100644 --- a/glib/glibconfig.h.in +++ b/glib/glibconfig.h.in @@ -23,6 +23,7 @@ #undef HAVE_SYS_SELECT_H #undef HAVE_STRERROR #undef HAVE_STRSIGNAL +#undef HAVE_VSNPRINTF #undef HAVE_VALUES_H #undef HAVE_VPRINTF @@ -61,6 +62,9 @@ /* Define if you have the strsignal function. */ #undef HAVE_STRSIGNAL +/* Define if you have the vsnprintf function. */ +#undef HAVE_VSNPRINTF + /* Define if you have the header file. */ #undef HAVE_FLOAT_H diff --git a/glib/gutils.c b/glib/gutils.c index c5dc9965ec..87c3964b53 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -804,6 +804,41 @@ g_set_print_handler (GPrintFunc func) old_print_func = print_func; print_func = func; - + return old_print_func; } + +gint +g_snprintf (gchar *str, + gulong n, + gchar const *fmt, + ...) +{ +#ifdef HAVE_VSNPRINTF + va_list args; + gint retval; + + va_start (args, fmt); + retval = vsnprintf (str, n, fmt, args); + va_end (args); + + return retval; + +#else + gchar *printed; + va_list args, args2; + + va_start (args, fmt); + va_start (args2, fmt); + + printed = g_vsprintf (fmt, &args, &args2); + strncpy (str, printed, n); + str[n-1] = '\0'; + + va_end (args2); + va_end (args); + + return strlen (str); + +#endif +}