ref: f9f3bb77618267d94cc2e5102c35e9d036cfcde0
parent: 1a5c423984ca6cce1cb0b6b2100836bf4aa56e84
author: Antonio Niño Díaz <[email protected]>
date: Fri Jan 26 19:02:26 EST 2018
Remove dependency of strlcat() There was only one place where `strlcat` was used, and `snprintf` actually does a better job at what the code was trying to achieve. Signed-off-by: Antonio Niño Díaz <[email protected]>
--- a/LICENSE.rst
+++ b/LICENSE.rst
@@ -27,5 +27,5 @@
extern/reallocarray.c is derived from the OpenBSD Project,
http://www.openbsd.org, and is released under the ISC license.
-extern/strlcat.c and extern/strlcpy.c are derived from the OpenBSD Project,
-http://www.openbsd.org, and are released under the BSD license.
+extern/strlcpy.c is derived from the OpenBSD Project, http://www.openbsd.org,
+and is released under the BSD license.
--- a/Makefile
+++ b/Makefile
@@ -59,7 +59,6 @@
src/extern/err.o \
src/extern/reallocarray.o \
src/extern/strlcpy.o \
- src/extern/strlcat.o \
src/extern/utf8decoder.o \
src/extern/version.o
--- a/include/extern/strl.h
+++ b/include/extern/strl.h
@@ -16,9 +16,7 @@
#else /* STRL_IN_LIBC */
#define strlcpy rgbds_strlcpy
-#define strlcat rgbds_strlcat
size_t strlcpy(char *dst, const char *src, size_t dsize);
-size_t strlcat(char *dst, const char *src, size_t dsize);
#endif /* STRL_IN_LIBC */
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -236,6 +236,9 @@
int32_t i;
FILE *f;
+ if (fname == NULL)
+ return NULL;
+
f = fopen(fname, "rb");
if (f != NULL || errno != ENOENT) {
@@ -246,11 +249,17 @@
}
for (i = 0; i < NextIncPath; ++i) {
- if (strlcpy(path, IncludePaths[i], sizeof(path))
+ /*
+ * The function snprintf() does not write more than `size` bytes
+ * (including the terminating null byte ('\0')). If the output
+ * was truncated due to this limit, the return value is the
+ * number of characters (excluding the terminating null byte)
+ * which would have been written to the final string if enough
+ * space had been available. Thus, a return value of `size` or
+ * more means that the output was truncated.
+ */
+ if (snprintf(path, sizeof(path), "%s%s", IncludePaths[i], fname)
>= sizeof(path))
- continue;
-
- if (strlcat(path, fname, sizeof(path)) >= sizeof(path))
continue;
f = fopen(path, "rb");
--- a/src/extern/strlcat.c
+++ /dev/null
@@ -1,54 +1,0 @@
-/* $OpenBSD: strlcat.c,v 1.14 2015/01/15 03:54:12 millert Exp $ */
-
-/*
- * Copyright (c) 1998, 2015 Todd C. Miller <[email protected]>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <string.h>
-#include <sys/types.h>
-
-/*
- * Appends src to string dst of size dsize (unlike strncat, dsize is the
- * full size of dst, not space left). At most dsize-1 characters
- * will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
- * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
- * If retval >= dsize, truncation occurred.
- */
-size_t rgbds_strlcat(char *dst, const char *src, size_t dsize)
-{
- const char *odst = dst;
- const char *osrc = src;
- size_t n = dsize;
- size_t dlen;
-
- /* Find the end of dst and adjust bytes left but don't go past end. */
- while (n-- != 0 && *dst != '\0')
- dst++;
- dlen = dst - odst;
- n = dsize - dlen;
-
- if (n-- == 0)
- return(dlen + strlen(src));
- while (*src != '\0') {
- if (n != 0) {
- *dst++ = *src;
- n--;
- }
- src++;
- }
- *dst = '\0';
-
- return dlen + (src - osrc); /* count does not include NUL */
-}