
Apparently strdup is not portable, so LIL used its own. Use strdup.
Signed-off-by: Sean Anderson seanga2@gmail.com ---
common/cli_lil.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/common/cli_lil.c b/common/cli_lil.c index c8c6986fe1..294d79e86e 100644 --- a/common/cli_lil.c +++ b/common/cli_lil.c @@ -123,17 +123,6 @@ static struct lil_env **envpool; static size_t envpoolsize, envpoolcap; #endif
-static char *strclone(const char *s) -{ - size_t len = strlen(s) + 1; - char *ns = malloc(len); - - if (!ns) - return NULL; - memcpy(ns, s, len); - return ns; -} - static unsigned long hm_hash(const char *key) { unsigned long hash = 5381; @@ -173,7 +162,7 @@ static void hm_put(struct hashmap *hm, const char *key, void *value) }
cell->e = realloc(cell->e, sizeof(struct hashentry) * (cell->c + 1)); - cell->e[cell->c].k = strclone(key); + cell->e[cell->c].k = strdup(key); cell->e[cell->c].v = value; cell->c++; } @@ -606,7 +595,7 @@ static struct lil_func *add_func(struct lil *lil, const char *name) }
cmd = calloc(1, sizeof(struct lil_func)); - cmd->name = strclone(name); + cmd->name = strdup(name);
ncmd = realloc(lil->cmd, sizeof(struct lil_func *) * (lil->cmds + 1)); if (!ncmd) { @@ -705,7 +694,7 @@ struct lil_var *lil_set_var(struct lil *lil, const char *name,
env->var = nvar; nvar[env->vars] = calloc(1, sizeof(struct lil_var)); - nvar[env->vars]->n = strclone(name); + nvar[env->vars]->n = strdup(name); nvar[env->vars]->env = env; nvar[env->vars]->v = freeval ? val : lil_clone_value(val); hm_put(&env->varmap, name, nvar[env->vars]); @@ -1207,7 +1196,7 @@ void lil_set_error(struct lil *lil, const char *msg) free(lil->err_msg); lil->error = ERROR_FIXHEAD; lil->err_head = 0; - lil->err_msg = strclone(msg ? msg : ""); + lil->err_msg = strdup(msg ? msg : ""); }
void lil_set_error_at(struct lil *lil, size_t pos, const char *msg) @@ -1218,7 +1207,7 @@ void lil_set_error_at(struct lil *lil, size_t pos, const char *msg) free(lil->err_msg); lil->error = ERROR_DEFAULT; lil->err_head = pos; - lil->err_msg = strclone(msg ? msg : ""); + lil->err_msg = strdup(msg ? msg : ""); }
int lil_error(struct lil *lil, const char **msg, size_t *pos) @@ -2016,7 +2005,7 @@ static struct lil_value *fnc_rename(struct lil *lil, size_t argc, hm_put(&lil->cmdmap, oldname, 0); hm_put(&lil->cmdmap, newname, func); free(func->name); - func->name = strclone(newname); + func->name = strdup(newname); } else { del_func(lil, func); } @@ -2728,7 +2717,7 @@ static struct lil_value *real_trim(const char *str, const char *chars, int left, size_t len; char *s;
- s = strclone(str + base); + s = strdup(str + base); len = strlen(s); while (len && strchr(chars, s[len - 1])) len--; @@ -2833,7 +2822,7 @@ static struct lil_value *fnc_repstr(struct lil *lil, size_t argc, if (!from[0]) return NULL;
- src = strclone(lil_to_string(argv[0])); + src = strdup(lil_to_string(argv[0])); srclen = strlen(src); fromlen = strlen(from); tolen = strlen(to);