static int setprefix(struct plist *p, char *line, struct file_attr *a) { char *pkgprefix; /* if no arguments then set default prefix */ if (line[0] == '\0') { pkg_get(p->pkg, PKG_PREFIX, &pkgprefix); strlcpy(p->prefix, pkgprefix, sizeof(p->prefix)); } else strlcpy(p->prefix, line, sizeof(p->prefix)); pkg_get(p->pkg, PKG_PREFIX, &pkgprefix); if (pkgprefix == NULL || *pkgprefix == '\0') pkg_set(p->pkg, PKG_PREFIX, line); p->slash = p->prefix[strlen(p->prefix) -1] == '/' ? "" : "/"; exec_append(p->post_install_buf, "cd %s\n", p->prefix); pre_unexec_append(p->pre_deinstall_buf, "cd %s\n", p->prefix); post_unexec_append(p->post_deinstall_buf, "cd %s\n", p->prefix); free(a); return (EPKG_OK); }
static int exec_command(memcached_st *mcd, int n_cmds, char * const cmds[]) { int retval = 1; if (strcmp(cmds[0], "get") == 0 && n_cmds == 2) retval = exec_get(mcd, cmds[1]); else if (strcmp(cmds[0], "add") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_add(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "set") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_set(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "replace") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_replace(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "append") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_append(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "prepend") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_prepend(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "cas") == 0 && (n_cmds >= 4 && n_cmds <= 6)) retval = exec_cas(mcd, cmds[1], cmds[2], atol(cmds[3]), n_cmds > 4 ? atol(cmds[4]) : 0, n_cmds > 5 ? atol(cmds[5]) : 0); else if (strcmp(cmds[0], "delete") == 0 && (n_cmds >= 2 && n_cmds <= 3)) retval = exec_delete(mcd, cmds[1], n_cmds > 2 ? atol(cmds[2]) : 0); else if (strcmp(cmds[0], "incr") == 0 && n_cmds == 2) retval = exec_incr(mcd, cmds[1]); else if (strcmp(cmds[0], "decr") == 0 && n_cmds == 2) retval = exec_decr(mcd, cmds[1]); else if (strcmp(cmds[0], "flush") == 0 && (n_cmds >= 1 && n_cmds <=2)) retval = exec_flush(mcd, n_cmds > 1 ? atol(cmds[1]) : 0); else if (strcmp(cmds[0], "simple_bench") == 0 && (n_cmds >= 1 && n_cmds <=2)) retval = exec_simple_bench(mcd, n_cmds > 1 ? atof(cmds[1]) : 100.0); return retval; }