xbps-bin: simplify sanitize_localpath().

--HG--
extra : convert_revision : 223334822b80c6b11e63f1a34e7bfadb9115d5b9
This commit is contained in:
Juan RP 2008-12-27 22:56:47 +01:00
parent 926b1dfa4a
commit e5774555cf

View file

@ -130,6 +130,7 @@ static bool
sanitize_localpath(char *buf, const char *path)
{
char *dirnp, *basenp, *dir, *base, *tmp;
bool rv = false;
dir = strdup(path);
if (dir == NULL)
@ -143,29 +144,27 @@ sanitize_localpath(char *buf, const char *path)
dirnp = dirname(dir);
if (strcmp(dirnp, ".") == 0)
goto error;
goto out;
basenp = basename(base);
if (strcmp(basenp, base) == 0)
goto error;
goto out;
tmp = strncpy(buf, dirnp, PATH_MAX - 1);
if (sizeof(*tmp) >= PATH_MAX)
goto error;
goto out;
buf[strlen(buf) + 1] = '\0';
if (strcmp(dirnp, "/"))
strncat(buf, "/", 1);
strncat(buf, basenp, PATH_MAX - strlen(buf) - 1);
rv = true;
out:
free(dir);
free(base);
return true;
error:
free(base);
free(dir);
return false;
return rv;
}
int