summaryrefslogtreecommitdiff
path: root/app/bin/stringxtc.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-24 21:26:53 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-24 21:26:53 +0200
commitdf247efec654e512242e4f4f1b0212034f9e01fe (patch)
tree25c02e16957f3aa613af30c140fd8e8a3d52fda6 /app/bin/stringxtc.c
parentd0b6a8a4ec298024f14f704f9e40a6f9d324ccf3 (diff)
parenta5ade52caa489cf0a713e0f02b764000d203140e (diff)
Merge branch 'release/debian/1%5.2.0Beta2.1-1' into masterHEADdebian/1%5.2.0Beta2.1-1master
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;
+}
+
+