+2009-01-13 Matthias Clasen <mclasen@redhat.com>
+
+ Bug 564728 Add function to decode base64 encoded data in place
+
+ * glib/glib.symbols:
+ * glib/gbase64.[hc] (g_base64_decode_inplace): New convenience
+ API to decode in place, overwriting the input string. Patch by
+ Sebastian Dröge.
+
2009-01-12 Matthias Clasen <mclasen@redhat.com>
* glib/gtestutils.c (g_strcmp0): Be more explicit about the NULL
+2009-01-13 Matthias Clasen <mclasen@redhat.com>
+
+ * glib/glib-sections.txt:
+ * glib/tmpl/base64.sgml: Mention g_base64_decode_inplace
+
2009-01-05 Matthias Clasen <mclasen@redhat.com>
* === Released 2.19.4 ===
g_base64_encode
g_base64_decode_step
g_base64_decode
+g_base64_decode_inplace
</SECTION>
<SECTION>
GLib supports incremental encoding using g_base64_encode_step() and
g_base64_encode_close(). Incremental decoding can be done with
g_base64_decode_step(). To encode or decode data in one go, use
-g_base64_encode() or g_base64_decode().
+g_base64_encode() or g_base64_decode(). To avoid memory allocation when
+decoding, you can use g_base64_decode_inplace().
</para>
<para>
return ret;
}
+
+/**
+ * g_base64_decode_inplace:
+ * @text: zero-terminated string with base64 text to decode
+ * @out_len: The length of the decoded data is written here
+ *
+ * Decode a sequence of Base-64 encoded text into binary data
+ * by overwriting the input data.
+ *
+ * Return value: The binary data that @text responds. This pointer
+ * is the same as the input @text.
+ *
+ * Since: 2.20
+ */
+guchar *
+g_base64_decode_inplace (gchar *text,
+ gsize *out_len)
+{
+ gint input_length, state = 0;
+ guint save = 0;
+
+ g_return_val_if_fail (text != NULL, NULL);
+ g_return_val_if_fail (out_len != NULL, NULL);
+
+ input_length = strlen (text);
+
+ g_return_val_if_fail (input_length > 1, NULL);
+
+ *out_len = g_base64_decode_step (text, input_length, (guchar *) text, &state, &save);
+
+ return text;
+}
+
#define __G_BASE64_C__
#include "galiasdef.c"
guint *save);
guchar *g_base64_decode (const gchar *text,
gsize *out_len) G_GNUC_MALLOC;
+guchar *g_base64_decode_inplace (gchar *text,
+ gsize *out_len);
+
G_END_DECLS
g_base64_encode G_GNUC_MALLOC
g_base64_decode_step
g_base64_decode G_GNUC_MALLOC
+g_base64_decode_inplace
#endif
#endif