ncopy: use shared endian helpers

Replace the local NCOPY endian buffer helpers with the shared tools.c helpers.

This removes duplicate little-endian and big-endian get/put code while keeping
the experimental NCOPY NCP request layouts unchanged.

No behavior change.
This commit is contained in:
Mario Fetka
2026-05-29 12:50:17 +02:00
parent b6bdbf958f
commit 892bea8a5e

40
ncopy.c
View File

@@ -536,32 +536,6 @@ fail:
return(-1);
}
static uint32 ncopy_get_dword_be(uint8 *p)
{
return(GET_BE32(p));
}
static void ncopy_put_word_lh(uint8 *p, uint16 v)
{
p[0] = (uint8)(v & 0xff);
p[1] = (uint8)((v >> 8) & 0xff);
}
static void ncopy_put_dword_lh(uint8 *p, uint32 v)
{
p[0] = (uint8)(v & 0xff);
p[1] = (uint8)((v >> 8) & 0xff);
p[2] = (uint8)((v >> 16) & 0xff);
p[3] = (uint8)((v >> 24) & 0xff);
}
static uint32 ncopy_get_dword_lh(uint8 *p)
{
return((uint32)p[0] | ((uint32)p[1] << 8) |
((uint32)p[2] << 16) | ((uint32)p[3] << 24));
}
static unsigned ncopy_build_nw_handle_path(uint8 *buf, uint8 dhandle,
const char *name)
{
@@ -584,7 +558,7 @@ static unsigned ncopy_build_nw_handle_path(uint8 *buf, uint8 dhandle,
* TCOPY/SRC/A.TXT instead of only A.TXT under the temp handle.
*/
buf[0] = dhandle;
ncopy_put_dword_lh(buf + 1, 0);
tool_put_dword_lh(buf + 1, 0);
buf[5] = 0; /* dirstyle = short directory handle */
buf[6] = 1; /* one path component */
@@ -648,10 +622,10 @@ static int ncopy_open_create_ncp87_direct(char *path,
req.subfunc = 0x01; /* NCP 87/01 Open/Create File or Subdirectory */
req.namespace_id = 0; /* DOS namespace */
req.open_create_mode = open_create_mode;
ncopy_put_word_lh(req.search_attrs, search_attrs);
ncopy_put_dword_lh(req.return_info_mask, 0x00000fffUL);
ncopy_put_dword_lh(req.create_attrs, create_attrs);
ncopy_put_word_lh(req.desired_access, desired_access);
tool_put_word_lh(req.search_attrs, search_attrs);
tool_put_dword_lh(req.return_info_mask, 0x00000fffUL);
tool_put_dword_lh(req.create_attrs, create_attrs);
tool_put_word_lh(req.desired_access, desired_access);
path_len = ncopy_build_nw_handle_path(req.nwpath, dhandle, name);
/* INT 21h AX=F257 uses the same request layout as the working FLAG
* code: a 16-bit length prefix followed by the NCP 87 subfunction.
@@ -706,7 +680,7 @@ static int ncopy_open_create_ncp87_direct(char *path,
}
if (size_out)
*size_out = ncopy_get_dword_lh(repl.info + 10);
*size_out = tool_get_dword_lh(repl.info + 10);
ncopy_debug_rc("direct open/create NCP 0x57/01", 0);
ncopy_debug_msg("direct NCP87 handle returned");
@@ -1071,7 +1045,7 @@ static int ncopy_ncp74_copy_chunk(uint8 src_handle[6], uint8 dst_handle[6],
}
if (copied)
*copied = ncopy_get_dword_be(repl.copied);
*copied = tool_get_dword_hl(repl.copied);
ncopy_debug_rc("copy chunk NCP 0x4a", 0);
if (copied)
ncopy_debug_ul("copy chunk copied", (unsigned long)*copied);