summaryrefslogtreecommitdiff
path: root/app/bin/stringxtc.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-08 11:53:12 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-08 11:53:12 +0200
commite50482f994b6ebcce864a412111d376e99205cdb (patch)
treeff3192c6aaf213c4922521bed988e4ed4147f537 /app/bin/stringxtc.c
parentd3897ce090dbeb220ed2c782f095597e417cf3cc (diff)
parentb623f5953691b2a0614e6f1f4def86bdbb9a4113 (diff)
Update upstream source from tag 'upstream/5.2.0Beta2.1'
Update to upstream version '5.2.0Beta2.1' with Debian dir 1576f25f4c1496abfed44af31ead67d32c7be650
Diffstat (limited to 'app/bin/stringxtc.c')
-rw-r--r--app/bin/stringxtc.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/app/bin/stringxtc.c b/app/bin/stringxtc.c
new file mode 100644
index 0000000..483f1a6
--- /dev/null
+++ b/app/bin/stringxtc.c
@@ -0,0 +1,106 @@
+/** \file stringxtc.c
+ *
+ * Copyright (C) 1991, 1992 Linus Torvalds
+ */
+
+ /*
+ * stupid library routines.
+ */
+
+#include <ctype.h>
+#include <stddef.h>
+#include <errno.h>
+#include "include/stringxtc.h"
+
+/**
+ * strscpy - Copy a C-string into a sized buffer
+ * @dest: Where to copy the string to
+ * @src: Where to copy the string from
+ * @count: Size of destination buffer
+ *
+ * Copy the string, or as much of it as fits, into the dest buffer. The
+ * behavior is undefined if the string buffers overlap. The destination
+ * buffer is always NUL terminated, unless it's zero-sized.
+ *
+ * Preferred to strlcpy() since the API doesn't require reading memory
+ * from the src string beyond the specified "count" bytes, and since
+ * the return value is easier to error-check than strlcpy()'s.
+ * In addition, the implementation is robust to the string changing out
+ * from underneath it, unlike the current strlcpy() implementation.
+ *
+ * Preferred to strncpy() since it always returns a valid string, and
+ * doesn't unnecessarily force the tail of the destination buffer to be
+ * zeroed. If zeroing is desired please use strscpy_pad().
+ *
+ * Return: The number of characters copied (not including the trailing
+ * %NUL) or -E2BIG if the destination buffer wasn't big enough.
+ */
+
+size_t strscpy(char *dest, const char *src, size_t count)
+{
+ long res = 0;
+
+ if (count == 0)
+ return -E2BIG;
+
+ while (count) {
+ char c;
+
+ c = src[res];
+ dest[res] = c;
+ if (!c)
+ return res;
+ res++;
+ count--;
+ }
+
+ /* Hit buffer length without finding a NUL; force NUL-termination. */
+ if (res)
+ dest[res - 1] = '\0';
+
+ return -E2BIG;
+}
+
+/**
+ * Convert a string to lower case
+ * Taken from https://stackoverflow.com/questions/23618316/undefined-reference-to-strlwr
+ *
+ * \param str IN string to convert
+ * \return pointer to converted string
+ */
+
+char *
+XtcStrlwr(char *str)
+{
+ unsigned char *p = (unsigned char *)str;
+
+ while (*p) {
+ *p = tolower((unsigned char)*p);
+ p++;
+ }
+
+ return str;
+}
+
+/**
+ * Compare two strings case insensitive
+ * Taken from https://stackoverflow.com/questions/30733786/c99-remove-stricmp-and-strnicmp
+ *
+ * \param a, b IN strings to compare
+ * \return
+ */
+
+int
+XtcStricmp(const char *a, const char *b)
+{
+ int ca, cb;
+ do {
+ ca = (unsigned char) *a++;
+ cb = (unsigned char) *b++;
+ ca = tolower(toupper(ca));
+ cb = tolower(toupper(cb));
+ } while ((ca == cb) && (ca != '\0'));
+ return ca - cb;
+}
+
+