free(node);
}
-void
+/*
+ * conff_add_key
+ *
+ * returns 0 if the key was successfully added
+ */
+
+int
conff_add_key(struct conff_node **ptr, char *key, char *value, int flags)
{
struct conff_node *new_item, *next = NULL;
+ int replace = 0;
assert(key != NULL && value != NULL);
for(; *ptr; ptr = &( (*ptr) -> next) )
if(!strcasecmp(key, (*ptr) -> key ) ) {
if (flags & REPLACE_KEY) {
- next = (*ptr) -> next;
- conff_free_node(*ptr);
+ replace = 1;
break;
} else
- return;
+ return 1;
}
- /*
- * out of memory - error is ignored
- * NOTE: with REPLACE_KEY flag the node will be deleted in OOM
- * situation
- */
if( (new_item = malloc(sizeof(struct conff_node))) == NULL )
- return;
-
+ return 5;
+
+ if(replace) {
+ next = (*ptr) -> next;
+ conff_free_node(*ptr);
+ }
+
new_item -> key = strdup(key);
new_item -> value = strdup(value);
new_item -> next = next;
*ptr = new_item;
+
+ return 0;
}
char *
char *line = NULL, *tmp;
int i = 0;
+ assert(filename != NULL);
+
if (!(in = fopen(filename, "r")))
return -1;
};
-void conff_add_key(struct conff_node **ptr, char *key,
+int conff_add_key(struct conff_node **ptr, char *key,
char *value, int flags);
char *conff_get_value(struct conff_node *node, char *key);
#ifdef DEBUG
{
char *s, *s2;
+ assert(str != NULL);
+
s = s2 = strdup(str);
while( *str )
{
char *tmp = str;
+ assert(str != NULL);
+
while( ( *str = toupper( *str ) ) )
str++;
{
char *tmp = str;
+ assert(str != NULL);
+
while( ( *str = tolower ( *str ) ) )
str++;
(char *) malloc (size);
#endif
+ assert(format != NULL);
+
for(;;) {
int n;
MY_VA_START(format);
MY_VA_LOCAL_DECL;
char *s, *concat;
- if(str == NULL)
- return NULL;
+ assert(str != NULL);
l = 1 + strlen (str);
MY_VA_START(str);
char *dir = NULL;
int size = 100;
- dir = malloc(size);
+ if( (dir = malloc(size)) == NULL)
+ return NULL;
while( getcwd(dir, size) == NULL && errno == ERANGE )
- dir = realloc(dir, size *=2);
+ if( (dir = realloc(dir, size *=2)) == NULL)
+ return NULL;
return dir;
}
* parameters:
* (char *str)
* if n >= 0 str is a pointer which points a place where to store
- * the string, else str is ingnored
+ * the string, else str is ignored
* (int n)
* the maximum length of the string
* If n < 0 function will allocate needed space for the string.