summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <maclas@gmx.de>2003-06-05 22:47:42 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2003-06-05 22:47:42 +0000
commit27b3b2c681e1edba973e2f13130386a8a49949bf (patch)
tree5470c2051b22a1ca40ed37b72af1e4269433c799
parent1cf610e216072fdb49d170d898bd4b7178ea3d2b (diff)
downloadglib-27b3b2c681e1edba973e2f13130386a8a49949bf.tar.gz
glib-27b3b2c681e1edba973e2f13130386a8a49949bf.tar.bz2
glib-27b3b2c681e1edba973e2f13130386a8a49949bf.zip
Synchronize argument names with headers and docs. (g_vasprintf): An
2003-06-06 Matthias Clasen <maclas@gmx.de> * glib/gprintf.[ch]: Synchronize argument names with headers and docs. (g_vasprintf): An implementation of vasprintf(), code was lifted from g_strdup_vprintf(). (#112365) * glib/gstrfuncs.c (g_strdup_vprintf): Just use g_vasprintf().
-rw-r--r--ChangeLog8
-rw-r--r--ChangeLog.pre-2-108
-rw-r--r--ChangeLog.pre-2-128
-rw-r--r--ChangeLog.pre-2-48
-rw-r--r--ChangeLog.pre-2-68
-rw-r--r--ChangeLog.pre-2-88
-rw-r--r--glib/gprintf.c118
-rw-r--r--glib/gprintf.h4
-rw-r--r--glib/gstrfuncs.c27
9 files changed, 142 insertions, 55 deletions
diff --git a/ChangeLog b/ChangeLog
index 4e76b6248..38cc4919b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-06-06 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
+ (g_vasprintf): An implementation of vasprintf(), code was lifted
+ from g_strdup_vprintf(). (#112365)
+
+ * glib/gstrfuncs.c (g_strdup_vprintf): Just use g_vasprintf().
+
2003-06-05 Tor Lillqvist <tml@iki.fi>
* glib/giochannel.h
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 4e76b6248..38cc4919b 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,11 @@
+2003-06-06 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
+ (g_vasprintf): An implementation of vasprintf(), code was lifted
+ from g_strdup_vprintf(). (#112365)
+
+ * glib/gstrfuncs.c (g_strdup_vprintf): Just use g_vasprintf().
+
2003-06-05 Tor Lillqvist <tml@iki.fi>
* glib/giochannel.h
diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12
index 4e76b6248..38cc4919b 100644
--- a/ChangeLog.pre-2-12
+++ b/ChangeLog.pre-2-12
@@ -1,3 +1,11 @@
+2003-06-06 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
+ (g_vasprintf): An implementation of vasprintf(), code was lifted
+ from g_strdup_vprintf(). (#112365)
+
+ * glib/gstrfuncs.c (g_strdup_vprintf): Just use g_vasprintf().
+
2003-06-05 Tor Lillqvist <tml@iki.fi>
* glib/giochannel.h
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index 4e76b6248..38cc4919b 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,11 @@
+2003-06-06 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
+ (g_vasprintf): An implementation of vasprintf(), code was lifted
+ from g_strdup_vprintf(). (#112365)
+
+ * glib/gstrfuncs.c (g_strdup_vprintf): Just use g_vasprintf().
+
2003-06-05 Tor Lillqvist <tml@iki.fi>
* glib/giochannel.h
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 4e76b6248..38cc4919b 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,11 @@
+2003-06-06 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
+ (g_vasprintf): An implementation of vasprintf(), code was lifted
+ from g_strdup_vprintf(). (#112365)
+
+ * glib/gstrfuncs.c (g_strdup_vprintf): Just use g_vasprintf().
+
2003-06-05 Tor Lillqvist <tml@iki.fi>
* glib/giochannel.h
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 4e76b6248..38cc4919b 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,11 @@
+2003-06-06 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
+ (g_vasprintf): An implementation of vasprintf(), code was lifted
+ from g_strdup_vprintf(). (#112365)
+
+ * glib/gstrfuncs.c (g_strdup_vprintf): Just use g_vasprintf().
+
2003-06-05 Tor Lillqvist <tml@iki.fi>
* glib/giochannel.h
diff --git a/glib/gprintf.c b/glib/gprintf.c
index 85461644b..03d8a076a 100644
--- a/glib/gprintf.c
+++ b/glib/gprintf.c
@@ -21,6 +21,12 @@
#include <config.h>
#endif
+#define _GNU_SOURCE /* For vasprintf */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+
#include "glib.h"
#include "gprintf.h"
#include "gprintfint.h"
@@ -38,14 +44,14 @@
* Since: 2.2
**/
gint
-g_printf (gchar const *fmt,
+g_printf (gchar const *format,
...)
{
va_list args;
gint retval;
- va_start (args, fmt);
- retval = g_vprintf (fmt, args);
+ va_start (args, format);
+ retval = g_vprintf (format, args);
va_end (args);
return retval;
@@ -65,15 +71,15 @@ g_printf (gchar const *fmt,
* Since: 2.2
**/
gint
-g_fprintf (FILE *file,
- gchar const *fmt,
+g_fprintf (FILE *file,
+ gchar const *format,
...)
{
va_list args;
gint retval;
- va_start (args, fmt);
- retval = g_vfprintf (file, fmt, args);
+ va_start (args, format);
+ retval = g_vfprintf (file, format, args);
va_end (args);
return retval;
@@ -93,15 +99,15 @@ g_fprintf (FILE *file,
* Since: 2.2
**/
gint
-g_sprintf (gchar *str,
- gchar const *fmt,
+g_sprintf (gchar *string,
+ gchar const *format,
...)
{
va_list args;
gint retval;
- va_start (args, fmt);
- retval = g_vsprintf (str, fmt, args);
+ va_start (args, format);
+ retval = g_vsprintf (string, format, args);
va_end (args);
return retval;
@@ -137,16 +143,16 @@ g_sprintf (gchar *str,
* was large enough.
**/
gint
-g_snprintf (gchar *str,
+g_snprintf (gchar *string,
gulong n,
- gchar const *fmt,
+ gchar const *format,
...)
{
va_list args;
gint retval;
- va_start (args, fmt);
- retval = g_vsnprintf (str, n, fmt, args);
+ va_start (args, format);
+ retval = g_vsnprintf (string, n, format, args);
va_end (args);
return retval;
@@ -165,12 +171,12 @@ g_snprintf (gchar *str,
* Since: 2.2
**/
gint
-g_vprintf (gchar const *fmt,
+g_vprintf (gchar const *format,
va_list args)
{
- g_return_val_if_fail (fmt != NULL, 0);
+ g_return_val_if_fail (format != NULL, 0);
- return _g_vprintf (fmt, args);
+ return _g_vprintf (format, args);
}
/**
@@ -187,13 +193,13 @@ g_vprintf (gchar const *fmt,
* Since: 2.2
**/
gint
-g_vfprintf (FILE *file,
- gchar const *fmt,
+g_vfprintf (FILE *file,
+ gchar const *format,
va_list args)
{
- g_return_val_if_fail (fmt != NULL, 0);
+ g_return_val_if_fail (format != NULL, 0);
- return _g_vfprintf (file, fmt, args);
+ return _g_vfprintf (file, format, args);
}
/**
@@ -210,14 +216,14 @@ g_vfprintf (FILE *file,
* Since: 2.2
**/
gint
-g_vsprintf (gchar *str,
- gchar const *fmt,
+g_vsprintf (gchar *string,
+ gchar const *format,
va_list args)
{
- g_return_val_if_fail (str != NULL, 0);
- g_return_val_if_fail (fmt != NULL, 0);
+ g_return_val_if_fail (string != NULL, 0);
+ g_return_val_if_fail (format != NULL, 0);
- return _g_vsprintf (str, fmt, args);
+ return _g_vsprintf (string, format, args);
}
/**
@@ -250,15 +256,63 @@ g_vsprintf (gchar *str,
* was large enough.
*/
gint
-g_vsnprintf (gchar *str,
+g_vsnprintf (gchar *string,
gulong n,
- gchar const *fmt,
+ gchar const *format,
va_list args)
{
- g_return_val_if_fail (n == 0 || str != NULL, 0);
- g_return_val_if_fail (fmt != NULL, 0);
+ g_return_val_if_fail (n == 0 || string != NULL, 0);
+ g_return_val_if_fail (format != NULL, 0);
+
+ return _g_vsnprintf (string, n, format, args);
+}
+
+/**
+ * g_vasprintf:
+ * @string: the return location for the newly-allocated string.
+ * @format: the format string. See the printf() documentation.
+ * @args: the list of arguments to insert in the output.
+ *
+ * An implementation of the GNU vasprintf() function which supports
+ * positional parameters, as specified in the Single Unix Specification.
+ * This function is similar to g_vsprintf(), except that it allocates a
+ * string to hold the output, instead of putting the output in a buffer
+ * you allocate in advance.
+ *
+ * Returns: the number of characters printed.
+ *
+ * Since: 2.4
+ **/
+gint
+g_vasprintf (gchar **string,
+ gchar const *format,
+ va_list args)
+{
+ gint len;
+ g_return_val_if_fail (string != NULL, -1);
+
+#ifdef HAVE_VASPRINTF
+ len = _g_vasprintf (string, format, args);
+ if (len < 0)
+ *string = NULL;
+ else if (!g_mem_is_system_malloc ())
+ {
+ gchar *string1 = g_strndup (*string, len);
+ free (*string);
+ *string = string1;
+ }
+#else
+ va_list args2;
+
+ G_VA_COPY (args2, args);
+
+ *string = g_new (gchar, g_printf_string_upper_bound (format, args));
+
+ len = _g_vsprintf (*string, format, args2);
+ va_end (args2);
+#endif
- return _g_vsnprintf (str, n, fmt, args);
+ return len;
}
diff --git a/glib/gprintf.h b/glib/gprintf.h
index 6fcacc2c1..0226f22a5 100644
--- a/glib/gprintf.h
+++ b/glib/gprintf.h
@@ -50,7 +50,9 @@ gint g_vsnprintf (gchar *string,
gulong n,
gchar const *format,
va_list args);
-
+gint g_vasprintf (gchar **string,
+ gchar const *format,
+ va_list args);
G_END_DECLS
diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c
index b8c84b721..410c3e402 100644
--- a/glib/gstrfuncs.c
+++ b/glib/gstrfuncs.c
@@ -44,6 +44,7 @@
#endif
#include "glib.h"
+#include "gprintf.h"
#include "gprintfint.h"
#ifdef G_OS_WIN32
@@ -181,31 +182,13 @@ g_stpcpy (gchar *dest,
gchar*
g_strdup_vprintf (const gchar *format,
- va_list args1)
+ va_list args)
{
- gchar *buffer;
-#ifdef HAVE_VASPRINTF
- gint len;
- len = _g_vasprintf (&buffer, format, args1);
- if (len < 0)
- buffer = NULL;
- else if (!g_mem_is_system_malloc ())
- {
- gchar *buffer1 = g_strndup (buffer, len);
- free (buffer);
- buffer = buffer1;
- }
-#else
- va_list args2;
+ gchar *string = NULL;
- G_VA_COPY (args2, args1);
+ g_vasprintf (&string, format, args);
- buffer = g_new (gchar, g_printf_string_upper_bound (format, args1));
-
- _g_vsprintf (buffer, format, args2);
- va_end (args2);
-#endif
- return buffer;
+ return string;
}
gchar*