Bug 564728 Add function to decode base64 encoded data in place

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.


svn path=/trunk/; revision=7807
This commit is contained in:
Matthias Clasen 2009-01-13 19:59:32 +00:00 committed by Matthias Clasen
parent 0f35c33ecf
commit c8dd07333a
7 changed files with 54 additions and 1 deletions

View File

@ -1,3 +1,12 @@
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

View File

@ -1,3 +1,8 @@
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 ===

View File

@ -2527,6 +2527,7 @@ g_base64_encode_close
g_base64_encode
g_base64_decode_step
g_base64_decode
g_base64_decode_inplace
</SECTION>
<SECTION>

View File

@ -18,7 +18,8 @@ for email.
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>

View File

@ -374,6 +374,39 @@ g_base64_decode (const gchar *text,
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"

View File

@ -48,6 +48,9 @@ gsize g_base64_decode_step (const gchar *in,
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

View File

@ -111,6 +111,7 @@ g_base64_encode_close
g_base64_encode G_GNUC_MALLOC
g_base64_decode_step
g_base64_decode G_GNUC_MALLOC
g_base64_decode_inplace
#endif
#endif