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/util.c | |
parent | b315f99c90d01104d6baa91ca0f2cfb32c920abd (diff) | |
download | p11-kit-b9a8a140cf09780671402e872130a51ec4f4b014.tar.gz |
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/util.c')
-rw-r--r-- | p11-kit/util.c | 34 |
1 files changed, 34 insertions, 0 deletions
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; +} |