summaryrefslogtreecommitdiff
path: root/vere/ext/nasm/stdlib
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-05 21:56:51 +0700
committerpolwex <polwex@sortug.com>2025-10-05 21:56:51 +0700
commitfcedfddf00b3f994e4f4e40332ac7fc192c63244 (patch)
tree51d38e62c7bdfcc5f9a5e9435fe820c93cfc9a3d /vere/ext/nasm/stdlib
claude is gud
Diffstat (limited to 'vere/ext/nasm/stdlib')
-rw-r--r--vere/ext/nasm/stdlib/snprintf.c26
-rw-r--r--vere/ext/nasm/stdlib/strlcpy.c51
-rw-r--r--vere/ext/nasm/stdlib/strnlen.c45
-rw-r--r--vere/ext/nasm/stdlib/strrchrnul.c49
-rw-r--r--vere/ext/nasm/stdlib/vsnprintf.c46
5 files changed, 217 insertions, 0 deletions
diff --git a/vere/ext/nasm/stdlib/snprintf.c b/vere/ext/nasm/stdlib/snprintf.c
new file mode 100644
index 0000000..e4a1c0b
--- /dev/null
+++ b/vere/ext/nasm/stdlib/snprintf.c
@@ -0,0 +1,26 @@
+/*
+ * snprintf()
+ *
+ * Implement snprintf() in terms of vsnprintf()
+ */
+
+#include "compiler.h"
+
+
+#include "nasmlib.h"
+
+#if !defined(HAVE_SNPRINTF) && !defined(HAVE__SNPRINTF)
+
+int snprintf(char *str, size_t size, const char *format, ...)
+{
+ va_list ap;
+ int rv;
+
+ va_start(ap, format);
+ rv = vsnprintf(str, size, format, ap);
+ va_end(ap);
+
+ return rv;
+}
+
+#endif
diff --git a/vere/ext/nasm/stdlib/strlcpy.c b/vere/ext/nasm/stdlib/strlcpy.c
new file mode 100644
index 0000000..22d9ccf
--- /dev/null
+++ b/vere/ext/nasm/stdlib/strlcpy.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * 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 "compiler.h"
+
+/*
+ * Copy src to string dst of size siz. At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+#ifndef HAVE_STRLCPY
+
+size_t strlcpy(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}
+
+#endif
diff --git a/vere/ext/nasm/stdlib/strnlen.c b/vere/ext/nasm/stdlib/strnlen.c
new file mode 100644
index 0000000..193245e
--- /dev/null
+++ b/vere/ext/nasm/stdlib/strnlen.c
@@ -0,0 +1,45 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 1996-2016 The NASM Authors - All Rights Reserved
+ * See the file AUTHORS included with the NASM distribution for
+ * the specific copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include "compiler.h"
+
+#ifndef HAVE_STRNLEN
+
+size_t strnlen(const char *s, size_t maxlen)
+{
+ const char *end = memchr(s, 0, maxlen);
+
+ return end ? (size_t)(end - s) : maxlen;
+}
+
+#endif
diff --git a/vere/ext/nasm/stdlib/strrchrnul.c b/vere/ext/nasm/stdlib/strrchrnul.c
new file mode 100644
index 0000000..2fc8eb6
--- /dev/null
+++ b/vere/ext/nasm/stdlib/strrchrnul.c
@@ -0,0 +1,49 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2017 The NASM Authors - All Rights Reserved
+ * See the file AUTHORS included with the NASM distribution for
+ * the specific copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include "compiler.h"
+
+#ifndef HAVE_STRRCHRNUL
+
+char *strrchrnul(const char *s, int c)
+{
+ char *p;
+
+ p = strrchr(s, c);
+ if (!p)
+ p = strchr(s, '\0');
+
+ return p;
+}
+
+#endif
diff --git a/vere/ext/nasm/stdlib/vsnprintf.c b/vere/ext/nasm/stdlib/vsnprintf.c
new file mode 100644
index 0000000..58de651
--- /dev/null
+++ b/vere/ext/nasm/stdlib/vsnprintf.c
@@ -0,0 +1,46 @@
+/*
+ * vsnprintf()
+ *
+ * Poor substitute for a real vsnprintf() function for systems
+ * that don't have them...
+ */
+
+#include "compiler.h"
+
+
+#include "nasmlib.h"
+#include "error.h"
+
+#if !defined(HAVE_VSNPRINTF) && !defined(HAVE__VSNPRINTF)
+
+#define BUFFER_SIZE 65536 /* Bigger than any string we might print... */
+
+static char snprintf_buffer[BUFFER_SIZE];
+
+int vsnprintf(char *str, size_t size, const char *format, va_list ap)
+{
+ int rv, bytes;
+
+ if (size > BUFFER_SIZE) {
+ nasm_panic("vsnprintf: size (%llu) > BUFFER_SIZE (%d)",
+ (unsigned long long)size, BUFFER_SIZE);
+ size = BUFFER_SIZE;
+ }
+
+ rv = vsprintf(snprintf_buffer, format, ap);
+ if (rv >= BUFFER_SIZE)
+ nasm_panic("vsnprintf buffer overflow");
+
+ if (size > 0) {
+ if ((size_t)rv < size-1)
+ bytes = rv;
+ else
+ bytes = size-1;
+ memcpy(str, snprintf_buffer, bytes);
+ str[bytes] = '\0';
+ }
+
+ return rv;
+}
+
+#endif