diff options
author | Stef Walter <stefw@gnome.org> | 2013-01-23 14:29:25 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-01-23 14:29:25 +0100 |
commit | b28c936bd281c4b7ff9ed0f621b840f6d5a4b328 (patch) | |
tree | 9645b90b794908d378970aafd73e7726c5267341 | |
parent | 4671352fe2a4f56c6707322dcab0015e2e8600c4 (diff) |
Use the stdbool.h C99 bool type
It was getting really wild knowing whether a function returning
an int would return -1 on failure or 0 or whether the int return
value was actually a number etc..
-rw-r--r-- | common/array.c | 16 | ||||
-rw-r--r-- | common/array.h | 4 | ||||
-rw-r--r-- | common/attrs.c | 12 | ||||
-rw-r--r-- | common/compat.h | 8 | ||||
-rw-r--r-- | common/debug.c | 8 | ||||
-rw-r--r-- | common/debug.h | 14 | ||||
-rw-r--r-- | common/dict.c | 41 | ||||
-rw-r--r-- | common/dict.h | 26 | ||||
-rw-r--r-- | common/library.c | 4 | ||||
-rw-r--r-- | common/tests/test-dict.c | 90 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | p11-kit/conf.c | 58 | ||||
-rw-r--r-- | p11-kit/conf.h | 6 | ||||
-rw-r--r-- | p11-kit/modules.c | 32 | ||||
-rw-r--r-- | p11-kit/pin.c | 22 | ||||
-rw-r--r-- | p11-kit/tests/conf-test.c | 19 | ||||
-rw-r--r-- | p11-kit/tests/mock-module.c | 14 | ||||
-rw-r--r-- | p11-kit/tests/uri-test.c | 41 | ||||
-rw-r--r-- | p11-kit/uri.c | 118 | ||||
-rw-r--r-- | tools/p11-kit.c | 10 |
20 files changed, 311 insertions, 234 deletions
diff --git a/common/array.c b/common/array.c index f645fd1..f2930a9 100644 --- a/common/array.c +++ b/common/array.c @@ -33,11 +33,12 @@ #include "config.h" #include "array.h" +#include "debug.h" #include <stdlib.h> #include <string.h> -static int +static bool maybe_expand_array (p11_array *array, unsigned int length) { @@ -45,19 +46,18 @@ maybe_expand_array (p11_array *array, void **new_memory; if (length <= array->allocated) - return 1; + return true; new_allocated = array->allocated + 16; if (new_allocated < length) new_allocated = length; new_memory = realloc (array->elem, new_allocated * sizeof (void*)); - if (new_memory == NULL) - return 0; + return_val_if_fail (new_memory != NULL, false); array->elem = new_memory; array->allocated = new_allocated; - return 1; + return true; } p11_array * @@ -95,16 +95,16 @@ p11_array_free (p11_array *array) free (array); } -int +bool p11_array_push (p11_array *array, void *value) { if (!maybe_expand_array (array, array->num + 1)) - return 0; + return_val_if_reached (false); array->elem[array->num] = value; array->num++; - return 1; + return true; } void diff --git a/common/array.h b/common/array.h index 6ed7866..8964b83 100644 --- a/common/array.h +++ b/common/array.h @@ -35,7 +35,7 @@ #ifndef __P11_ARRAY_H__ #define __P11_ARRAY_H__ -#include <sys/types.h> +#include "compat.h" #ifndef P11_DESTROYER_DEFINED #define P11_DESTROYER_DEFINED @@ -57,7 +57,7 @@ p11_array * p11_array_new (p11_destroyer destroyer); void p11_array_free (p11_array *array); -int p11_array_push (p11_array *array, +bool p11_array_push (p11_array *array, void *value); void p11_array_remove (p11_array *array, diff --git a/common/attrs.c b/common/attrs.c index 2f4dca7..dd91afc 100644 --- a/common/attrs.c +++ b/common/attrs.c @@ -56,7 +56,7 @@ p11_attrs_count (CK_ATTRIBUTE *attrs) CK_ULONG count; if (attrs == NULL) - return 0; + return 0UL; for (count = 0; !p11_attrs_is_empty (attrs); count++, attrs++); @@ -80,7 +80,7 @@ p11_attrs_free (void *attrs) static CK_ATTRIBUTE * attrs_build (CK_ATTRIBUTE *attrs, CK_ULONG count_to_add, - int copy, + bool copy, CK_ATTRIBUTE * (*generator) (void *), void *state) { @@ -147,14 +147,14 @@ p11_attrs_build (CK_ATTRIBUTE *attrs, CK_ULONG count; va_list va; - count = 0; + count = 0UL; va_start (va, attrs); while (va_arg (va, CK_ATTRIBUTE *)) count++; va_end (va); va_start (va, attrs); - attrs = attrs_build (attrs, count, 1, vararg_generator, va); + attrs = attrs_build (attrs, count, true, vararg_generator, va); va_end (va); return attrs; @@ -172,7 +172,7 @@ p11_attrs_buildn (CK_ATTRIBUTE *attrs, CK_ATTRIBUTE *add, CK_ULONG count) { - return attrs_build (attrs, count, 1, template_generator, &add); + return attrs_build (attrs, count, true, template_generator, &add); } CK_ATTRIBUTE * @@ -183,7 +183,7 @@ p11_attrs_take (CK_ATTRIBUTE *attrs, { CK_ATTRIBUTE attr = { type, value, length }; CK_ATTRIBUTE *add = &attr; - return attrs_build (attrs, 1, 0, template_generator, &add); + return attrs_build (attrs, 1, false, template_generator, &add); } CK_ATTRIBUTE * diff --git a/common/compat.h b/common/compat.h index 5061b9f..12b038d 100644 --- a/common/compat.h +++ b/common/compat.h @@ -39,6 +39,8 @@ #include <sys/types.h> +typedef enum { false, true } bool; + #if !defined(__cplusplus) && (__GNUC__ > 2) #define GNUC_PRINTF(x, y) __attribute__((__format__(__printf__, x, y))) #else @@ -203,4 +205,10 @@ void * memdup (void *data, #endif /* HAVE_MEMDUP */ +#ifdef HAVE_STDBOOL_H +#include <stdbool.h> +#else +typedef enum { false, true } bool; +#endif + #endif /* __COMPAT_H__ */ diff --git a/common/debug.c b/common/debug.c index cca9aaf..2728bf6 100644 --- a/common/debug.c +++ b/common/debug.c @@ -58,8 +58,8 @@ static struct DebugKey debug_keys[] = { { 0, } }; -static int debug_inited = 0; -static int debug_strict = 0; +static bool debug_inited = false; +static bool debug_strict = false; /* global variable exported in debug.h */ int p11_debug_current_flags = ~0; @@ -75,7 +75,7 @@ parse_environ_flags (void) env = getenv ("P11_KIT_STRICT"); if (env && env[0] != '\0') - debug_strict = 1; + debug_strict = true; env = getenv ("P11_KIT_DEBUG"); if (!env) @@ -117,7 +117,7 @@ void p11_debug_init (void) { p11_debug_current_flags = parse_environ_flags (); - debug_inited = 1; + debug_inited = true; } void diff --git a/common/debug.h b/common/debug.h index e4759d4..2374b6f 100644 --- a/common/debug.h +++ b/common/debug.h @@ -57,31 +57,31 @@ void p11_debug_precond (const char *format, ...) GNUC_PRINTF (1, 2); #define assert_not_reached() \ - (assert (0 && "this code should not be reached")) + (assert (false && "this code should not be reached")) #define return_val_if_fail(x, v) \ do { if (!(x)) { \ p11_debug_precond ("p11-kit: '%s' not true at %s\n", #x, __func__); \ return v; \ - } } while (0) + } } while (false) #define return_if_fail(x) \ do { if (!(x)) { \ p11_debug_precond ("p11-kit: '%s' not true at %s\n", #x, __func__); \ return; \ - } } while (0) + } } while (false) #define return_if_reached() \ do { \ p11_debug_precond ("p11-kit: shouldn't be reached at %s\n", __func__); \ return; \ - } while (0) + } while (false) #define return_val_if_reached(v) \ do { \ p11_debug_precond ("p11-kit: shouldn't be reached at %s\n", __func__); \ return v; \ - } while (0) + } while (false) #endif /* DEBUG_H */ @@ -119,10 +119,10 @@ void p11_debug_precond (const char *format, #undef p11_debug #define p11_debug(format, ...) \ - do {} while (0) + do {} while (false) #undef p11_debugging -#define p11_debugging 0 +#define p11_debugging (0) #endif /* !defined (WITH_DEBUG) */ diff --git a/common/dict.c b/common/dict.c index 2f976c1..df8c7ac 100644 --- a/common/dict.c +++ b/common/dict.c @@ -33,6 +33,7 @@ #include "config.h" +#include "debug.h" #include "dict.h" #include <sys/types.h> @@ -73,19 +74,19 @@ next_entry (p11_dictiter *iter) } -int +bool p11_dict_next (p11_dictiter *iter, void **key, void **value) { dictbucket *bucket = next_entry (iter); if (bucket == NULL) - return 0; + return false; if (key) *key = bucket->key; if (value) *value = bucket->value; - return 1; + return true; } void @@ -100,7 +101,7 @@ p11_dict_iterate (p11_dict *dict, static dictbucket ** lookup_or_create_bucket (p11_dict *dict, const void *key, - int create) + bool create) { dictbucket **bucketp; unsigned int hash; @@ -136,14 +137,14 @@ p11_dict_get (p11_dict *dict, { dictbucket **bucketp; - bucketp = lookup_or_create_bucket (dict, key, 0); + bucketp = lookup_or_create_bucket (dict, key, false); if (bucketp && *bucketp) return (void*)((*bucketp)->value); else return NULL; } -int +bool p11_dict_set (p11_dict *dict, void *key, void *val) @@ -154,7 +155,7 @@ p11_dict_set (p11_dict *dict, dictbucket **new_buckets; unsigned int num_buckets; - bucketp = lookup_or_create_bucket (dict, key, 1); + bucketp = lookup_or_create_bucket (dict, key, true); if(bucketp && *bucketp) { /* Destroy the previous key */ @@ -189,13 +190,13 @@ p11_dict_set (p11_dict *dict, } } - return 1; + return true; } - return 0; + return_val_if_reached (false); } -int +bool p11_dict_steal (p11_dict *dict, const void *key, void **stolen_key, @@ -203,7 +204,7 @@ p11_dict_steal (p11_dict *dict, { dictbucket **bucketp; - bucketp = lookup_or_create_bucket (dict, key, 0); + bucketp = lookup_or_create_bucket (dict, key, false); if (bucketp && *bucketp) { dictbucket *old = *bucketp; *bucketp = (*bucketp)->next; @@ -213,14 +214,14 @@ p11_dict_steal (p11_dict *dict, if (stolen_value) *stolen_value = old->value; free (old); - return 1; + return true; } - return 0; + return false; } -int +bool p11_dict_remove (p11_dict *dict, const void *key) { @@ -228,13 +229,13 @@ p11_dict_remove (p11_dict *dict, void *old_value; if (!p11_dict_steal (dict, key, &old_key, &old_value)) - return 0; + return false; if (dict->key_destroy_func) dict->key_destroy_func (old_key); if (dict->value_destroy_func) dict->value_destroy_func (old_value); - return 1; + return true; } void @@ -335,7 +336,7 @@ p11_dict_str_hash (const void *string) return hash; } -int +bool p11_dict_str_equal (const void *string_one, const void *string_two) { @@ -352,7 +353,7 @@ p11_dict_ulongptr_hash (const void *to_ulong) return (unsigned int)*((unsigned long*)to_ulong); } -int +bool p11_dict_ulongptr_equal (const void *ulong_one, const void *ulong_two) { @@ -368,7 +369,7 @@ p11_dict_intptr_hash (const void *to_int) return (unsigned int)*((int*)to_int); } -int +bool p11_dict_intptr_equal (const void *int_one, const void *int_two) { @@ -383,7 +384,7 @@ p11_dict_direct_hash (const void *ptr) return (unsigned int)(size_t)ptr; } -int +bool p11_dict_direct_equal (const void *ptr_one, const void *ptr_two) { diff --git a/common/dict.h b/common/dict.h index 1ba7185..e13c5d6 100644 --- a/common/dict.h +++ b/common/dict.h @@ -36,7 +36,7 @@ #ifndef P11_DICT_H_ #define P11_DICT_H_ -#include <sys/types.h> +#include "compat.h" /* * ARGUMENT DOCUMENTATION @@ -64,7 +64,7 @@ typedef struct _p11_dictiter { typedef unsigned int (*p11_dict_hasher) (const void *data); -typedef int (*p11_dict_equals) (const void *one, +typedef bool (*p11_dict_equals) (const void *one, const void *two); #ifndef P11_DESTROYER_DEFINED @@ -107,25 +107,25 @@ void* p11_dict_get (p11_dict *dict, /* * p11_dict_set: Set a value in the hash table - * - returns 1 if the entry was added properly + * - returns true if the entry was added properly */ -int p11_dict_set (p11_dict *dict, +bool p11_dict_set (p11_dict *dict, void *key, void *value); /* * p11_dict_remove: Remove a value from the hash table - * - returns 1 if the entry was found + * - returns true if the entry was found */ -int p11_dict_remove (p11_dict *dict, +bool p11_dict_remove (p11_dict *dict, const void *key); /* * p11_dict_steal: Remove a value from the hash table without calling * destroy funcs - * - returns 1 if the entry was found + * - returns true if the entry was found */ -int p11_dict_steal (p11_dict *dict, +bool p11_dict_steal (p11_dict *dict, const void *key, void **stolen_key, void **stolen_value); @@ -142,7 +142,7 @@ void p11_dict_iterate (p11_dict *dict, * - sets key and value to key and/or value * - returns whether there was another entry */ -int p11_dict_next (p11_dictiter *iter, +bool p11_dict_next (p11_dictiter *iter, void **key, void **value); @@ -157,22 +157,22 @@ void p11_dict_clear (p11_dict *dict); unsigned int p11_dict_str_hash (const void *string); -int p11_dict_str_equal (const void *string_one, +bool p11_dict_str_equal (const void *string_one, const void *string_two); unsigned int p11_dict_ulongptr_hash (const void *to_ulong); -int p11_dict_ulongptr_equal (const void *ulong_one, +bool p11_dict_ulongptr_equal (const void *ulong_one, const void *ulong_two); unsigned int p11_dict_intptr_hash (const void *to_int); -int p11_dict_intptr_equal (const void *int_one, +bool p11_dict_intptr_equal (const void *int_one, const void *int_two); unsigned int p11_dict_direct_hash (const void *ptr); -int p11_dict_direct_equal (const void *ptr_one, +bool p11_dict_direct_equal (const void *ptr_one, const void *ptr_two); #endif /* __P11_DICT_H__ */ diff --git a/common/library.c b/common/library.c index 48fd0c9..d0c246c 100644 --- a/common/library.c +++ b/common/library.c @@ -65,7 +65,7 @@ p11_mutex_t p11_library_mutex; pthread_once_t p11_library_once; #endif -static int print_messages = 1; +static bool print_messages = true; void p11_message_store (const char* msg, @@ -112,7 +112,7 @@ void p11_message_quiet (void) { p11_lock (); - print_messages = 0; + print_messages = false; p11_unlock (); } diff --git a/common/tests/test-dict.c b/common/tests/test-dict.c index 3af3daa..00b64c5 100644 --- a/common/tests/test-dict.c +++ b/common/tests/test-dict.c @@ -60,7 +60,7 @@ test_free_null (CuTest *tc) typedef struct { int value; - int freed; + bool freed; } Key; static unsigned int @@ -71,7 +71,7 @@ key_hash (const void *ptr) return p11_dict_intptr_hash (&k->value); } -static int +static bool key_equal (const void *one, const void *two) { @@ -87,7 +87,7 @@ key_destroy (void *data) { Key *k = data; assert (!k->freed); - k->freed = 1; + k->freed = true; } static void @@ -110,7 +110,7 @@ test_free_destroys (CuTest *tc) CuFail (tc, "should not be reached"); p11_dict_free (map); - CuAssertIntEquals (tc, 1, key.freed); + CuAssertIntEquals (tc, true, key.freed); CuAssertIntEquals (tc, 2, value); } @@ -166,7 +166,7 @@ test_set_get_remove (CuTest *tc) char *value = "VALUE"; char *check; p11_dict *map; - int ret; + bool ret; map = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL); @@ -177,9 +177,9 @@ test_set_get_remove (CuTest *tc) CuAssertPtrEquals (tc, check, value); ret = p11_dict_remove (map, key); - CuAssertIntEquals (tc, ret, 1); + CuAssertIntEquals (tc, true, ret); ret = p11_dict_remove (map, key); - CuAssertIntEquals (tc, ret, 0); + CuAssertIntEquals (tc, false, ret); check = p11_dict_get (map, key); CuAssert (tc, "should be null", check == NULL); @@ -214,7 +214,7 @@ test_remove_destroys (CuTest *tc) p11_dict *map; Key key = { 8, 0 }; int value = 0; - int ret; + bool ret; map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy); CuAssertPtrNotNull (tc, map); @@ -222,26 +222,26 @@ test_remove_destroys (CuTest *tc) CuFail (tc, "should not be reached"); ret = p11_dict_remove (map, &key); - CuAssertIntEquals (tc, ret, 1); - CuAssertIntEquals (tc, 1, key.freed); + CuAssertIntEquals (tc, true, ret); + CuAssertIntEquals (tc, true, key.freed); CuAssertIntEquals (tc, 2, value); /* should not be destroyed again */ - key.freed = 0; + key.freed = false; value = 0; ret = p11_dict_remove (map, &key); - CuAssertIntEquals (tc, ret, 0); - CuAssertIntEquals (tc, 0, key.freed); + CuAssertIntEquals (tc, false, ret); + CuAssertIntEquals (tc, false, key.freed); CuAssertIntEquals (tc, 0, value); /* should not be destroyed again */ - key.freed = 0; + key.freed = false; value = 0; p11_dict_free (map); - CuAssertIntEquals (tc, 0, key.freed); + CuAssertIntEquals (tc, false, key.freed); CuAssertIntEquals (tc, 0, value); } @@ -252,59 +252,64 @@ test_set_destroys (CuTest *tc) Key key = { 8, 0 }; Key key2 = { 8, 0 }; int value, value2; - int ret; + bool ret; map = p11_dict_new (key_hash, key_equal, key_destroy, value_destroy); CuAssertPtrNotNull (tc, map); if (!p11_dict_set (map, &key, &value)) CuFail (tc, "should not be reached"); - key.freed = key2.freed = value = value2 = 0; + key.freed = key2.freed = false; + value = value2 = 0; /* Setting same key and value, should not be destroyed */ ret = p11_dict_set (map, &key, &value); - CuAssertIntEquals (tc, ret, 1); - CuAssertIntEquals (tc, 0, key.freed); - CuAssertIntEquals (tc, 0, key2.freed); + CuAssertIntEquals (tc, true, ret); + CuAssertIntEquals (tc, false, key.freed); + CuAssertIntEquals (tc, false, key2.freed); CuAssertIntEquals (tc, 0, value); CuAssertIntEquals (tc, 0, value2); - key.freed = key2.freed = value = value2 = 0; + key.freed = key2.freed = false; + value = value2 = 0; /* Setting a new key same value, key should be destroyed */ ret = p11_dict_set (map, &key2, &value); - CuAssertIntEquals (tc, ret, 1); - CuAssertIntEquals (tc, 1, key.freed); - CuAssertIntEquals (tc, 0, key2.freed); + CuAssertIntEquals (tc, true, ret); + CuAssertIntEquals (tc, true, key.freed); + CuAssertIntEquals (tc, false, key2.freed); CuAssertIntEquals (tc, 0, value); CuAssertIntEquals (tc, 0, value2); - key.freed = key2.freed = value = value2 = 0; + key.freed = key2.freed = false; + value = value2 = 0; /* Setting same key, new value, value should be destroyed */ ret = p11_dict_set (map, &key2, &value2); - CuAssertIntEquals (tc, ret, 1); - CuAssertIntEquals (tc, 0, key.freed); - CuAssertIntEquals (tc, 0, key2.freed); + CuAssertIntEquals (tc, true, ret); + CuAssertIntEquals (tc, false, key.freed); + CuAssertIntEquals (tc, false, key2.freed); CuAssertIntEquals (tc, 2, value); CuAssertIntEquals (tc, 0, value2); - key.freed = key2.freed = value = value2 = 0; + key.freed = key2.freed = false; + value = value2 = 0; /* Setting new key new value, both should be destroyed */ ret = p11_dict_set (map, &key, &value); - CuAssertIntEquals (tc, ret, 1); - CuAssertIntEquals (tc, 0, key.freed); - CuAssertIntEquals (tc, 1, key2.freed); + CuAssertIntEquals (tc, true, ret); + CuAssertIntEquals (tc, false, key.freed); + CuAssertIntEquals (tc, true, key2.freed); CuAssertIntEquals (tc, 0, value); CuAssertIntEquals (tc, 2, value2); - key.freed = key2.freed = value = value2 = 0; + key.freed = key2.freed = false; + value = value2 = 0; p11_dict_free (map); - CuAssertIntEquals (tc, 1, key.freed); + CuAssertIntEquals (tc, true, key.freed); CuAssertIntEquals (tc, 2, value); - CuAssertIntEquals (tc, 0, key2.freed); + CuAssertIntEquals (tc, false, key2.freed); CuAssertIntEquals (tc, 0, value2); } @@ -322,24 +327,24 @@ test_clear_destroys (CuTest *tc) CuFail (tc, "should not be reached"); p11_dict_clear (map); - CuAssertIntEquals (tc, 1, key.freed); + CuAssertIntEquals (tc, true, key.freed); CuAssertIntEquals (tc, 2, value); /* should not be destroyed again */ - key.freed = 0; + key.freed = false; value = 0; p11_dict_clear (map); - CuAssertIntEquals (tc, 0, key.freed); + CuAssertIntEquals (tc, false, key.freed); CuAssertIntEquals (tc, 0, value); /* should not be destroyed again */ - key.freed = 0; + key.freed = false; value = 0; p11_dict_free (map); - CuAssertIntEquals (tc, 0, key.freed); + CuAssertIntEquals (tc, false, key.freed); CuAssertIntEquals (tc, 0, value); } @@ -381,7 +386,8 @@ test_hash_count (CuTest *tc) { p11_dict *map; int *value; - int i, ret; + int i; + bool ret; map = p11_dict_new (p11_dict_intptr_hash, p11_dict_intptr_equal, NULL, free); @@ -397,7 +403,7 @@ test_hash_count (CuTest *tc) for (i = 0; i < 20000; ++i) { ret = p11_dict_remove (map, &i); - CuAssertIntEquals (tc, 1, ret); + CuAssertIntEquals (tc, true, ret); CuAssertIntEquals (tc, 20000 - (i + 1), p11_dict_size (map)); } diff --git a/configure.ac b/configure.ac index a4d2857..2593d9a 100644 --- a/configure.ac +++ b/configure.ac @@ -68,7 +68,7 @@ if test "$os_unix" = "yes"; then AC_SEARCH_LIBS([nanosleep], [rt], [], [AC_MSG_ERROR([could not find nanosleep])]) AC_CHECK_MEMBERS([struct dirent.d_type],,,[#include <dirent.h>]) - AC_CHECK_HEADERS([err.h errno.h]) + AC_CHECK_HEADERS([err.h errno.h stdbool.h]) AC_CHECK_FUNCS([getprogname getexecname memdup]) # Check if these are declared and/or available to link against diff --git a/p11-kit/conf.c b/p11-kit/conf.c index 1d92942..45b1404 100644 --- a/p11-kit/conf.c +++ b/p11-kit/conf.c @@ -222,7 +222,7 @@ read_config_file (const char* filename, int flags) return config; } -int +bool _p11_conf_merge_defaults (p11_dict *map, p11_dict *defaults) { @@ -236,14 +236,14 @@ _p11_conf_merge_defaults (p11_dict *map, if (p11_dict_get (map, key)) continue; key = strdup (key); - return_val_if_fail (key != NULL, -1); + return_val_if_fail (key != NULL, false); value = strdup (value); - return_val_if_fail (key != NULL, -1); + return_val_if_fail (key != NULL, false); if (!p11_dict_set (map, key, value)) - return_val_if_reached (-1); + return_val_if_reached (false); } - return 0; + return true; } p11_dict * @@ -441,7 +441,7 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf, /* If merging, then supplement user config with system values */ if (mode == CONF_USER_MERGE) { - if (_p11_conf_merge_defaults (uconfig, config) < 0) { + if (!_p11_conf_merge_defaults (uconfig, config)) { error = errno; goto finished; } @@ -509,7 +509,7 @@ calc_name_from_filename (const char *fname) return name; } -static int +static bool load_config_from_file (const char *configfile, const char *name, p11_dict *configs, @@ -526,22 +526,22 @@ load_config_from_file (const char *configfile, if (key == NULL) { p11_message ("invalid config filename, will be ignored in the future: %s", configfile); key = strdup (name); - return_val_if_fail (key != NULL, -1); + return_val_if_fail (key != NULL, false); } config = _p11_conf_parse_file (configfile, flags); if (!config) { free (key); - return -1; + return false; } prev = p11_dict_get (configs, key); if (prev == NULL) { if (!p11_dict_set (configs, key, config)) - return_val_if_reached (-1); + return_val_if_reached (false); config = NULL; } else { - if (_p11_conf_merge_defaults (prev, config) < 0) + if (!_p11_conf_merge_defaults (prev, config)) error = errno; free (key); } @@ -551,13 +551,13 @@ load_config_from_file (const char *configfile, if (error) { errno = error; - return -1; + return false; } - return 0; + return true; } -static int +static bool load_configs_from_directory (const char *directory, p11_dict *configs, int flags) @@ -566,7 +566,7 @@ load_configs_from_directory (const char *directory, struct stat st; DIR *dir; int error = 0; - int is_dir; + bool is_dir; char *path; int count = 0; @@ -579,24 +579,24 @@ load_configs_from_directory (const char *directory, if ((flags & CONF_IGNORE_MISSING) && (errno == ENOENT || errno == ENOTDIR)) { p11_debug ("module configs do not exist"); - return 0; + return true; } else if ((flags & CONF_IGNORE_ACCESS_DENIED) && (errno == EPERM || errno == EACCES)) { p11_debug ("couldn't list inacessible module configs"); - return 0; + return true; } p11_message ("couldn't list directory: %s: %s", directory, strerror (error)); errno = error; - return -1; + return false; } /* We're within a global mutex, so readdir is safe */ while ((dp = readdir(dir)) != NULL) { path = strconcat (directory, "/", dp->d_name, NULL); - return_val_if_fail (path != NULL, -1); + return_val_if_fail (path != NULL, false); - is_dir = 0; + is_dir = false; #ifdef HAVE_STRUCT_DIRENT_D_TYPE if(dp->d_type != DT_UNKNOWN) { is_dir = (dp->d_type == DT_DIR); @@ -612,7 +612,7 @@ load_configs_from_directory (const char *directory, is_dir = S_ISDIR (st.st_mode); } - if (!is_dir && load_config_from_file (path, dp->d_name, configs, flags) < 0) { + if (!is_dir && !load_config_from_file (path, dp->d_name, configs, flags)) { error = errno; free (path); break; @@ -626,10 +626,10 @@ load_configs_from_directory (const char *directory, if (error) { errno = error; - return -1; + return false; } - return count; + return true; } p11_dict * @@ -650,7 +650,7 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir) path = expand_user_path (user_dir); if (!path) error = errno; - else if (load_configs_from_directory (path, configs, flags) < 0) + else if (!load_configs_from_directory (path, configs, flags)) error = errno; free (path); if (error != 0) { @@ -667,7 +667,7 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir) */ if (mode != CONF_USER_ONLY) { flags = CONF_IGNORE_MISSING; - if (load_configs_from_directory (system_dir, configs, flags) < 0) { + if (!load_configs_from_directory (system_dir, configs, flags)) { error = errno; p11_dict_free (configs); errno = error; @@ -678,17 +678,17 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir) return configs; } -int +bool _p11_conf_parse_boolean (const char *string, - int default_value) + bool default_value) { if (!string) return default_value; if (strcmp (string, "yes") == 0) { - return 1; + return true; } else if (strcmp (string, "no") == 0) { - return 0; + return false; } else { p11_message ("invalid setting '%s' defaulting to '%s'", string, default_value ? "yes" : "no"); diff --git a/p11-kit/conf.h b/p11-kit/conf.h index b70666d..3895b0c 100644 --- a/p11-kit/conf.h +++ b/p11-kit/conf.h @@ -50,7 +50,7 @@ enum { CONF_USER_ONLY }; -int _p11_conf_merge_defaults (p11_dict *config, +bool _p11_conf_merge_defaults (p11_dict *config, p11_dict *defaults); /* Returns a hash of char *key -> char *value */ @@ -67,7 +67,7 @@ p11_dict * _p11_conf_load_modules (int user_mode, const char *system_dir, const char *user_dir); -int _p11_conf_parse_boolean (const char *string, - int default_value); +bool _p11_conf_parse_boolean (const char *string, + bool default_value); #endif /* __CONF_H__ */ diff --git a/p11-kit/modules.c b/p11-kit/modules.c index e4b0f66..292bf28 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -109,7 +109,7 @@ typedef struct _Module { /* Initialization, mutex must be held */ p11_mutex_t initialize_mutex; - int initialize_called; + bool initialize_called; p11_thread_id_t initialize_thread; } Module; @@ -183,7 +183,7 @@ free_module_unlocked (void *data) assert (mod != NULL); /* Module must be finalized */ - assert (mod->initialize_called == 0); + assert (!mod->initialize_called); assert (mod->initialize_thread == 0); /* Module must have no outstanding references */ @@ -336,7 +336,7 @@ is_list_delimiter (char ch) return ch == ',' || isspace (ch); } -static int +static bool is_string_in_list (const char *list, const char *string) { @@ -344,31 +344,31 @@ is_string_in_list (const char *list, where = strstr (list, string); if (where == NULL) - return 0; + return false; /* Has to be at beginning/end of string, and delimiter before/after */ if (where != list && !is_list_delimiter (*(where - 1))) - return 0; + return false; where += strlen (string); return (*where == '\0' || is_list_delimiter (*where)); } -static int +static bool is_module_enabled_unlocked (const char *name, p11_dict *config) { const char *progname; const char *enable_in; const char *disable_in; - int enable = 0; + bool enable = false; enable_in = p11_dict_get (config, "enable-in"); disable_in = p11_dict_get (config, "disable-in"); /* Defaults to enabled if neither of these are set */ if (!enable_in && !disable_in) - return 1; + return true; progname = _p11_get_progname_unlocked (); if (enable_in && disable_in) @@ -475,7 +475,7 @@ load_registered_modules_unlocked (void) p11_dict *config; int mode; CK_RV rv; - int critical; + bool critical; if (gl.config) return CKR_OK; @@ -508,7 +508,7 @@ load_registered_modules_unlocked (void) assert_not_reached (); /* Is this a critical module, should abort loading of others? */ - critical = _p11_conf_parse_boolean (p11_dict_get (config, "critical"), 0); + critical = _p11_conf_parse_boolean (p11_dict_get (config, "critical"), false); rv = take_config_and_load_module_unlocked (&name, &config); @@ -575,7 +575,7 @@ initialize_module_unlocked_reentrant (Module *mod) /* Module was initialized and C_Finalize should be called */ if (rv == CKR_OK) - mod->initialize_called = 1; + mod->initialize_called = true; /* Module was already initialized, we don't call C_Finalize */ else if (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED) @@ -608,7 +608,7 @@ reinitialize_after_fork (void) if (gl.modules) { p11_dict_iterate (gl.modules, &iter); while (p11_dict_next (&iter, NULL, (void **)&mod)) - mod->initialize_called = 0; + mod->initialize_called = false; } p11_unlock (); @@ -621,7 +621,7 @@ reinitialize_after_fork (void) static CK_RV init_globals_unlocked (void) { - static int once = 0; + static bool once = false; if (!gl.modules) { gl.modules = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, @@ -635,7 +635,7 @@ init_globals_unlocked (void) #ifdef OS_UNIX pthread_atfork (NULL, NULL, reinitialize_after_fork); #endif - once = 1; + once = true; return CKR_OK; } @@ -689,7 +689,7 @@ finalize_module_unlocked_reentrant (Module *mod) assert (mod->funcs); mod->funcs->C_Finalize (NULL); - mod->initialize_called = 0; + mod->initialize_called = false; } p11_mutex_unlock (&mod->initialize_mutex); @@ -748,7 +748,7 @@ _p11_kit_initialize_registered_unlocked_reentrant (void) p11_message ("failed to initialize module: %s: %s", mod->name, p11_kit_strerror (rv)); - critical = _p11_conf_parse_boolean (p11_dict_get (mod->config, "critical"), 0); + critical = _p11_conf_parse_boolean (p11_dict_get (mod->config, "critical"), false); if (!critical) { p11_debug ("ignoring failure, non-critical module: %s", mod->name); rv = CKR_OK; diff --git a/p11-kit/pin.c b/p11-kit/pin.c index a8be64b..bb65e4c 100644 --- a/p11-kit/pin.c +++ b/p11-kit/pin.c @@ -170,7 +170,7 @@ unref_pin_callback (void *pointer) } } -static int +static bool register_callback_unlocked (const char *pin_source, PinCallback *cb) { @@ -178,12 +178,12 @@ register_callback_unlocked (const char *pin_source, char *name; name = strdup (pin_source); - return_val_if_fail (name != NULL, -1); + return_val_if_fail (name != NULL, false); if (gl.pin_sources == NULL) { gl.pin_sources = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, free, (p11_destroyer)p11_array_free); - return_val_if_fail (gl.pin_sources != NULL, -1); + return_val_if_fail (gl.pin_sources != NULL, false); } if (gl.pin_sources != NULL) @@ -191,15 +191,15 @@ register_callback_unlocked (const char *pin_source, if (callbacks == NULL) { callbacks = p11_array_new (unref_pin_callback); - return_val_if_fail (callbacks != NULL, -1); + return_val_if_fail (callbacks != NULL, false); if (!p11_dict_set (gl.pin_sources, name, callbacks)) - return_val_if_reached (-1); + return_val_if_reached (false); } - if (p11_array_push (callbacks, cb) < 0) - return_val_if_reached (-1); + if (!p11_array_push (callbacks, cb)) + return_val_if_reached (false); - return 0; + return true; } /** @@ -227,7 +227,7 @@ p11_kit_pin_register_callback (const char *pin_source, p11_kit_pin_destroy_func callback_destroy) { PinCallback *cb; - int ret; + bool ret; return_val_if_fail (pin_source != NULL, -1); return_val_if_fail (callback != NULL, -1); @@ -246,7 +246,7 @@ p11_kit_pin_register_callback (const char *pin_source, p11_unlock (); - return ret; + return ret ? 0 : -1; } /** @@ -685,7 +685,7 @@ p11_kit_pin_ref (P11KitPin *pin) void p11_kit_pin_unref (P11KitPin *pin) { - int last = 0; + bool last = false; p11_lock (); diff --git a/p11-kit/tests/conf-test.c b/p11-kit/tests/conf-test.c index ab3b31d..704313d 100644 --- a/p11-kit/tests/conf-test.c +++ b/p11-kit/tests/conf-test.c @@ -107,7 +107,7 @@ test_merge_defaults (CuTest *tc) p11_dict_set (defaults, strdup ("two"), strdup ("default2")); p11_dict_set (defaults, strdup ("three"), strdup ("default3")); - if (_p11_conf_merge_defaults (values, defaults) < 0) + if (!_p11_conf_merge_defaults (values, defaults)) CuFail (tc, "should not be reached"); p11_dict_free (defaults); @@ -247,13 +247,11 @@ test_load_globals_user_sets_invalid (CuTest *tc) p11_dict_free (config); } -static int +static bool assert_msg_contains (const char *msg, const char *text) { - if (msg == NULL) - return 0; - return strstr (msg, text) ? 1 : 0; + return (msg && strstr (msg, text)) ? true : false; } static void @@ -378,6 +376,16 @@ test_load_modules_no_user (CuTest *tc) p11_dict_free (configs); } +static void +test_parse_boolean (CuTest *tc) +{ + p11_message_quiet (); + + CuAssertIntEquals (tc, true, _p11_conf_parse_boolean ("yes", false)); + CuAssertIntEquals (tc, false, _p11_conf_parse_boolean ("no", true)); + CuAssertIntEquals (tc, true, _p11_conf_parse_boolean ("!!!", true)); +} + int main (void) { @@ -402,6 +410,7 @@ main (void) SUITE_ADD_TEST (suite, test_load_modules_no_user); SUITE_ADD_TEST (suite, test_load_modules_user_only); SUITE_ADD_TEST (suite, test_load_modules_user_none); + SUITE_ADD_TEST (suite, test_parse_boolean); p11_kit_be_quiet (); diff --git a/p11-kit/tests/mock-module.c b/p11-kit/tests/mock-module.c index 1a74806..15db600 100644 --- a/p11-kit/tests/mock-module.c +++ b/p11-kit/tests/mock-module.c @@ -53,7 +53,7 @@ static p11_mutex_t init_mutex; /* Whether we've been initialized, and on what process id it happened */ -static int pkcs11_initialized = 0; +static bool pkcs11_initialized = false; static pid_t pkcs11_initialized_pid = 0; /* ----------------------------------------------------------------------------- @@ -141,10 +141,10 @@ mock_C_Initialize (CK_VOID_PTR init_args) done: /* Mark us as officially initialized */ if (ret == CKR_OK) { - pkcs11_initialized = 1; + pkcs11_initialized = true; pkcs11_initialized_pid = pid; } else if (ret != CKR_CRYPTOKI_ALREADY_INITIALIZED) { - pkcs11_initialized = 0; + pkcs11_initialized = false; pkcs11_initialized_pid = 0; } @@ -158,13 +158,13 @@ CK_RV mock_C_Finalize (CK_VOID_PTR reserved) { debug (("C_Finalize: enter")); - return_val_if_fail (pkcs11_initialized != 0, CKR_CRYPTOKI_NOT_INITIALIZED); + return_val_if_fail (pkcs11_initialized, CKR_CRYPTOKI_NOT_INITIALIZED); return_val_if_fail (reserved == NULL, CKR_ARGUMENTS_BAD); p11_mutex_lock (&init_mutex); /* This should stop all other calls in */ - pkcs11_initialized = 0; + pkcs11_initialized = false; pkcs11_initialized_pid = 0; p11_mutex_unlock (&init_mutex); @@ -890,9 +890,9 @@ CK_FUNCTION_LIST mock_module_no_slots = { void mock_module_init (void) { - static int initialized = 0; + static bool initialized = false; if (!initialized) { p11_mutex_init (&init_mutex); - initialized = 1; + initialized = true; } } diff --git a/p11-kit/tests/uri-test.c b/p11-kit/tests/uri-test.c index 1920412..11fdebe 100644 --- a/p11-kit/tests/uri-test.c +++ b/p11-kit/tests/uri-test.c @@ -210,18 +210,18 @@ test_uri_parse_with_bad_hex_encoding (CuTest *tc) p11_kit_uri_free (uri); } -static int +static bool is_space_string (CK_UTF8CHAR_PTR string, CK_ULONG size, const char *check) { size_t i, len = strlen (check); if (len > size) - return 0; + return false; if (memcmp (string, check, len) != 0) - return 0; + return false; for (i = len; i < size; ++i) if (string[i] != ' ') - return 0; - return 1; + return false; + return true; } static void @@ -909,6 +909,36 @@ test_uri_match_module (CuTest *tc) } static void +test_uri_match_version (CuTest *tc) +{ + CK_INFO info; + P11KitUri *uri; + int ret; + + memset (&info, 0, sizeof (info)); + + uri = p11_kit_uri_new (); + CuAssertPtrNotNull (tc, uri); + + ret = p11_kit_uri_parse ("pkcs11:library-version=5.8", P11_KIT_URI_FOR_ANY, uri); + CuAssertIntEquals (tc, P11_KIT_URI_OK, ret); + + info.libraryVersion.major = 5; + info.libraryVersion.minor = 8; + + ret = p11_kit_uri_match_module_info (uri, &info); + CuAssertIntEquals (tc, 1, ret); + + info.libraryVersion.major = 2; + info.libraryVersion.minor = 3; + + ret = p11_kit_uri_match_module_info (uri, &info); + CuAssertIntEquals (tc, 0, ret); + + p11_kit_uri_free (uri); +} + +static void test_uri_match_attributes (CuTest *tc) { CK_ATTRIBUTE attrs[4]; @@ -1208,6 +1238,7 @@ main (void) SUITE_ADD_TEST (suite, test_uri_get_set_unrecognized); SUITE_ADD_TEST (suite, test_uri_match_token); SUITE_ADD_TEST (suite, test_uri_match_module); + SUITE_ADD_TEST (suite, test_uri_match_version); SUITE_ADD_TEST (suite, test_uri_match_attributes); SUITE_ADD_TEST (suite, test_uri_get_set_attribute); SUITE_ADD_TEST (suite, test_uri_get_set_attributes); diff --git a/p11-kit/uri.c b/p11-kit/uri.c index 8828188..9678358 100644 --- a/p11-kit/uri.c +++ b/p11-kit/uri.c @@ -136,7 +136,7 @@ */ struct p11_kit_uri { - int unrecognized; + bool unrecognized; CK_INFO module; CK_TOKEN_INFO token; CK_ATTRIBUTE *attrs; @@ -202,8 +202,11 @@ url_decode (const char *value, const char *end, return P11_KIT_URI_OK; } -static char* -url_encode (const unsigned char *value, const unsigned char *end, size_t *length, int force) +static char * +url_encode (const unsigned char *value, + const unsigned char *end, + size_t *length, + bool force) { char *p; char *result; @@ -262,7 +265,7 @@ key_decode (const char *value, const char *end) return key; } -static int +static bool match_struct_string (const unsigned char *inuri, const unsigned char *real, size_t length) { @@ -272,19 +275,19 @@ match_struct_string (const unsigned char *inuri, const unsigned char *real, /* NULL matches anything */ if (inuri[0] == 0) - return 1; + return true; - return memcmp (inuri, real, length) == 0 ? 1 : 0; + return memcmp (inuri, real, length) == 0 ? true : false; } -static int +static bool match_struct_version (CK_VERSION_PTR inuri, CK_VERSION_PTR real) { /* This matches anything */ if (inuri->major == (CK_BYTE)-1 && inuri->minor == (CK_BYTE)-1) - return 1; + return true; - return memcmp (inuri, real, sizeof (CK_VERSION)); + return memcmp (inuri, real, sizeof (CK_VERSION)) == 0 ? true : false; } /** @@ -594,7 +597,7 @@ void p11_kit_uri_set_unrecognized (P11KitUri *uri, int unrecognized) { return_if_fail (uri != NULL); - uri->unrecognized = unrecognized; + uri->unrecognized = unrecognized ? true : false; } /** @@ -700,22 +703,25 @@ p11_kit_uri_new (void) return uri; } -static int -format_raw_string (char **string, size_t *length, int *is_first, - const char *name, const char *value) +static bool +format_raw_string (char **string, + size_t *length, + bool *is_first, + const char *name, + const char *value) { size_t namelen; size_t vallen; /* Not set */ if (!value) - return 1; + return true; namelen = strlen (name); vallen = strlen (value); *string = realloc (*string, *length + namelen + vallen + 3); - return_val_if_fail (*string != NULL, 0); + return_val_if_fail (*string != NULL, false); if (!*is_first) (*string)[(*length)++] = ';'; @@ -725,21 +731,25 @@ format_raw_string (char **string, size_t *length, int *is_first, memcpy ((*string) + *length, value, vallen); *length += vallen; (*string)[*length] = 0; - *is_first = 0; + *is_first = false; - return 1; + return true; } -static int -format_encode_string (char **string, size_t *length, int *is_first, - const char *name, const unsigned char *value, - size_t n_value, int force) +static bool +format_encode_string (char **string, + size_t *length, + bool *is_first, + const char *name, + const unsigned char *value, + size_t n_value, + bool force) { char *encoded; - int ret; + bool ret; encoded = url_encode (value, value + n_value, NULL, force); - return_val_if_fail (encoded != NULL, 0); + return_val_if_fail (encoded != NULL, false); ret = format_raw_string (string, length, is_first, name, encoded); free (encoded); @@ -747,45 +757,54 @@ format_encode_string (char **string, size_t *length, int *is_first, } -static int -format_struct_string (char **string, size_t *length, int *is_first, - const char *name, const unsigned char *value, +static bool +format_struct_string (char **string, + size_t *length, + bool *is_first, + const char *name, + const unsigned char *value, size_t value_max) { size_t len; /* Not set */ if (!value[0]) - return 1; + return true; len = p11_kit_space_strlen (value, value_max); - return format_encode_string (string, length, is_first, name, value, len, 0); + return format_encode_string (string, length, is_first, name, value, len, false); } -static int -format_attribute_string (char **string, size_t *length, int *is_first, - const char *name, CK_ATTRIBUTE_PTR attr, - int force) +static bool +format_attribute_string (char **string, + size_t *length, + bool *is_first, + const char *name, + CK_ATTRIBUTE_PTR attr, + bool force) { /* Not set */; if (attr == NULL) - return 1; + return true; return format_encode_string (string, length, is_first, name, attr->pValue, attr->ulValueLen, force); } -static int -format_attribute_class (char **string, size_t *length, int *is_first, - const char *name, CK_ATTRIBUTE_PTR attr) +static bool +format_attribute_class (char **string, + size_t *length, + bool *is_first, + const char *name, + CK_ATTRIBUTE_PTR attr) { CK_OBJECT_CLASS klass; const char *value; /* Not set */; if (attr == NULL) - return 1; + return true; klass = *((CK_OBJECT_CLASS*)attr->pValue); switch (klass) { @@ -805,21 +824,24 @@ format_attribute_class (char **string, size_t *length, int *is_first, value = "private"; break; default: - return 1; + return true; } return format_raw_string (string, length, is_first, name, value); } -static int -format_struct_version (char **string, size_t *length, int *is_first, - const char *name, CK_VERSION_PTR version) +static bool +format_struct_version (char **string, + size_t *length, + bool *is_first, + const char *name, + CK_VERSION_PTR version) { char buffer[64]; /* Not set */ if (version->major == (CK_BYTE)-1 && version->minor == (CK_BYTE)-1) - return 1; + return true; snprintf (buffer, sizeof (buffer), "%d.%d", (int)version->major, (int)version->minor); @@ -859,7 +881,7 @@ p11_kit_uri_format (P11KitUri *uri, P11KitUriType uri_type, char **string) { char *result = NULL; size_t length = 0; - int is_first = 1; + bool is_first = true; return_val_if_fail (uri != NULL, P11_KIT_URI_UNEXPECTED); return_val_if_fail (string != NULL, P11_KIT_URI_UNEXPECTED); @@ -910,10 +932,10 @@ p11_kit_uri_format (P11KitUri *uri, P11KitUriType uri_type, char **string) if ((uri_type & P11_KIT_URI_FOR_OBJECT) == P11_KIT_URI_FOR_OBJECT) { if (!format_attribute_string (&result, &length, &is_first, "id", p11_kit_uri_get_attribute (uri, CKA_ID), - 1) || + true) || !format_attribute_string (&result, &length, &is_first, "object", p11_kit_uri_get_attribute (uri, CKA_LABEL), - 0)) { + false)) { return_val_if_reached (P11_KIT_URI_UNEXPECTED); } @@ -992,7 +1014,7 @@ parse_class_attribute (const char *name, const char *start, const char *end, klass = CKO_DATA; else { free (value); - uri->unrecognized = 1; + uri->unrecognized = true; return 1; } @@ -1026,7 +1048,7 @@ parse_struct_info (unsigned char *where, size_t length, const char *start, /* Too long, shouldn't match anything */ if (value_length > length) { free (value); - uri->unrecognized = 1; + uri->unrecognized = true; return 1; } @@ -1266,7 +1288,7 @@ p11_kit_uri_parse (const char *string, P11KitUriType uri_type, if (ret < 0) return ret; if (ret == 0) - uri->unrecognized = 1; + uri->unrecognized = true; if (*spos == '\0') break; diff --git a/tools/p11-kit.c b/tools/p11-kit.c index 5bb31ca..f789fb8 100644 --- a/tools/p11-kit.c +++ b/tools/p11-kit.c @@ -47,7 +47,7 @@ #include "p11-kit/uri.h" typedef int (*operation) (int argc, char *argv[]); -int verbose = 0; +bool verbose = false; static void usage (void) @@ -82,7 +82,7 @@ hex_encode (const unsigned char *data, return result; } -static int +static bool is_ascii_string (const unsigned char *data, size_t n_data) { @@ -91,10 +91,10 @@ is_ascii_string (const unsigned char *data, for (i = 0; i < n_data; i++) { if (!isascii (data[i]) && (data[i] < 0x20 && !isspace (data[i]))) - return 0; + return false; } - return 1; + return true; } static void @@ -253,7 +253,7 @@ main (int argc, char *argv[]) oper = list_modules; break; case 'v': - verbose = 1; + verbose = true; putenv ("P11_KIT_DEBUG=all"); break; case 'h': |