diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-06-07 12:58:38 +0000 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-06-07 12:58:38 +0000 |
commit | b9a8a140cf09780671402e872130a51ec4f4b014 (patch) | |
tree | 63f7d4bbb427ef90f473b6c30e1567ff5281839a /p11-kit | |
parent | b315f99c90d01104d6baa91ca0f2cfb32c920abd (diff) |
Add p11_kit_space_strdup() function, and rename p11_kit_space_strlen()
* Print out module info in p11-kit tool.
Diffstat (limited to 'p11-kit')
-rw-r--r-- | p11-kit/p11-kit.h | 6 | ||||
-rw-r--r-- | p11-kit/uri.c | 15 | ||||
-rw-r--r-- | p11-kit/uri.h | 3 | ||||
-rw-r--r-- | p11-kit/util.c | 34 |
4 files changed, 42 insertions, 16 deletions
diff --git a/p11-kit/p11-kit.h b/p11-kit/p11-kit.h index f60e4ae..96b9df3 100644 --- a/p11-kit/p11-kit.h +++ b/p11-kit/p11-kit.h @@ -72,6 +72,12 @@ CK_RV p11_kit_load_initialize_module (const char *module_p const char* p11_kit_strerror (CK_RV rv); +size_t p11_kit_space_strlen (const unsigned char *string, + size_t max_length); + +char* p11_kit_space_strdup (const unsigned char *string, + size_t max_length); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/p11-kit/uri.c b/p11-kit/uri.c index 4f8e251..3075cae 100644 --- a/p11-kit/uri.c +++ b/p11-kit/uri.c @@ -37,6 +37,7 @@ #define DEBUG_FLAG DEBUG_URI #include "debug.h" #include "pkcs11.h" +#include "p11-kit.h" #include "uri.h" #include "util.h" @@ -733,18 +734,6 @@ p11_kit_uri_new (void) return uri; } -size_t -p11_kit_uri_space_strlen (const unsigned char *string, size_t max_length) -{ - size_t i = max_length - 1; - - assert (string); - - while (i > 0 && string[i] == ' ') - --i; - return i + 1; -} - static int format_raw_string (char **string, size_t *length, int *is_first, const char *name, const char *value) @@ -805,7 +794,7 @@ format_struct_string (char **string, size_t *length, int *is_first, if (!value[0]) return 1; - len = p11_kit_uri_space_strlen (value, value_max); + len = p11_kit_space_strlen (value, value_max); return format_encode_string (string, length, is_first, name, value, len); } diff --git a/p11-kit/uri.h b/p11-kit/uri.h index 2ce56e6..9f1f516 100644 --- a/p11-kit/uri.h +++ b/p11-kit/uri.h @@ -143,9 +143,6 @@ void p11_kit_uri_free (P11KitUri *uri); const char* p11_kit_uri_message (int code); -size_t p11_kit_uri_space_strlen (const unsigned char *string, - size_t max_length); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/p11-kit/util.c b/p11-kit/util.c index 2b9e79c..ead18cc 100644 --- a/p11-kit/util.c +++ b/p11-kit/util.c @@ -36,9 +36,12 @@ #include "config.h" +#include "p11-kit.h" #include "util.h" +#include <assert.h> #include <stdlib.h> +#include <string.h> void* xrealloc (void *memory, size_t length) @@ -48,3 +51,34 @@ xrealloc (void *memory, size_t length) free (memory); return allocated; } + +size_t +p11_kit_space_strlen (const unsigned char *string, size_t max_length) +{ + size_t i = max_length - 1; + + assert (string); + + while (i > 0 && string[i] == ' ') + --i; + return i + 1; +} + +char* +p11_kit_space_strdup (const unsigned char *string, size_t max_length) +{ + size_t length; + char *result; + + assert (string); + + length = p11_kit_space_strlen (string, max_length); + + result = malloc (length + 1); + if (!result) + return NULL; + + memcpy (result, string, length); + result[length] = 0; + return result; +} |