From 364bc1f31ca4fe79699642a27ba32adae21848f0 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Fri, 25 Jul 2025 14:12:30 -0700 Subject: [PATCH] Removes StrNCpyFromLispToC(), renames StrNCpyFromCToLisp to MemCpyToLispFromNative Removes StrNCpyFromLispToC and the single use of it in LispStringToCString in the BYTESWAP implementation case. Rename StrNCpyFromCToLisp, which does NOT follow "strncpy" semantics, to be MemCpyToLispFromNative, where the types in the name match the types of the arguments, and the semantics (and argument order) are those of the C library "memcpy". --- inc/locfile.h | 29 +++++++++++++++-------------- src/dir.c | 4 ++-- src/dsk.c | 10 +++++----- src/osmsg.c | 2 +- src/ufs.c | 4 ++-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/inc/locfile.h b/inc/locfile.h index 856c23d..da69505 100644 --- a/inc/locfile.h +++ b/inc/locfile.h @@ -44,18 +44,17 @@ /* For getfileinfo. For WDATE&RDATE */ /* 29969152 == (timer.c)LISP_UNIX_TIME_DIFF */ -#define StrNCpyFromCToLisp(lispbuf, cbuf ,len) do { \ - char *lf_sptr = (cbuf); \ - char *lf_dptr = (lispbuf); \ - for(size_t lf_i=0;lf_i<(len);lf_i++)\ - GETBYTE(lf_dptr++) = *lf_sptr++; \ - } while (0) - -#define StrNCpyFromLispToC(cbuf , lispbuf, len) do { \ - char *lf_sptr = (lispbuf); \ - char *lf_dptr = (cbuf); \ - for(size_t lf_i=0;lf_i<(len);lf_i++)\ - *lf_dptr++ = GETBYTE(lf_sptr++); \ +/* + * Copy memory between native memory locations accounting for potential + * byte-swapping necessary when then destination is within Lisp memory space + * though the provided destination pointer is a native address within the + * Lisp space. + */ + #define MemCpyToLispFromNative(lispbuf, cbuf, len) \ + do { \ + char *lf_sptr = (cbuf); \ + char *lf_dptr = (lispbuf); \ + for (size_t lf_i = 0; lf_i < (len); lf_i++) *BYTEPTR(lf_dptr++) = *lf_sptr++; \ } while (0) #define FGetNum(ptr, place) do { \ @@ -122,8 +121,10 @@ case THIN_CHAR_TYPENUMBER: \ lf_base = ((char *)(NativeAligned2FromLAddr(lf_arrayp->base))) \ + ((int)(lf_arrayp->offset)); \ - StrNCpyFromLispToC(C , lf_base , lf_length ); \ - (C)[lf_length] = '\0'; \ + lf_dp = C; \ + for (size_t lf_i = 0; lf_i < lf_length; lf_i++) \ + *lf_dp++ = GETBYTE(lf_base++); \ + *lf_dp = '\0'; \ break; \ \ case FAT_CHAR_TYPENUMBER: \ diff --git a/src/dir.c b/src/dir.c index 5b31c4d..01f7b93 100644 --- a/src/dir.c +++ b/src/dir.c @@ -2159,7 +2159,7 @@ LispPTR COM_next_file(LispPTR *args) #ifndef BYTESWAP strncpy(base, fp->lname, fp->lname_len); #else - StrNCpyFromCToLisp(base, fp->lname, fp->lname_len); + MemCpyToLispFromNative(base, fp->lname, fp->lname_len); #endif /* BYTESWAP */ if (!propp) return (GetPosSmallp(fp->lname_len)); @@ -2175,7 +2175,7 @@ LispPTR COM_next_file(LispPTR *args) #ifndef BYTESWAP strncpy(base, pp->author, pp->au_len); #else - StrNCpyFromCToLisp(base, pp->author, pp->au_len); + MemCpyToLispFromNative(base, pp->author, pp->au_len); #endif /* BYTESWAP */ gfsp->aulen = pp->au_len; diff --git a/src/dsk.c b/src/dsk.c index a96a0f4..59983b9 100644 --- a/src/dsk.c +++ b/src/dsk.c @@ -1034,7 +1034,7 @@ LispPTR DSK_getfilename(LispPTR *args) #ifndef BYTESWAP strncpy(base, lfname, len + 1); #else - StrNCpyFromCToLisp(base, lfname, len + 1); + MemCpyToLispFromNative(base, lfname, len + 1); #endif /* BYTESWAP */ return (GetPosSmallp(len)); @@ -1070,7 +1070,7 @@ LispPTR DSK_getfilename(LispPTR *args) #ifndef BYTESWAP strncpy(base, lfname, len + 1); #else - StrNCpyFromCToLisp(base, lfname, len + 1); + MemCpyToLispFromNative(base, lfname, len + 1); #endif /* BYTESWAP */ return (GetPosSmallp(len)); @@ -1509,7 +1509,7 @@ LispPTR DSK_directorynamep(LispPTR *args) #ifndef BYTESWAP strncpy(base, dirname, len + 1); #else - StrNCpyFromCToLisp(base, dirname, len + 1); + MemCpyToLispFromNative(base, dirname, len + 1); #endif /* BYTESWAP */ return (GetPosSmallp(len)); @@ -1671,7 +1671,7 @@ LispPTR COM_getfileinfo(LispPTR *args) #ifndef BYTESWAP strncpy(base, pwd->pw_name, len); #else - StrNCpyFromCToLisp(base, pwd->pw_name, len); + MemCpyToLispFromNative(base, pwd->pw_name, len); #endif /* BYTESWAP */ #endif /* DOS */ return (GetPosSmallp(len)); @@ -1710,7 +1710,7 @@ LispPTR COM_getfileinfo(LispPTR *args) #ifndef BYTESWAP strncpy(base, pwd->pw_name, len); #else - StrNCpyFromCToLisp(base, pwd->pw_name, len); + MemCpyToLispFromNative(base, pwd->pw_name, len); #endif /* BYTESWAP */ #endif /* DOS */ return (GetPosSmallp(len)); diff --git a/src/osmsg.c b/src/osmsg.c index 6c0b748..929b95f 100644 --- a/src/osmsg.c +++ b/src/osmsg.c @@ -283,7 +283,7 @@ LispPTR mess_read(LispPTR *args) if (temp_buf[i] == '\n') temp_buf[i] = '\000'; } /* COPY actual Lisp Buffer(for BYTESWAP magic) */ - StrNCpyFromCToLisp(base, temp_buf, size); + MemCpyToLispFromNative(base, temp_buf, size); return (GetSmallp(size)); #else diff --git a/src/ufs.c b/src/ufs.c index b5173cd..cb62990 100644 --- a/src/ufs.c +++ b/src/ufs.c @@ -218,7 +218,7 @@ LispPTR UFS_getfilename(LispPTR *args) #ifndef BYTESWAP strncpy(base, lfname, len + 1); #else - StrNCpyFromCToLisp(base, lfname, len + 1); + MemCpyToLispFromNative(base, lfname, len + 1); #endif /* BYTESWAP */ return (GetSmallp(len)); @@ -422,7 +422,7 @@ LispPTR UFS_directorynamep(LispPTR *args) #ifndef BYTESWAP strncpy(base, dirname, len + 1); #else - StrNCpyFromCToLisp(base, dirname, len + 1); + MemCpyToLispFromNative(base, dirname, len + 1); #endif /* BYTESWAP */ return (GetSmallp(len));