Introduce xbps_sanitize_path() to fix #78 properly.

This removes multiple slashes of a path and returns you a buffer with
the sanitized string.
This commit is contained in:
Juan RP
2015-02-18 15:12:39 +01:00
parent 3c34c300d1
commit 1722635e08
3 changed files with 54 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2014 Juan Romero Pardines.
* Copyright (c) 2008-2015 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -425,3 +425,30 @@ xbps_pkg_reverts(xbps_dictionary_t pkg, const char *pkgver)
return false;
}
char *
xbps_sanitize_path(const char *src)
{
const char *s = src;
char *d, *dest;
size_t len;
assert(src);
len = strlen(src);
assert(len != 0);
dest = malloc(len);
assert(dest);
d = dest;
while ((*d = *s)) {
if (*s == '/' && *(s+1) == '/') {
s++;
continue;
}
d++, s++;
}
*d = '\0';
return dest;
}