error_map.h revision 13132:9615cdbf7b70
1/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. */ 2/* 3 * This file is generated, please don't edit it. 4 * script: ./../../../util/gen-map.pl 5 * args: 6 * -oerror_map.new 7 * NAME=gsserrmap 8 * KEY=OM_uint32 9 * VALUE=char * 10 * COMPARE=compare_OM_uint32 11 * FREEVALUE=free_string 12 * The rest of this file is copied from a template, with 13 * substitutions. See the template for copyright info. 14 */ 15/* 16 * map, generated from template 17 * map name: gsserrmap 18 * key: OM_uint32 19 * value: char * 20 * compare: compare_OM_uint32 21 * copy_key: 0 22 * free_key: 0 23 * free_value: free_string 24 */ 25struct gsserrmap__element { 26 OM_uint32 key; 27 char * value; 28 struct gsserrmap__element *next; 29}; 30struct gsserrmap__head { 31 struct gsserrmap__element *first; 32}; 33typedef struct gsserrmap__head gsserrmap; 34static inline int gsserrmap_init (struct gsserrmap__head *head) 35{ 36 head->first = NULL; 37 return 0; 38} 39static inline void gsserrmap_destroy (struct gsserrmap__head *head) 40{ 41 struct gsserrmap__element *e, *e_next; 42 void (*free_key)(OM_uint32) = 0; 43 void (*free_value)(char *) = free_string; 44 for (e = head->first; e; e = e_next) { 45 e_next = e->next; 46 if (free_key) 47 (*free_key)(e->key); 48 if (free_value) 49 (*free_value)(e->value); 50 free(e); 51 } 52 head->first = NULL; 53} 54/* Returns pointer to linked-list entry, or null if key not found. */ 55static inline struct gsserrmap__element * 56gsserrmap__find_node (struct gsserrmap__head *head, OM_uint32 key) 57{ 58 struct gsserrmap__element *e; 59 for (e = head->first; e; e = e->next) 60 if (compare_OM_uint32 (key, e->key) == 0) 61 return e; 62 return 0; 63} 64/* Returns pointer to value, or null if key not found. */ 65static inline char * * 66gsserrmap_find (struct gsserrmap__head *head, OM_uint32 key) 67{ 68 struct gsserrmap__element *e = gsserrmap__find_node(head, key); 69 if (e) 70 return &e->value; 71 return 0; 72} 73/* Returns 0 or error code. */ 74static inline int 75gsserrmap__copy_key (OM_uint32 *out, OM_uint32 in) 76{ 77 int (*copykey)(OM_uint32 *, OM_uint32) = 0; 78 if (copykey == 0) { 79 *out = in; 80 return 0; 81 } else 82 return (*copykey)(out, in); 83} 84/* Returns 0 or error code. */ 85static inline int 86gsserrmap_replace_or_insert (struct gsserrmap__head *head, 87 OM_uint32 key, char * new_value) 88{ 89 struct gsserrmap__element *e = gsserrmap__find_node(head, key); 90 int ret; 91 92 if (e) { 93 /* replace */ 94 void (*free_value)(char *) = free_string; 95 if (free_value) 96 (*free_value)(e->value); 97 e->value = new_value; 98 } else { 99 /* insert */ 100 e = malloc(sizeof(*e)); 101 if (e == NULL) 102 return ENOMEM; 103 ret = gsserrmap__copy_key (&e->key, key); 104 if (ret) { 105 free(e); 106 return ret; 107 } 108 e->value = new_value; 109 e->next = head->first; 110 head->first = e; 111 } 112 return 0; 113} 114