/* * Secure X Message Passing Library v2 implementation. * (sxmplv2) it superseed all versions before due to the: * - memory consumption * - new features such as pulse emitting * - performance optimization * * (c) Askele Group 2013-2015 * (c) Alexander Vdolainen 2013-2015,2016 * * libsxmp is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * libsxmp is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see ."; * */ #include #include #include #include #include #include #include #include #include #include #include #include #include list_head_t *sxstream_generic_slist_alloc(void) { list_head_t *list = malloc(sizeof(list_head_t)); if(list) list_init_head(list); return list; } void sxstream_generic_slist_free(list_head_t *list) { struct _nn_stream_entry_node *entry; list_node_t *iter, *siter; list_for_each_safe(list, iter, siter) { entry = list_entry(iter, struct _nn_stream_entry_node, node); list_del(iter); free(entry->value); free(entry); } free(list); return; } int sxstream_generic_slist_additem(list_head_t *list, const char *value) { struct _nn_stream_entry_node *entry = malloc(sizeof(struct _nn_stream_entry_node)); size_t value_len = 0; if(!entry) return -1; if(!value) { __enomem: free(entry); return -1; } else value_len = strlen(value) + 3*sizeof(char); /* additional nil and two underscopes */ if(!(entry->value = malloc(value_len))) goto __enomem; else snprintf(entry->value, value_len, "\"%s\"", value); list_init_node(&entry->node); list_add2tail(list, &entry->node); return 0; }