From b5d61a25cb9ed3a879e6a8469ff8b6f9df4d0b64 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 25 Jan 2024 19:47:57 +1300 Subject: [PATCH] rename the statically linked strlcpy to strbcpy stands for "string bounds copy". Some systems like macOS include their very own version of strlcpy and testing for that would require some bloat like gnu automake so I'm just gonna rename it to prevent any future conflicts. I only test on Linux and OpenBSD anyway. ;) --- lcl.c | 5 +---- lfs.c | 4 ++-- lprocess.c | 6 +++--- util.c | 9 +++------ util.h | 6 ++---- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/lcl.c b/lcl.c index b3c49dc..c889384 100644 --- a/lcl.c +++ b/lcl.c @@ -9,9 +9,6 @@ #include #include #include -#ifdef __OpenBSD__ -# include -#endif #include #include @@ -225,7 +222,7 @@ cl_options(lua_State *L) /* parameter type checking */ luaL_checktype(L, 1, LUA_TTABLE); - strlcpy(optstring, luaL_checkstring(L, 2), lua_rawlen(L, 2) * sizeof(char *)); + strbcpy(optstring, luaL_checkstring(L, 2), lua_rawlen(L, 2) * sizeof(char *)); luaL_checktype(L, 3, LUA_TFUNCTION); argc = (int)lua_rawlen(L, 1) + 1; /* get argv length */ diff --git a/lfs.c b/lfs.c index 1a9c664..dfef0e1 100644 --- a/lfs.c +++ b/lfs.c @@ -406,10 +406,10 @@ recursiveremove(lua_State *L, const char *path) len = plen + nlen + 2; fullname = malloc(len * sizeof(char)); - strlcpy(fullname, path, len); + strbcpy(fullname, path, len); fullname[plen] = '/'; fullname[plen + 1] = 0; - strlcat(fullname, ent->d_name, len); + strbcat(fullname, ent->d_name, len); if (ent->d_type == DT_DIR) { /* if rmdir succeeded, free fullname and diff --git a/lprocess.c b/lprocess.c index 2b56c38..deedac2 100644 --- a/lprocess.c +++ b/lprocess.c @@ -168,9 +168,9 @@ process_pidof(lua_State *L) /* construct pgrep command */ memset(command, 0, PROCESS_MAX * sizeof(char)); - strlcat(command, "pgrep '", PROCESS_MAX); - strlcat(command, process, PROCESS_MAX); - strlcat(command, "' | sed 1q", PROCESS_MAX); + strbcat(command, "pgrep '", PROCESS_MAX); + strbcat(command, process, PROCESS_MAX); + strbcat(command, "' | sed 1q", PROCESS_MAX); p = popen(command, "r"); buffer = malloc(PID_MAX * sizeof(char *)); diff --git a/util.c b/util.c index 6226684..0688ecb 100644 --- a/util.c +++ b/util.c @@ -33,11 +33,10 @@ lfailm(lua_State *L, const char *mesg) } /* - * strlcat and strlcpy are from OpenBSD source files + * strbcat and strbcpy are from OpenBSD source files * lib/libc/string/strlcat.c and * lib/libc/string/strlcpy.c respectively */ -#ifndef __OpenBSD__ /* * Appends src to string dst of size dsize (unlike strncat, dsize is the @@ -47,7 +46,7 @@ lfailm(lua_State *L, const char *mesg) * If retval >= dsize, truncation occurred. */ size_t -strlcat(char *dst, const char *src, size_t dsize) +strbcat(char *dst, const char *src, size_t dsize) { const char *odst = dst; const char *osrc = src; @@ -80,7 +79,7 @@ strlcat(char *dst, const char *src, size_t dsize) * Returns strlen(src); if retval >= dsize, truncation occurred. */ size_t -strlcpy(char *dst, const char *src, size_t dsize) +strbcpy(char *dst, const char *src, size_t dsize) { const char *osrc = src; size_t nleft = dsize; @@ -104,8 +103,6 @@ strlcpy(char *dst, const char *src, size_t dsize) return(src - osrc - 1); /* count does not include NUL */ } -#endif - /* * Prepends t to s. */ diff --git a/util.h b/util.h index 5465f26..4a9e2da 100644 --- a/util.h +++ b/util.h @@ -8,10 +8,8 @@ int lfail(lua_State *); int lfailm(lua_State *, const char *); -#ifndef __OpenBSD__ -size_t strlcat(char *, const char *, size_t); -size_t strlcpy(char *, const char *, size_t); -#endif +size_t strbcat(char *, const char *, size_t); +size_t strbcpy(char *, const char *, size_t); void strprepend(char *, const char *); #endif