diff options
author | David Bremner <bremner@debian.org> | 2012-06-15 01:08:36 +0300 |
---|---|---|
committer | David Bremner <bremner@debian.org> | 2012-12-02 09:14:59 -0400 |
commit | 902f2e19bdb649baee4e07cdb9cc9e7785f209b5 (patch) | |
tree | 5a85a3324e376a55c1771a4427708d391153fd9e /util/hex-escape.h | |
parent | 113e30c01baab44b67c0065f81cc6073553415fa (diff) |
hex-escape: (en|de)code strings to/from restricted character set
The character set is chosen to be suitable for pathnames, and the same
as that used by contrib/nmbug
[With additions by Jani Nikula]
Diffstat (limited to 'util/hex-escape.h')
-rw-r--r-- | util/hex-escape.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/util/hex-escape.h b/util/hex-escape.h new file mode 100644 index 00000000..5182042e --- /dev/null +++ b/util/hex-escape.h @@ -0,0 +1,41 @@ +#ifndef _HEX_ESCAPE_H +#define _HEX_ESCAPE_H + +typedef enum hex_status { + HEX_SUCCESS = 0, + HEX_SYNTAX_ERROR, + HEX_OUT_OF_MEMORY +} hex_status_t; + +/* + * The API for hex_encode() and hex_decode() is modelled on that for + * getline. + * + * If 'out' points to a NULL pointer a char array of the appropriate + * size is allocated using talloc, and out_size is updated. + * + * If 'out' points to a non-NULL pointer, it assumed to describe an + * existing char array, with the size given in *out_size. This array + * may be resized by talloc_realloc if needed; in this case *out_size + * will also be updated. + * + * Note that it is an error to pass a NULL pointer for any parameter + * of these routines. + */ + +hex_status_t +hex_encode (void *talloc_ctx, const char *in, char **out, + size_t *out_size); + +hex_status_t +hex_decode (void *talloc_ctx, const char *in, char **out, + size_t *out_size); + +/* + * Non-allocating hex decode to decode 's' in-place. The length of the + * result is always equal to or shorter than the length of the + * original. + */ +hex_status_t +hex_decode_inplace (char *s); +#endif |