From b6bdbf958f3a0f0f2c84ed7cd2b340528c6d1273 Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Fri, 29 May 2026 12:46:13 +0200 Subject: [PATCH] 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. --- ndir.c | 22 +--------------------- net.h | 1 + nwtests.c | 25 +------------------------ rights.c | 26 +------------------------- tools.c | 31 +++++++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 70 deletions(-) diff --git a/ndir.c b/ndir.c index 41c29e3..e1bda5f 100644 --- a/ndir.c +++ b/ndir.c @@ -467,26 +467,6 @@ static int ndir_attr_filter_match(uint32 attr, int options) return(match); } -static void ndir_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) { - if (*p == ':') { - p[1] = '\0'; - } else { - *p = '\0'; - } - strmaxcpy(dst, tmp, max - 1); - } else { - dst[0] = '\0'; - } -} static void ndir_old_rights_string(uint8 old_rights, char *out) { @@ -627,7 +607,7 @@ static void ndir_effective_rights(char *path, char *out) return; } - ndir_parent_path(usepath, path, sizeof(usepath)); + tool_parent_path(usepath, path, sizeof(usepath)); newhandle = alloc_temp_dir_handle(dhandle, usepath, 0, &eff_old); if (newhandle >= 0) { dealloc_dir_handle(newhandle); diff --git a/net.h b/net.h index d30ad68..f3495c9 100644 --- a/net.h +++ b/net.h @@ -166,6 +166,7 @@ extern void tool_header_path(char *out, char *path, int max); extern int tool_is_dot_dir(char *name); extern void tool_join_path(char *out, char *base, char *name, int max); extern int tool_has_wildcards(char *path); +extern void tool_parent_path(char *dst, char *src, int max); extern void tool_parent_pattern(char *dir, char *pattern, char *path, int maxdir, int maxpat); diff --git a/nwtests.c b/nwtests.c index 1451c2d..820e4d6 100644 --- a/nwtests.c +++ b/nwtests.c @@ -91,29 +91,6 @@ static void tests_mask_string(uint8 mask, char *out) out[8] = '\0'; } -static void tests_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); -} static void tests_print_mask(char *label, int rc, uint8 mask) { @@ -2575,7 +2552,7 @@ static int tests_effright(char *path) tests_print_eff_row("old handle path", newhandle, 0, 0, 0); } - tests_parent_path(usepath, path, sizeof(usepath)); + tool_parent_path(usepath, path, sizeof(usepath)); newhandle = alloc_temp_dir_handle(dhandle, usepath, 0, &eff_old); if (newhandle >= 0) { dealloc_dir_handle(newhandle); diff --git a/rights.c b/rights.c index 8a983dc..c266246 100644 --- a/rights.c +++ b/rights.c @@ -63,30 +63,6 @@ static void rights_usage(void) fprintf(stdout, " | Modify | File scan | Access Control\n"); } -static void rights_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); -} static void rights_ncp_path(char *dst, char *src, int max) { @@ -184,7 +160,7 @@ static int rights_effective_mask(char *path, int is_dir, uint8 *mask) } else { char npath[260]; rights_ncp_path(npath, path, sizeof(npath)); - rights_parent_path(usepath, npath, sizeof(usepath)); + tool_parent_path(usepath, npath, sizeof(usepath)); } newhandle = alloc_temp_dir_handle(dhandle, usepath, 0, &eff); diff --git a/tools.c b/tools.c index 82e6ced..0757c79 100644 --- a/tools.c +++ b/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 *