/** * @brief Create and initilize AVL tree for environment variables * in global variable called "env_avltree" * * @return void * * @retval None */ void create_env_avltree() { int i = 0; char varname_tmp[_MAX_ENV] = {'\0'}; char *name = NULL; char *value = NULL; AVL_IX_REC *pe = NULL; extern char **environ; if (env_avltree == NULL) { if ((env_avltree = malloc(sizeof(AVL_IX_DESC))) != NULL) { avl_create_index(env_avltree, AVL_NO_DUP_KEYS, 0); } } if (env_avltree != NULL) { for (i=0; environ[i] != NULL; i++) { (void)strncpy_s(varname_tmp, sizeof(varname_tmp), environ[i], _TRUNCATE); if ((name = strtok_s(varname_tmp, "=", &value)) != NULL) { if ((pe = malloc(sizeof(AVL_IX_REC) + WINLOG_BUF_SIZE + 1)) != NULL) { strncpy(pe->key, name, WINLOG_BUF_SIZE); if ((pe->recptr = (void *)strdup(value)) != NULL) avl_add_key(pe, env_avltree); free(pe); pe = NULL; } } } } }
void * entlim_initialize_ctx(void) { AVL_IX_DESC *ctx; ctx = (AVL_IX_DESC *)malloc(sizeof(AVL_IX_DESC)); if (ctx != NULL) { avl_create_index(ctx, AVL_NO_DUP_KEYS, 0); if (maxkeylen == 0) { defkeylen = sizeof(AVL_IX_REC); maxkeylen = defkeylen; } } return ((void *)ctx); }