pstr STDCALL gettempfile( pstr name, pstr additional ) { str tempdir; str_init( &tempdir ); gettempdir( &tempdir ); str_dirfile( &tempdir, additional, name ); str_delete( &tempdir ); return name; }
static int executable(clib_package_t *pkg) { int rc; char *url = NULL; char *file = NULL; char *tarball = NULL; char *command = NULL; char *dir = NULL; char *deps = NULL; char *tmp = NULL; tmp = gettempdir(); if (NULL == tmp) { logger_error("error", "gettempdir() out of memory"); return -1; } E_FORMAT(&url , "https://github.com/%s/%s/archive/%s.tar.gz" , pkg->author , pkg->name , pkg->version); E_FORMAT(&file, "%s-%s.tar.gz", pkg->name, pkg->version); E_FORMAT(&tarball, "%s/%s", tmp, file); rc = http_get_file(url, tarball); E_FORMAT(&command, "cd %s && tar -xf %s", tmp, file); // cheap untar rc = system(command); if (0 != rc) goto cleanup; E_FORMAT(&dir, "%s/%s-%s", tmp, pkg->name, pkg->version); if (pkg->dependencies) { E_FORMAT(&deps, "%s/deps", dir); rc = clib_package_install_dependencies(pkg, deps, opts.verbose); if (-1 == rc) goto cleanup; } free(command); command = NULL; E_FORMAT(&command, "cd %s && %s", dir, pkg->install); rc = system(command); cleanup: free(tmp); free(dir); free(command); free(tarball); free(file); free(url); return rc; }
static char * clib_search_file(void) { char *file = NULL; char *temp = NULL; temp = gettempdir(); if (NULL == temp) { logger_error("error", "gettempdir() out of memory"); return NULL; } int rc = asprintf(&file, "%s/%s", temp, CLIB_SEARCH_CACHE); if (-1 == rc) { logger_error("error", "asprintf() out of memory"); free(temp); return NULL; } free(temp); return file; }