From b3cec8eecfb69bf991d4d3a6b78bd96467958332 Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Fri, 29 May 2026 09:38:08 +0200 Subject: [PATCH] tools: add shared current directory handle helper Add tool_current_dhandle_only() as a small wrapper for callers that only need the current NetWare directory handle. Replace the local creator_current_dhandle() and tests_current_dhandle() implementations in CREATOR and NWTESTS with the shared helper. This removes duplicate requester-current-directory code without changing behavior. --- creator.c | 25 +------------------------ net.h | 1 + nwtests.c | 55 +++++++++++++++---------------------------------------- tools.c | 7 +++++++ 4 files changed, 24 insertions(+), 64 deletions(-) diff --git a/creator.c b/creator.c index 5fb920a..a5bb743 100644 --- a/creator.c +++ b/creator.c @@ -90,29 +90,6 @@ static void creator_usage(void) fprintf(stdout, " CREATOR F:\\CIXTEST\\SUP\\S_SUP.TXT /ARCHIVE MARIO\n"); } -static int creator_get_current_drive(void) -{ - REGS regs; - - regs.h.ah = 0x19; - int86(0x21, ®s, ®s); - return((int)regs.h.al); -} - -static int creator_current_dhandle(uint8 *dhandle) -{ - uint8 connid = 0; - uint8 flags = 0; - int drive; - - drive = creator_get_current_drive(); - if (get_drive_info((uint8)drive, &connid, dhandle, &flags)) - return(-1); - if (!connid || (flags & 0x80)) - return(-1); - return(0); -} - static int hex_value(int c) { if (c >= '0' && c <= '9') return(c - '0'); @@ -516,7 +493,7 @@ int func_creator(int argc, char *argv[], int mode) return(1); } - if (creator_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "CREATOR: current drive is not a network drive\n"); if (oldcwd[0]) chdir(oldcwd); return(1); diff --git a/net.h b/net.h index 9e52957..e7da7d6 100644 --- a/net.h +++ b/net.h @@ -183,6 +183,7 @@ extern int tool_is_files_option(char *s); extern int tool_is_subdirs_option(char *s); extern int tool_get_current_drive(void); extern int tool_current_dhandle(uint8 *connid, uint8 *dhandle); +extern int tool_current_dhandle_only(uint8 *dhandle); extern int tool_current_prefix(char *out, int max); extern int tool_is_current_path(char *path); extern void tool_upcopy(char *dst, char *src, int max); diff --git a/nwtests.c b/nwtests.c index 3697258..ba5f3ee 100644 --- a/nwtests.c +++ b/nwtests.c @@ -62,31 +62,6 @@ static void tests_usage(void) fprintf(stdout, " TESTS NCP23MAP path (probe NCP23/F4 then F3 layouts; see server debug log)\n"); } -static int tests_get_current_drive(void) -{ - REGS regs; - - regs.h.ah = 0x19; - int86(0x21, ®s, ®s); - return((int)regs.h.al); -} - -static int tests_current_dhandle(uint8 *dhandle) -{ - uint8 connid = 0; - uint8 flags = 0; - int drive; - - drive = tests_get_current_drive(); - if (get_drive_info((uint8)drive, &connid, dhandle, &flags)) - return(-1); - - if (!connid || (flags & 0x80)) - return(-1); - - return(0); -} - static uint8 tests_map_ncp_mask(uint16 ncp_rights) { uint8 mask = 0; @@ -438,7 +413,7 @@ static int tests_ncp2225miss(char *path) if (!path || !*path) path = "NO22_25.$$$"; - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP2225MISS failed: current drive is not a network drive\n"); return(1); } @@ -467,7 +442,7 @@ static int tests_ncp2225attr(char *path, char *attr_arg) return(1); } - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP2225ATTR failed: current drive is not a network drive\n"); return(1); } @@ -983,7 +958,7 @@ static int tests_ncp221einfo(char *path) return(1); } - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP221EINFO failed: current drive is not a network drive\n"); return(1); } @@ -1109,7 +1084,7 @@ static int tests_ncp2225time(char *path, char *date_arg, char *time_arg) return(1); } - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP2225TIME failed: current drive is not a network drive\n"); return(1); } @@ -1200,7 +1175,7 @@ static int tests_ncp2225adate(char *path, char *date_arg) return(1); } - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP2225ADATE failed: current drive is not a network drive\n"); return(1); } @@ -1296,7 +1271,7 @@ static int tests_ncp2225maxspace(char *path, char *space_arg) return(1); } - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP2225MAXSPACE failed: current drive is not a network drive\n"); return(1); } @@ -1354,7 +1329,7 @@ static int tests_ncp2225modid(char *path, char *id_arg) return(1); } - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP2225MODID failed: current drive is not a network drive\n"); return(1); } @@ -1447,7 +1422,7 @@ static int tests_ncp2225create(char *path, char *date_arg, char *time_arg, char return(1); } - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP2225CREATE failed: current drive is not a network drive\n"); return(1); } @@ -1557,7 +1532,7 @@ static int tests_ncp2225arch(char *path, char *date_arg, char *time_arg, char *i return(1); } - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP2225ARCH failed: current drive is not a network drive\n"); return(1); } @@ -1794,7 +1769,7 @@ static int tests_ncp22ren(char *src, char *dst) return(1); } - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP22REN failed: current drive is not a network drive\n"); return(1); } @@ -1835,7 +1810,7 @@ static int tests_ncp22rendir(char *parent) if (!parent || !*parent) parent = "."; - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP22RENDIR failed: current drive is not a network drive\n"); return(1); } @@ -1884,7 +1859,7 @@ static int tests_ncp22s4(char *path, char *mask_arg) if (!path) path = "."; - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP22S4 failed: current drive is not a network drive\n"); return(1); } @@ -1930,7 +1905,7 @@ static int tests_ncp87c32attr(void) uint16 handle_hi = 0; int rc; - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP87C32ATTR failed: current drive is not a network drive\n"); return(1); } @@ -2193,7 +2168,7 @@ static int tests_ncp23map(char *path) if (!path) path = "."; - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "NCP23MAP failed: current drive is not a network drive\n"); return(1); } @@ -2520,7 +2495,7 @@ static int tests_effright(char *path) if (!path) path = "."; - if (tests_current_dhandle(&dhandle)) { + if (tool_current_dhandle_only(&dhandle)) { fprintf(stdout, "EFFRIGHT failed: current drive is not a network drive\n"); return(1); } diff --git a/tools.c b/tools.c index bd51c66..0aceab5 100644 --- a/tools.c +++ b/tools.c @@ -596,6 +596,13 @@ int tool_current_dhandle(uint8 *connid, uint8 *dhandle) return(0); } +int tool_current_dhandle_only(uint8 *dhandle) +{ + uint8 connid = 0; + + return(tool_current_dhandle(&connid, dhandle)); +} + int tool_current_prefix(char *out, int max) { uint8 connid = 0;