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. ;)
This commit is contained in:
parent
bee1a5f180
commit
b5d61a25cb
5 changed files with 11 additions and 19 deletions
5
lcl.c
5
lcl.c
|
@ -9,9 +9,6 @@
|
|||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#include <errno.h>
|
||||
#ifdef __OpenBSD__
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
@ -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 */
|
||||
|
|
4
lfs.c
4
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
|
||||
|
|
|
@ -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 *));
|
||||
|
|
9
util.c
9
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.
|
||||
*/
|
||||
|
|
6
util.h
6
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue