diff options
author | Werner Koch <wk@gnupg.org> | 2007-11-19 17:03:50 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2007-11-19 17:03:50 +0100 |
commit | 55ba204bfa848c2e591a29fedc9f103103493a57 (patch) | |
tree | e37263e4d3a25e2aa300faf4c5240191b54ea1a7 /jnlib/stringhelp.c | |
parent | Updated (diff) | |
download | gnupg2-55ba204bfa848c2e591a29fedc9f103103493a57.tar.xz gnupg2-55ba204bfa848c2e591a29fedc9f103103493a57.zip |
Started to implement the audit log feature.
Pass PINENTRY_USER_DATA and XAUTHORITY to Pinentry.
Improved support for the quality bar.
Minor internal restructuring.
Translation fixes.
Diffstat (limited to 'jnlib/stringhelp.c')
-rw-r--r-- | jnlib/stringhelp.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c index 2f5204341..028750528 100644 --- a/jnlib/stringhelp.c +++ b/jnlib/stringhelp.c @@ -856,9 +856,9 @@ memrchr (const void *buffer, int c, size_t n) /* Percent-escape the string STR by replacing colons with '%3a'. If - EXTRA is not NULL all characters in it are also escaped. */ -char * -percent_escape (const char *str, const char *extra) + EXTRA is not NULL all characters in EXTRA are also escaped. */ +static char * +do_percent_escape (const char *str, const char *extra, int die) { int i, j; char *ptr; @@ -869,7 +869,14 @@ percent_escape (const char *str, const char *extra) for (i=j=0; str[i]; i++) if (str[i] == ':' || str[i] == '%' || (extra && strchr (extra, str[i]))) j++; - ptr = jnlib_xmalloc (i + 2 * j + 1); + if (die) + ptr = jnlib_xmalloc (i + 2 * j + 1); + else + { + ptr = jnlib_malloc (i + 2 * j + 1); + if (!ptr) + return NULL; + } i = 0; while (*str) { @@ -899,3 +906,19 @@ percent_escape (const char *str, const char *extra) return ptr; } + +/* Percent-escape the string STR by replacing colons with '%3a'. If + EXTRA is not NULL all characters in EXTRA are also escaped. */ +char * +percent_escape (const char *str, const char *extra) +{ + return do_percent_escape (str, extra, 1); +} + +/* Same as percent_escape but return NULL instead of exiting on memory + error. */ +char * +try_percent_escape (const char *str, const char *extra) +{ + return do_percent_escape (str, extra, 0); +} |