summaryrefslogtreecommitdiffstats
path: root/src/lib/kStuff/kHlp/Generic
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/kStuff/kHlp/Generic')
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpGetEnvUZ.c108
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpGetExt.c78
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpGetFilename.c72
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpInt2Ascii.c83
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpIsFilenameOnly.c61
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemChr.c51
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemComp.c71
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemCopy.c69
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemICompAscii.c80
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemMove.c100
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemPComp.c71
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemPCopy.c69
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemPMove.c99
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemPSet.c77
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpMemSet.c76
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpPage.c371
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrCat.c52
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrChr.c56
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrComp.c52
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrCopy.c46
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrICompAscii.c58
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrIPCompAscii.c59
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrLen.c44
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrNCat.c55
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrNComp.c52
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrNICompAscii.c59
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrNIPCompAscii.c61
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrNLen.c44
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrNPCat.c54
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrNPComp.c53
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrPCat.c51
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrPComp.c53
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrPCopy.c45
-rw-r--r--src/lib/kStuff/kHlp/Generic/kHlpStrRChr.c59
34 files changed, 2489 insertions, 0 deletions
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpGetEnvUZ.c b/src/lib/kStuff/kHlp/Generic/kHlpGetEnvUZ.c
new file mode 100644
index 0000000..4721af7
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpGetEnvUZ.c
@@ -0,0 +1,108 @@
+/* $Id: kHlpGetEnvUZ.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpEnv - kHlpGetEnvUZ.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpEnv.h>
+#include <k/kHlpString.h>
+
+
+/**
+ * Gets an environment variable and converts it to a KSIZE.
+ *
+ * @returns 0 and *pcb on success.
+ * @returns On failure see kHlpGetEnv.
+ * @param pszVar The name of the variable.
+ * @param pcb Where to put the value.
+ */
+KHLP_DECL(int) kHlpGetEnvUZ(const char *pszVar, KSIZE *pcb)
+{
+ KSIZE cb;
+ unsigned uBase;
+ char szVal[64];
+ KSIZE cchVal = sizeof(szVal);
+ const char *psz;
+ int rc;
+
+ *pcb = 0;
+ rc = kHlpGetEnv(pszVar, szVal, cchVal);
+ if (rc)
+ return rc;
+
+ /* figure out the base. */
+ uBase = 10;
+ psz = szVal;
+ if ( *psz == '0'
+ && (psz[1] == 'x' || psz[1] == 'X'))
+ {
+ uBase = 16;
+ psz += 2;
+ }
+
+ /* convert it up to the first unknown char. */
+ cb = 0;
+ for(;;)
+ {
+ const char ch = *psz;
+ unsigned uDigit;
+ if (!ch)
+ break;
+ else if (ch >= '0' && ch <= '9')
+ uDigit = ch - '0';
+ else if (ch >= 'a' && ch <= 'z')
+ uDigit = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'Z')
+ uDigit = ch - 'A' + 10;
+ else
+ break;
+ if (uDigit >= uBase)
+ break;
+
+ /* add the digit */
+ cb *= uBase;
+ cb += uDigit;
+
+ psz++;
+ }
+
+ /* check for unit */
+ if (*psz == 'm' || *psz == 'M')
+ cb *= 1024*1024;
+ else if (*psz == 'k' ||*psz == 'K')
+ cb *= 1024;
+ else if (*psz == 'g' || *psz == 'G')
+ cb *= 1024*1024*1024;
+
+ *pcb = cb;
+ return 0;
+}
+
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpGetExt.c b/src/lib/kStuff/kHlp/Generic/kHlpGetExt.c
new file mode 100644
index 0000000..7e338fa
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpGetExt.c
@@ -0,0 +1,78 @@
+/* $Id: kHlpGetExt.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpPath - kHlpGetExt and kHlpGetSuff.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpPath.h>
+#include <k/kHlpString.h>
+
+
+/**
+ * Gets the filename suffix.
+ *
+ * @returns Pointer to where the suffix starts within the string pointed to by pszFilename.
+ * @returns Pointer to the terminator char if no suffix.
+ * @param pszFilename The filename to parse.
+ */
+KHLP_DECL(char *) kHlpGetSuff(const char *pszFilename)
+{
+ const char *pszDot = NULL;
+ pszFilename = kHlpGetFilename(pszFilename);
+ for (;;)
+ {
+ char ch = *pszFilename;
+ if (ch == '.')
+ {
+ while ((ch = *++pszFilename) == '.')
+ /* nothing */;
+ if (ch)
+ pszDot = pszFilename - 1;
+ }
+ if (!ch)
+ return (char *)(pszDot ? pszDot : pszFilename);
+ pszFilename++;
+ }
+}
+
+
+/**
+ * Gets the filename extention.
+ *
+ * @returns Pointer to where the extension starts within the string pointed to by pszFilename.
+ * @returns Pointer to the terminator char if no extension.
+ * @param pszFilename The filename to parse.
+ */
+KHLP_DECL(char *) kHlpGetExt(const char *pszFilename)
+{
+ char *psz = kHlpGetSuff(pszFilename);
+ return *psz ? psz + 1 : psz;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpGetFilename.c b/src/lib/kStuff/kHlp/Generic/kHlpGetFilename.c
new file mode 100644
index 0000000..c04293e
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpGetFilename.c
@@ -0,0 +1,72 @@
+/* $Id: kHlpGetFilename.c 85 2016-09-06 03:21:04Z bird $ */
+/** @file
+ * kHlpPath - kHlpGetFilename.
+ */
+
+/*
+ * Copyright (c) 2006-2016 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpPath.h>
+#include <k/kHlpString.h>
+
+
+/**
+ * Get the pointer to the filename part of the name.
+ *
+ * @returns Pointer to where the filename starts within the string pointed to by pszFilename.
+ * @returns Pointer to the terminator char if no filename.
+ * @param pszFilename The filename to parse.
+ */
+KHLP_DECL(char *) kHlpGetFilename(const char *pszFilename)
+{
+ const char *pszLast = pszFilename;
+ for (;;)
+ {
+ char ch = *pszFilename;
+#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
+ if (ch == '/' || ch == '\\' || ch == ':')
+ {
+ while ((ch = *++pszFilename) == '/' || ch == '\\' || ch == ':')
+ /* nothing */;
+ pszLast = pszFilename;
+ }
+#else
+ if (ch == '/')
+ {
+ while ((ch = *++pszFilename) == '/')
+ /* betsuni */;
+ pszLast = pszFilename;
+ }
+#endif
+ if (ch)
+ pszFilename++;
+ else
+ return (char *)pszLast;
+ }
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpInt2Ascii.c b/src/lib/kStuff/kHlp/Generic/kHlpInt2Ascii.c
new file mode 100644
index 0000000..dcea005
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpInt2Ascii.c
@@ -0,0 +1,83 @@
+/* $Id: kHlpInt2Ascii.c 113 2018-07-12 11:34:27Z bird $ */
+/** @file
+ * kHlpString - kHlpInt2Ascii.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+/**
+ * Converts an signed integer to an ascii string.
+ *
+ * @returns psz.
+ * @param psz Pointer to the output buffer.
+ * @param cch The size of the output buffer.
+ * @param lVal The value.
+ * @param iBase The base to format it. (2,8,10 or 16)
+ */
+KHLP_DECL(char *) kHlpInt2Ascii(char *psz, KSIZE cch, long lVal, unsigned iBase)
+{
+ static const char s_szDigits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+ char *pszRet = psz;
+
+ if (psz != NULL)
+ {
+ if (cch >= (lVal < 0 ? 3U : 2U))
+ {
+ /* prefix */
+ if (lVal < 0)
+ {
+ *psz++ = '-';
+ cch--;
+ lVal = -lVal;
+ }
+
+ /* the digits */
+ do
+ {
+ *psz++ = s_szDigits[lVal % iBase];
+ cch--;
+ lVal /= iBase;
+ } while (lVal && cch > 1);
+
+ /* overflow indicator */
+ if (lVal)
+ psz[-1] = '+';
+ }
+ else if (cch > 1)
+ *psz++ = '+';
+ else if (cch < 1)
+ return pszRet;
+ *psz = '\0';
+ }
+ return pszRet;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpIsFilenameOnly.c b/src/lib/kStuff/kHlp/Generic/kHlpIsFilenameOnly.c
new file mode 100644
index 0000000..1cefa61
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpIsFilenameOnly.c
@@ -0,0 +1,61 @@
+/* $Id: kHlpIsFilenameOnly.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpPath - kHlpIsFilenameOnly.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpPath.h>
+#include <k/kHlpString.h>
+
+
+/**
+ * Checks if this is only a filename or if it contains any kind
+ * of drive, directory, or server specs.
+ *
+ * @returns 1 if this is a filename only.
+ * @returns 0 of it's isn't only a filename.
+ * @param pszFilename The filename to parse.
+ */
+KHLP_DECL(int) kHlpIsFilenameOnly(const char *pszFilename)
+{
+ for (;;)
+ {
+ const char ch = *pszFilename++;
+#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
+ if (ch == '/' || ch == '\\' || ch == ':')
+#else
+ if (ch == '/')
+#endif
+ return 0;
+ if (!ch)
+ return 1;
+ }
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemChr.c b/src/lib/kStuff/kHlp/Generic/kHlpMemChr.c
new file mode 100644
index 0000000..060916d
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemChr.c
@@ -0,0 +1,51 @@
+/* $Id: kHlpMemChr.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemChr.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(void *) kHlpMemChr(const void *pv1, int ch, KSIZE cb)
+{
+ const KU8 b = ch;
+ const KU8 *pb = (const KU8 *)pv1;
+
+ while (cb-- > 0)
+ {
+ if (*pb == b)
+ return (void *)pb;
+ pb++;
+ }
+
+ return NULL;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemComp.c b/src/lib/kStuff/kHlp/Generic/kHlpMemComp.c
new file mode 100644
index 0000000..54d1999
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemComp.c
@@ -0,0 +1,71 @@
+/* $Id: kHlpMemComp.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemComp.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(int) kHlpMemComp(const void *pv1, const void *pv2, KSIZE cb)
+{
+ union
+ {
+ const void *pv;
+ const KU8 *pb;
+ const KUPTR *pu;
+ } u1, u2;
+
+ u1.pv = pv1;
+ u2.pv = pv2;
+
+ if (cb >= 32)
+ {
+ while (cb > sizeof(KUPTR))
+ {
+ cb -= sizeof(KUPTR);
+ if (*u1.pu != *u2.pu)
+ return *u1.pu > *u2.pu ? 1 : -1;
+ u1.pu++;
+ u2.pu++;
+ }
+ }
+
+ while (cb-- > 0)
+ {
+ if (u1.pb != u2.pb)
+ return u1.pb > u2.pb ? 1 : -1;
+ u1.pb++;
+ u2.pb++;
+ }
+
+ return 0;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemCopy.c b/src/lib/kStuff/kHlp/Generic/kHlpMemCopy.c
new file mode 100644
index 0000000..8674674
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemCopy.c
@@ -0,0 +1,69 @@
+/* $Id: kHlpMemCopy.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemCopy.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(void *) kHlpMemCopy(void *pv1, const void *pv2, KSIZE cb)
+{
+ union
+ {
+ void *pv;
+ KU8 *pb;
+ KUPTR *pu;
+ } u1;
+ union
+ {
+ const void *pv;
+ const KU8 *pb;
+ const KUPTR *pu;
+ } u2;
+
+ u1.pv = pv1;
+ u2.pv = pv2;
+
+ if (cb >= 32)
+ {
+ while (cb > sizeof(KUPTR))
+ {
+ cb -= sizeof(KUPTR);
+ *u1.pu++ = *u2.pu++;
+ }
+ }
+
+ while (cb-- > 0)
+ *u1.pb++ = *u2.pb++;
+
+ return pv1;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemICompAscii.c b/src/lib/kStuff/kHlp/Generic/kHlpMemICompAscii.c
new file mode 100644
index 0000000..6df5767
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemICompAscii.c
@@ -0,0 +1,80 @@
+/* $Id: kHlpMemICompAscii.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemICompAscii.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(int) kHlpMemICompAscii(const void *pv1, const void *pv2, KSIZE cb)
+{
+ union
+ {
+ const void *pv;
+ const KU8 *pb;
+ const KUPTR *pu;
+ } u1, u2;
+
+ u1.pv = pv1;
+ u2.pv = pv2;
+
+ if (cb >= 32)
+ {
+ while (cb > sizeof(KUPTR))
+ {
+ if (*u1.pu != *u2.pu)
+ break; /* hand it on to the byte-by-byte routine. */
+ u1.pu++;
+ u2.pu++;
+ cb -= sizeof(KUPTR);
+ }
+ }
+
+ while (cb-- > 0)
+ {
+ if (u1.pb != u2.pb)
+ {
+ KU8 ch1 = *u1.pb;
+ KU8 ch2 = *u2.pb;
+ if (ch1 <= 'Z' && ch1 >= 'A')
+ ch1 += 'a' - 'A';
+ if (ch2 <= 'Z' && ch2 >= 'A')
+ ch2 += 'a' - 'A';
+ if (ch1 != ch2)
+ return ch1 > ch2 ? 1 : -1;
+ }
+ u1.pb++;
+ u2.pb++;
+ }
+
+ return 0;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemMove.c b/src/lib/kStuff/kHlp/Generic/kHlpMemMove.c
new file mode 100644
index 0000000..438a299
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemMove.c
@@ -0,0 +1,100 @@
+/* $Id: kHlpMemMove.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemMove.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(void *) kHlpMemMove(void *pv1, const void *pv2, KSIZE cb)
+{
+ union
+ {
+ void *pv;
+ KU8 *pb;
+ KUPTR *pu;
+ } u1;
+ union
+ {
+ const void *pv;
+ volatile KU8 *pb;
+ volatile KUPTR *pu;
+ } u2;
+
+ u1.pv = pv1;
+ u2.pv = pv2;
+
+ if ((KUPTR)u1.pb <= (KUPTR)u2.pb)
+ {
+ /* forward copy */
+ if (cb >= 32)
+ {
+ while (cb > sizeof(KUPTR))
+ {
+ KUPTR u = *u2.pu++;
+ *u1.pu++ = u;
+ cb -= sizeof(KUPTR);
+ }
+ }
+
+ while (cb-- > 0)
+ {
+ KU8 b = *u2.pb++;
+ *u1.pb++ = b;
+ }
+ }
+ else
+ {
+ /* backwards copy */
+ u1.pb += cb;
+ u2.pb += cb;
+
+ if (cb >= 32)
+ {
+ while (cb > sizeof(KUPTR))
+ {
+ KUPTR u = *--u2.pu;
+ *--u1.pu = u;
+ cb -= sizeof(KUPTR);
+ }
+ }
+
+ while (cb-- > 0)
+ {
+ KU8 b = *--u2.pb;
+ *--u1.pb = b;
+ }
+ }
+
+ return pv1;
+}
+
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemPComp.c b/src/lib/kStuff/kHlp/Generic/kHlpMemPComp.c
new file mode 100644
index 0000000..d678517
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemPComp.c
@@ -0,0 +1,71 @@
+/* $Id: kHlpMemPComp.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemPComp.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(void *) kHlpMemPComp(const void *pv1, const void *pv2, KSIZE cb)
+{
+ union
+ {
+ const void *pv;
+ const KU8 *pb;
+ const KUPTR *pu;
+ } u1, u2;
+
+ u1.pv = pv1;
+ u2.pv = pv2;
+
+ if (cb >= 32)
+ {
+ while (cb > sizeof(KUPTR))
+ {
+ if (*u1.pu != *u2.pu)
+ break; /* over to mr. byte-by-byte */
+ u1.pu++;
+ u2.pu++;
+ cb -= sizeof(KUPTR);
+ }
+ }
+
+ while (cb-- > 0)
+ {
+ if (u1.pb != u2.pb)
+ return (void *)u1.pb;
+ u1.pb++;
+ u2.pb++;
+ }
+
+ return NULL;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemPCopy.c b/src/lib/kStuff/kHlp/Generic/kHlpMemPCopy.c
new file mode 100644
index 0000000..0b7945e
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemPCopy.c
@@ -0,0 +1,69 @@
+/* $Id: kHlpMemPCopy.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemPCopy.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(void *) kHlpMemPCopy(void *pv1, const void *pv2, KSIZE cb)
+{
+ union
+ {
+ void *pv;
+ KU8 *pb;
+ KUPTR *pu;
+ } u1;
+ union
+ {
+ const void *pv;
+ const KU8 *pb;
+ const KUPTR *pu;
+ } u2;
+
+ u1.pv = pv1;
+ u2.pv = pv2;
+
+ if (cb >= 32)
+ {
+ while (cb > sizeof(KUPTR))
+ {
+ cb -= sizeof(KUPTR);
+ *u1.pu++ = *u2.pu++;
+ }
+ }
+
+ while (cb-- > 0)
+ *u1.pb++ = *u2.pb++;
+
+ return u1.pb;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemPMove.c b/src/lib/kStuff/kHlp/Generic/kHlpMemPMove.c
new file mode 100644
index 0000000..6276519
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemPMove.c
@@ -0,0 +1,99 @@
+/* $Id: kHlpMemPMove.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemPMove.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(void *) kHlpMemPMove(void *pv1, const void *pv2, KSIZE cb)
+{
+ union
+ {
+ void *pv;
+ KU8 *pb;
+ KUPTR *pu;
+ } u1;
+ union
+ {
+ const void *pv;
+ volatile KU8 *pb;
+ volatile KUPTR *pu;
+ } u2;
+
+ u1.pv = pv1;
+ u2.pv = pv2;
+
+ if ((KUPTR)u1.pb <= (KUPTR)u2.pb)
+ {
+ /* forwards copy */
+ if (cb >= 32)
+ {
+ while (cb > sizeof(KUPTR))
+ {
+ KUPTR u = *u2.pu++;
+ *u1.pu++ = u;
+ cb -= sizeof(KUPTR);
+ }
+ }
+
+ while (cb-- > 0)
+ {
+ KU8 b = *u2.pb++;
+ *u1.pb++ = b;
+ }
+
+ return u1.pb;
+ }
+
+ /* backwards copy */
+ u1.pb += cb;
+ u2.pb += cb;
+
+ if (cb >= 32)
+ {
+ while (cb > sizeof(KUPTR))
+ {
+ KUPTR u = *--u2.pu;
+ *--u1.pu = u;
+ cb -= sizeof(KUPTR);
+ }
+ }
+
+ while (cb-- > 0)
+ {
+ KU8 b = *--u2.pb;
+ *--u1.pb = b;
+ }
+
+ return (KU8 *)pv1 + cb;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemPSet.c b/src/lib/kStuff/kHlp/Generic/kHlpMemPSet.c
new file mode 100644
index 0000000..0a77e1a
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemPSet.c
@@ -0,0 +1,77 @@
+/* $Id: kHlpMemPSet.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemPSet.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(void *) kHlpMemPSet(void *pv1, int ch, KSIZE cb)
+{
+ union
+ {
+ void *pv;
+ KU8 *pb;
+ KUPTR *pu;
+ } u1;
+
+ u1.pv = pv1;
+
+ if (cb >= 32)
+ {
+ KUPTR u = ch & 0xff;
+#if K_ARCH_BITS > 8
+ u |= u << 8;
+#endif
+#if K_ARCH_BITS > 16
+ u |= u << 16;
+#endif
+#if K_ARCH_BITS > 32
+ u |= u << 32;
+#endif
+#if K_ARCH_BITS > 64
+ u |= u << 64;
+#endif
+
+ while (cb > sizeof(KUPTR))
+ {
+ cb -= sizeof(KUPTR);
+ *u1.pu++ = u;
+ }
+ }
+
+ while (cb-- > 0)
+ *u1.pb++ = ch;
+
+ return u1.pb;
+}
+
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpMemSet.c b/src/lib/kStuff/kHlp/Generic/kHlpMemSet.c
new file mode 100644
index 0000000..4e986ae
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpMemSet.c
@@ -0,0 +1,76 @@
+/* $Id: kHlpMemSet.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpMemSet.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(void *) kHlpMemSet(void *pv1, int ch, KSIZE cb)
+{
+ union
+ {
+ void *pv;
+ KU8 *pb;
+ KUPTR *pu;
+ } u1;
+
+ u1.pv = pv1;
+
+ if (cb >= 32)
+ {
+ KUPTR u = ch & 0xff;
+#if K_ARCH_BITS > 8
+ u |= u << 8;
+#endif
+#if K_ARCH_BITS > 16
+ u |= u << 16;
+#endif
+#if K_ARCH_BITS > 32
+ u |= u << 32;
+#endif
+#if K_ARCH_BITS > 64
+ u |= u << 64;
+#endif
+
+ while (cb > sizeof(KUPTR))
+ {
+ cb -= sizeof(KUPTR);
+ *u1.pu++ = u;
+ }
+ }
+
+ while (cb-- > 0)
+ *u1.pb++ = ch;
+
+ return pv1;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpPage.c b/src/lib/kStuff/kHlp/Generic/kHlpPage.c
new file mode 100644
index 0000000..f915f58
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpPage.c
@@ -0,0 +1,371 @@
+/* $Id: kHlpPage.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlp - Generic Page Memory Functions.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpAlloc.h>
+#include <k/kHlpAssert.h>
+
+#if K_OS == K_OS_DARWIN \
+ || K_OS == K_OS_FREEBSD \
+ || K_OS == K_OS_LINUX \
+ || K_OS == K_OS_NETBSD \
+ || K_OS == K_OS_OPENBSD \
+ || K_OS == K_OS_SOLARIS
+# include <k/kHlpSys.h>
+# include <sys/mman.h>
+
+#elif K_OS == K_OS_OS2
+# define INCL_BASE
+# define INCL_ERRORS
+# include <os2.h>
+
+#elif K_OS == K_OS_WINDOWS
+# include <Windows.h>
+
+#else
+# error "port me"
+#endif
+
+
+/*******************************************************************************
+* Global Variables *
+*******************************************************************************/
+#if K_OS == K_OS_DARWIN \
+ || K_OS == K_OS_FREEBSD \
+ || K_OS == K_OS_LINUX \
+ || K_OS == K_OS_NETBSD \
+ || K_OS == K_OS_OPENBSD \
+ || K_OS == K_OS_SOLARIS
+/* nothing */
+#elif K_OS == K_OS_OS2
+/** The base of the loader stub object. <kLdr Hack>
+ * The OS/2 exe stub consists of a single data object. When allocating memory
+ * for an executable, we'll have to reuse this. */
+static void *g_pvStub = NULL;
+/** The size of the stub object - 0 if no stub. <kLdr Hack> */
+static KSIZE g_cbStub = 0;
+
+#elif K_OS == K_OS_WINDOWS
+/** The system info. */
+static SYSTEM_INFO g_SystemInfo;
+#else
+# error "port me"
+#endif
+
+
+
+#if K_OS == K_OS_DARWIN \
+ || K_OS == K_OS_FREEBSD \
+ || K_OS == K_OS_LINUX \
+ || K_OS == K_OS_NETBSD \
+ || K_OS == K_OS_OPENBSD \
+ || K_OS == K_OS_SOLARIS
+static int kHlpPageProtToNative(KPROT enmProt)
+{
+ switch (enmProt)
+ {
+ case KPROT_NOACCESS: return PROT_NONE;
+ case KPROT_READONLY: return PROT_READ;
+ case KPROT_READWRITE: return PROT_READ | PROT_WRITE;
+ case KPROT_EXECUTE: return PROT_EXEC;
+ case KPROT_EXECUTE_READ: return PROT_EXEC | PROT_READ;
+ case KPROT_EXECUTE_READWRITE: return PROT_EXEC | PROT_READ | PROT_WRITE;
+ default:
+ kHlpAssert(0);
+ return ~0U;
+ }
+}
+
+#elif K_OS == K_OS_OS2
+static ULONG kHlpPageProtToNative(KPROT enmProt)
+{
+ switch (enmProt)
+ {
+ case KPROT_NOACCESS: return PAG_EXECUTE | PAG_READ | PAG_WRITE;
+ case KPROT_READONLY: return PAG_COMMIT | PAG_READ;
+ case KPROT_READWRITE: return PAG_COMMIT | PAG_READ | PAG_WRITE;
+ case KPROT_EXECUTE: return PAG_COMMIT | PAG_EXECUTE;
+ case KPROT_EXECUTE_READ: return PAG_COMMIT | PAG_EXECUTE | PAG_READ;
+ case KPROT_EXECUTE_READWRITE: return PAG_COMMIT | PAG_EXECUTE | PAG_READ | PAG_WRITE;
+ default:
+ kHlpAssert(0);
+ return ~0U;
+ }
+}
+#elif K_OS == K_OS_WINDOWS
+static DWORD kHlpPageProtToNative(KPROT enmProt)
+{
+ switch (enmProt)
+ {
+ case KPROT_NOACCESS: return PAGE_NOACCESS;
+ case KPROT_READONLY: return PAGE_READONLY;
+ case KPROT_READWRITE: return PAGE_READWRITE;
+ case KPROT_EXECUTE: return PAGE_EXECUTE;
+ case KPROT_EXECUTE_READ: return PAGE_EXECUTE_READ;
+ case KPROT_EXECUTE_READWRITE: return PAGE_EXECUTE_READWRITE;
+ default:
+ kHlpAssert(0);
+ return ~0U;
+ }
+}
+#endif
+
+
+
+/**
+ * Allocate a chunk of memory with page granularity.
+ *
+ * @returns 0 on success, non-zero OS status code on failure.
+ * @param ppv Where to store the address of the allocated memory.
+ * If fFixed is set, *ppv will on entry contain the desired address (page aligned).
+ * @param cb Number of bytes. Page aligned.
+ * @param enmProt The new protection. Copy-on-write is invalid.
+ */
+KHLP_DECL(int) kHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, KBOOL fFixed)
+{
+#if K_OS == K_OS_DARWIN \
+ || K_OS == K_OS_FREEBSD \
+ || K_OS == K_OS_LINUX \
+ || K_OS == K_OS_NETBSD \
+ || K_OS == K_OS_OPENBSD \
+ || K_OS == K_OS_SOLARIS
+ void *pv;
+
+ pv = kHlpSys_mmap(fFixed ? *ppv : NULL, cb, kHlpPageProtToNative(enmProt),
+ fFixed ? MAP_FIXED | MAP_ANON: MAP_ANON, -1, 0);
+ if ((KIPTR)pv < 256)
+ {
+ kHlpAssert(0);
+ return (int)(KIPTR)pv; /** @todo convert errno to kErrors */
+ }
+ *ppv = pv;
+ return 0;
+
+#elif K_OS == K_OS_OS2
+ APIRET rc;
+ ULONG fFlags = kHlpPageProtToNative(enmProt);
+
+ if (!fFixed)
+ {
+ /* simple */
+ rc = DosAllocMem(ppv, cb, fFlags | OBJ_ANY);
+ if (rc == ERROR_INVALID_PARAMETER)
+ rc = DosAllocMem(ppv, cb, fFlags);
+ }
+ else
+ {
+ /* not so simple. */
+ /** @todo I've got code for this in libc somewhere. */
+ rc = -1;
+ }
+ if (!rc)
+ return 0;
+ kHlpAssert(0);
+ return rc;
+
+#elif K_OS == K_OS_WINDOWS
+ /* (We don't have to care about the stub here, because the stub will be unmapped before we get here.) */
+ int rc;
+ DWORD fProt = kHlpPageProtToNative(enmProt);
+
+ if (!g_SystemInfo.dwPageSize)
+ GetSystemInfo(&g_SystemInfo);
+
+ *ppv = VirtualAlloc(fFixed ? *ppv : NULL, cb, MEM_COMMIT, fProt);
+ if (*ppv != NULL)
+ return 0;
+ rc = GetLastError();
+ kHlpAssert(0);
+ return rc;
+
+#else
+# error "port me"
+#endif
+}
+
+
+/**
+ * Change the protection of one or more pages in an allocation.
+ *
+ * (This will of course only work correctly on memory allocated by kHlpPageAlloc().)
+ *
+ * @returns 0 on success, non-zero OS status code on failure.
+ * @param pv First page. Page aligned.
+ * @param cb Number of bytes. Page aligned.
+ * @param enmProt The new protection. Copy-on-write is invalid.
+ */
+KHLP_DECL(int) kHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt)
+{
+#if K_OS == K_OS_DARWIN \
+ || K_OS == K_OS_FREEBSD \
+ || K_OS == K_OS_LINUX \
+ || K_OS == K_OS_NETBSD \
+ || K_OS == K_OS_OPENBSD \
+ || K_OS == K_OS_SOLARIS
+ int rc;
+
+ rc = kHlpSys_mprotect(pv, cb, kHlpPageProtToNative(enmProt));
+ if (!rc)
+ return 0;
+ /** @todo convert errno -> kErrors */
+ kHlpAssert(0);
+ return rc;
+
+#elif K_OS == K_OS_OS2
+ APIRET rc;
+ ULONG fFlags = kHlpPageProtToNative(enmProt);
+
+ /*
+ * The non-stub pages.
+ */
+ rc = DosSetMem(pv, cb, fFlags);
+ if (rc && fFlags != PAG_DECOMMIT)
+ rc = DosSetMem(pv, cb, fFlags | PAG_COMMIT);
+ if (rc)
+ {
+ /* Try page by page. */
+ while (cb > 0)
+ {
+ rc = DosSetMem(pv, 0x1000, fFlags);
+ if (rc && fFlags != PAG_DECOMMIT)
+ rc = DosSetMem(pv, 0x1000, fFlags | PAG_COMMIT);
+ if (rc)
+ return rc;
+ pv = (void *)((KUPTR)pv + 0x1000);
+ cb -= 0x1000;
+ }
+ }
+ kHlpAssert(!rc);
+ return rc;
+
+#elif K_OS == K_OS_WINDOWS
+ DWORD fOldProt = 0;
+ DWORD fProt = kHlpPageProtToNative(enmProt);
+ int rc = 0;
+
+ if (!VirtualProtect(pv, cb, fProt, &fOldProt))
+ {
+ rc = GetLastError();
+ kHlpAssert(0);
+ }
+ return rc;
+#else
+# error "port me"
+#endif
+}
+
+
+/**
+ * Free memory allocated by kHlpPageAlloc().
+ *
+ * @returns 0 on success, non-zero OS status code on failure.
+ * @param pv The address returned by kHlpPageAlloc().
+ * @param cb The byte count requested from kHlpPageAlloc().
+ */
+KHLP_DECL(int) kHlpPageFree(void *pv, KSIZE cb)
+{
+#if K_OS == K_OS_DARWIN \
+ || K_OS == K_OS_FREEBSD \
+ || K_OS == K_OS_LINUX \
+ || K_OS == K_OS_NETBSD \
+ || K_OS == K_OS_OPENBSD \
+ || K_OS == K_OS_SOLARIS
+ int rc;
+
+ rc = kHlpSys_munmap(pv, cb);
+ if (!rc)
+ return 0;
+ /** @todo convert errno -> kErrors */
+ return rc;
+
+#elif K_OS == K_OS_OS2
+ APIRET rc;
+
+ /*
+ * Deal with any portion overlapping with the stub.
+ */
+ KUPTR offStub = (KUPTR)pv - (KUPTR)g_pvStub;
+ if (offStub < g_cbStub)
+ {
+ /* decommit the pages in the stub. */
+ KSIZE cbStub = K_MIN(g_cbStub - offStub, cb);
+ rc = DosSetMem(pv, cbStub, PAG_DECOMMIT);
+ if (rc)
+ {
+ /* Page by page, ignoring errors after the first success. */
+ while (cbStub > 0)
+ {
+ if (!DosSetMem(pv, 0x1000, PAG_DECOMMIT))
+ rc = 0;
+ pv = (void *)((KUPTR)pv + 0x1000);
+ cbStub -= 0x1000;
+ cb -= 0x1000;
+ }
+ if (rc)
+ {
+ kHlpAssert(!rc);
+ return rc;
+ }
+ }
+ else
+ {
+ cb -= cbStub;
+ if (!cb)
+ return 0;
+ pv = (void *)((KUPTR)pv + cbStub);
+ }
+ }
+
+ /*
+ * Free the object.
+ */
+ rc = DosFreeMem(pv);
+ kHlpAssert(!rc);
+ return rc;
+
+#elif K_OS == K_OS_WINDOWS
+ /*
+ * Free the object.
+ */
+ int rc = 0;
+ if (!VirtualFree(pv, 0 /*cb*/, MEM_RELEASE))
+ {
+ rc = GetLastError();
+ kHlpAssert(0);
+ }
+ return rc;
+
+#else
+# error "port me"
+#endif
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrCat.c b/src/lib/kStuff/kHlp/Generic/kHlpStrCat.c
new file mode 100644
index 0000000..82900ea
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrCat.c
@@ -0,0 +1,52 @@
+/* $Id: kHlpStrCat.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrCat.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrCat(char *psz1, const char *psz2)
+{
+ char ch;
+ char *pszDst = psz1;
+
+ while (*pszDst != '\0')
+ pszDst++;
+ do
+ {
+ ch = *psz2++;
+ *pszDst++ = ch;
+ } while (ch != '\0');
+
+ return psz1;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrChr.c b/src/lib/kStuff/kHlp/Generic/kHlpStrChr.c
new file mode 100644
index 0000000..acff27c
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrChr.c
@@ -0,0 +1,56 @@
+/* $Id: kHlpStrChr.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrChr.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrChr(const char *psz, int ch)
+{
+ if (!ch)
+ {
+ while (*psz)
+ psz++;
+ return (char *)psz;
+ }
+
+ for (;;)
+ {
+ int chCur = *psz;
+ if (chCur == ch)
+ return (char *)psz;
+ if (!chCur)
+ return NULL;
+ psz++;
+ }
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrComp.c b/src/lib/kStuff/kHlp/Generic/kHlpStrComp.c
new file mode 100644
index 0000000..12bdaaf
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrComp.c
@@ -0,0 +1,52 @@
+/* $Id: kHlpStrComp.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrComp.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(int) kHlpStrComp(const char *psz1, const char *psz2)
+{
+ for (;;)
+ {
+ char ch1 = *psz1;
+ char ch2 = *psz2;
+ if (ch1 != ch2)
+ return ch1 > ch2 ? 1 : -1;
+ if (!ch1)
+ return 0;
+ psz1++;
+ psz2++;
+ }
+}
+
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrCopy.c b/src/lib/kStuff/kHlp/Generic/kHlpStrCopy.c
new file mode 100644
index 0000000..86efbab
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrCopy.c
@@ -0,0 +1,46 @@
+/* $Id: kHlpStrCopy.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrCopy.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrCopy(char *pszDst, const char *pszSrc)
+{
+ char ch;
+ char *psz = pszDst;
+ do
+ *psz++ = ch = *pszSrc;
+ while (ch);
+ return pszDst;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrICompAscii.c b/src/lib/kStuff/kHlp/Generic/kHlpStrICompAscii.c
new file mode 100644
index 0000000..446f61f
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrICompAscii.c
@@ -0,0 +1,58 @@
+/* $Id: kHlpStrICompAscii.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrICompAscii.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(int) kHlpStrICompAscii(const char *psz1, const char *psz2)
+{
+ for (;;)
+ {
+ char ch1 = *psz1;
+ char ch2 = *psz2;
+ if (ch1 != ch2)
+ {
+ if (ch1 <= 'Z' && ch1 >= 'A')
+ ch1 += 'a' - 'A';
+ if (ch2 <= 'Z' && ch2 >= 'A')
+ ch2 += 'a' - 'A';
+ if (ch1 != ch2)
+ return ch1 > ch2 ? 1 : -1;
+ }
+ if (!ch1)
+ return 0;
+ psz1++;
+ psz2++;
+ }
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrIPCompAscii.c b/src/lib/kStuff/kHlp/Generic/kHlpStrIPCompAscii.c
new file mode 100644
index 0000000..40d28f7
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrIPCompAscii.c
@@ -0,0 +1,59 @@
+/* $Id: kHlpStrIPCompAscii.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrIPCompAscii.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrIPCompAscii(const char *psz1, const char *psz2)
+{
+ for (;;)
+ {
+ char ch1 = *psz1;
+ char ch2 = *psz2;
+ if (ch1 != ch2)
+ {
+ if (ch1 <= 'Z' && ch1 >= 'A')
+ ch1 += 'a' - 'A';
+ if (ch2 <= 'Z' && ch2 >= 'A')
+ ch2 += 'a' - 'A';
+ if (ch1 != ch2)
+ return (char *)psz1;
+ }
+ if (!ch1)
+ return (char *)psz1;
+ psz1++;
+ psz2++;
+ }
+}
+
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrLen.c b/src/lib/kStuff/kHlp/Generic/kHlpStrLen.c
new file mode 100644
index 0000000..714c703
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrLen.c
@@ -0,0 +1,44 @@
+/* $Id: kHlpStrLen.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrLen.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(KSIZE) kHlpStrLen(const char *psz)
+{
+ const char *pszEnd = psz;
+ while (*pszEnd)
+ pszEnd++;
+ return pszEnd - psz;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrNCat.c b/src/lib/kStuff/kHlp/Generic/kHlpStrNCat.c
new file mode 100644
index 0000000..a311cb0
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrNCat.c
@@ -0,0 +1,55 @@
+/* $Id: kHlpStrNCat.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrNCat.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrNCat(char *psz1, const char *psz2, KSIZE cb)
+{
+ char ch;
+ char *pszDst = psz1;
+
+ while (*pszDst != '\0')
+ pszDst++;
+ while (cb-- > 0)
+ {
+ ch = *psz2++;
+ if (!ch)
+ break;
+ *pszDst++ = ch;
+ }
+ *pszDst = '\0';
+
+ return psz1;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrNComp.c b/src/lib/kStuff/kHlp/Generic/kHlpStrNComp.c
new file mode 100644
index 0000000..f46aa8a
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrNComp.c
@@ -0,0 +1,52 @@
+/* $Id: kHlpStrNComp.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrNComp.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(int) kHlpStrNComp(const char *psz1, const char *psz2, KSIZE cb)
+{
+ while (cb-- > 0)
+ {
+ char ch1 = *psz1;
+ char ch2 = *psz2;
+ if (ch1 != ch2)
+ return ch1 > ch2 ? 1 : -1;
+ if (!ch1)
+ break;
+ psz1++;
+ psz2++;
+ }
+ return 0;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrNICompAscii.c b/src/lib/kStuff/kHlp/Generic/kHlpStrNICompAscii.c
new file mode 100644
index 0000000..d9670a0
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrNICompAscii.c
@@ -0,0 +1,59 @@
+/* $Id: kHlpStrNICompAscii.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrNICompAscii.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(int) kHlpStrNICompAscii(const char *psz1, const char *psz2, KSIZE cb)
+{
+ while (cb-- > 0)
+ {
+ char ch1 = *psz1;
+ char ch2 = *psz2;
+ if (ch1 != ch2)
+ {
+ if (ch1 <= 'Z' && ch1 >= 'A')
+ ch1 += 'a' - 'A';
+ if (ch2 <= 'Z' && ch2 >= 'A')
+ ch2 += 'a' - 'A';
+ if (ch1 != ch2)
+ return ch1 > ch2 ? 1 : -1;
+ }
+ if (!ch1)
+ break;
+ psz1++;
+ psz2++;
+ }
+ return 0;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrNIPCompAscii.c b/src/lib/kStuff/kHlp/Generic/kHlpStrNIPCompAscii.c
new file mode 100644
index 0000000..976f197
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrNIPCompAscii.c
@@ -0,0 +1,61 @@
+/* $Id: kHlpStrNIPCompAscii.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrNIPCompAscii.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrNIPCompAscii(const char *psz1, const char *psz2, KSIZE cb)
+{
+ while (cb-- > 0)
+ {
+ char ch1 = *psz1;
+ char ch2 = *psz2;
+ if (ch1 != ch2)
+ {
+ if (ch1 <= 'Z' && ch1 >= 'A')
+ ch1 += 'a' - 'A';
+ if (ch2 <= 'Z' && ch2 >= 'A')
+ ch2 += 'a' - 'A';
+ if (ch1 != ch2)
+ return (char *)psz1;
+ }
+ if (!ch1)
+ break;
+ psz1++;
+ psz2++;
+ }
+ return NULL;
+}
+
+
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrNLen.c b/src/lib/kStuff/kHlp/Generic/kHlpStrNLen.c
new file mode 100644
index 0000000..bf1db6c
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrNLen.c
@@ -0,0 +1,44 @@
+/* $Id: kHlpStrNLen.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrNLen.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(KSIZE) kHlpStrNLen(const char *psz, KSIZE cchMax)
+{
+ const char *pszEnd = psz;
+ while (cchMax-- > 0 && *pszEnd)
+ pszEnd++;
+ return pszEnd - psz;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrNPCat.c b/src/lib/kStuff/kHlp/Generic/kHlpStrNPCat.c
new file mode 100644
index 0000000..cec0921
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrNPCat.c
@@ -0,0 +1,54 @@
+/* $Id: kHlpStrNPCat.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrNPCat.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrNPCat(char *pszDst, const char *pszSrc, KSIZE cb)
+{
+ char ch;
+
+ while (*pszDst != '\0')
+ pszDst++;
+ while (cb-- > 0)
+ {
+ ch = *pszSrc++;
+ if (!ch)
+ break;
+ *pszDst++ = ch;
+ }
+ *pszDst = '\0';
+
+ return pszDst;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrNPComp.c b/src/lib/kStuff/kHlp/Generic/kHlpStrNPComp.c
new file mode 100644
index 0000000..bafd05e
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrNPComp.c
@@ -0,0 +1,53 @@
+/* $Id: kHlpStrNPComp.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrNPComp.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrNPComp(const char *psz1, const char *psz2, KSIZE cb)
+{
+ while (cb-- > 0)
+ {
+ char ch1 = *psz1;
+ char ch2 = *psz2;
+ if (ch1 != ch2)
+ return (char *)psz1;
+ if (!ch1)
+ break;
+ psz1++;
+ psz2++;
+ }
+ return NULL;
+}
+
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrPCat.c b/src/lib/kStuff/kHlp/Generic/kHlpStrPCat.c
new file mode 100644
index 0000000..fc80f9c
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrPCat.c
@@ -0,0 +1,51 @@
+/* $Id: kHlpStrPCat.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrPCat.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrPCat(char *pszDst, const char *psz2)
+{
+ char ch;
+
+ while (*pszDst != '\0')
+ pszDst++;
+ do
+ {
+ ch = *psz2++;
+ *pszDst++ = ch;
+ } while (ch != '\0');
+
+ return pszDst - 1;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrPComp.c b/src/lib/kStuff/kHlp/Generic/kHlpStrPComp.c
new file mode 100644
index 0000000..3572427
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrPComp.c
@@ -0,0 +1,53 @@
+/* $Id: kHlpStrPComp.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrPComp.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrPComp(const char *psz1, const char *psz2)
+{
+ for (;;)
+ {
+ char ch1 = *psz1;
+ char ch2 = *psz2;
+ if (ch1 != ch2)
+ return (char *)psz1;
+ if (!ch1)
+ return NULL;
+ psz1++;
+ psz2++;
+ }
+}
+
+
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrPCopy.c b/src/lib/kStuff/kHlp/Generic/kHlpStrPCopy.c
new file mode 100644
index 0000000..821258c
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrPCopy.c
@@ -0,0 +1,45 @@
+/* $Id: kHlpStrPCopy.c 83 2016-08-30 18:38:12Z bird $ */
+/** @file
+ * kHlpString - kHlpStrPCopy.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrPCopy(char *pszDst, const char *pszSrc)
+{
+ char ch;
+ do
+ *pszDst++ = ch = *pszSrc++;
+ while (ch);
+ return pszDst - 1;
+}
+
diff --git a/src/lib/kStuff/kHlp/Generic/kHlpStrRChr.c b/src/lib/kStuff/kHlp/Generic/kHlpStrRChr.c
new file mode 100644
index 0000000..a712840
--- /dev/null
+++ b/src/lib/kStuff/kHlp/Generic/kHlpStrRChr.c
@@ -0,0 +1,59 @@
+/* $Id: kHlpStrRChr.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kHlpString - kHlpStrRChr.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KHLP_DECL(char *) kHlpStrRChr(const char *psz, int ch)
+{
+ char *pszLast;
+
+ if (!ch)
+ {
+ while (*psz)
+ psz++;
+ return (char *)psz;
+ }
+
+ pszLast = NULL;
+ for (;;)
+ {
+ int chCur = *psz;
+ if (chCur == ch)
+ pszLast = (char *)psz;
+ else if (!chCur)
+ return pszLast;
+ psz++;
+ }
+}
+