tools: add shared parent path helper
Move the common parent path extraction helper into tools.c and declare it in net.h. Replace the local implementations in RIGHTS, NDIR and NWTESTS with tool_parent_path(). The helper keeps the existing behavior of uppercasing the path and preserving a trailing volume colon for parent paths such as SYS:. No behavior change.
This commit is contained in:
31
tools.c
31
tools.c
@@ -998,6 +998,37 @@ int tool_has_wildcards(char *path)
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* tool_parent_path
|
||||
*
|
||||
* Purpose:
|
||||
* Copies the parent directory part of a DOS/NetWare path. The result is
|
||||
* uppercased and keeps a trailing volume colon for paths like SYS:FILE.TXT.
|
||||
*/
|
||||
void tool_parent_path(char *dst, char *src, int max)
|
||||
{
|
||||
char tmp[260];
|
||||
char *p;
|
||||
|
||||
tool_upcopy(tmp, src, sizeof(tmp));
|
||||
p = strrchr(tmp, '\\');
|
||||
if (!p) p = strrchr(tmp, ':');
|
||||
|
||||
if (!p) {
|
||||
dst[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
if (*p == ':') {
|
||||
p++;
|
||||
*p = '\0';
|
||||
} else {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
strmaxcpy(dst, tmp, max - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* tool_parent_pattern
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user