1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

s3-clitar: Improve readabilty of fix_unix_path().

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
This commit is contained in:
Andreas Schneider 2014-02-17 11:32:14 +01:00
parent ef150e7dfa
commit 3b207dc0f3

View File

@ -1662,39 +1662,42 @@ static int max_token (const char *str)
* @path: path to convert
* @removeprefix: if true, remove leading ./ or /.
*/
static char *fix_unix_path (char *path, bool removeprefix)
static char *fix_unix_path (char *path, bool do_remove_prefix)
{
char *from = path, *to = path;
if (!path || !*path)
if (path == NULL || path[0] == '\0') {
return path;
}
/* remove prefix:
* ./path => path
* /path => path
*/
if (removeprefix) {
if (do_remove_prefix) {
/* /path */
if (path[0] == '/' || path[0] == '\\') {
from += 1;
}
/* ./path */
if (path[1] && path[0] == '.' && (path[1] == '/' || path[1] == '\\')) {
if (path[1] != '\0' && path[0] == '.' && (path[1] == '/' || path[1] == '\\')) {
from += 2;
}
}
/* replace / with \ */
while (*from) {
if (*from == '/') {
*to = '\\';
while (from[0] != '\0') {
if (from[0] == '/') {
to[0] = '\\';
} else {
*to = *from;
to[0] = from[0];
}
from++; to++;
from++;
to++;
}
*to = 0;
to[0] = '\0';
return path;
}