summaryrefslogtreecommitdiff
path: root/src/MSL_C.PPCEABI.bare.H/string.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-02-02 17:29:19 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-02-03 13:27:06 -0400
commitf2eabdb6257c09cf2890dac5e9737912728542af (patch)
tree3b46f6787185d65605651a0f48776dc9779ce648 /src/MSL_C.PPCEABI.bare.H/string.c
parenteef1dd840b7cecac28c2e6b0574707b90a37d4e7 (diff)
global: Add rest of Dolphin SDK proper, add MSL, and MetroTRK
Finally, it links properly.
Diffstat (limited to 'src/MSL_C.PPCEABI.bare.H/string.c')
-rw-r--r--src/MSL_C.PPCEABI.bare.H/string.c201
1 files changed, 201 insertions, 0 deletions
diff --git a/src/MSL_C.PPCEABI.bare.H/string.c b/src/MSL_C.PPCEABI.bare.H/string.c
new file mode 100644
index 0000000..82ca568
--- /dev/null
+++ b/src/MSL_C.PPCEABI.bare.H/string.c
@@ -0,0 +1,201 @@
+#include "string.h"
+
+size_t strlen(const char* str) {
+ size_t len = -1;
+ unsigned char* p = (unsigned char*)str - 1;
+ do {
+ len++;
+ } while (*++p);
+ return len;
+}
+
+char*(strcpy)(char* dst, const char* src) {
+ unsigned char *destb, *fromb;
+ unsigned int w, t, align;
+ unsigned int k1;
+ unsigned int k2;
+
+ fromb = (unsigned char*)src;
+ destb = (unsigned char*)dst;
+
+ if ((align = ((int)fromb & 3)) != ((int)destb & 3)) {
+ goto bytecopy;
+ }
+
+ if (align) {
+ if ((*destb = *fromb) == 0) {
+ return dst;
+ }
+
+ for (align = 3 - align; align; align--) {
+ if ((*(++destb) = *(++fromb)) == 0) {
+ return dst;
+ }
+ }
+ ++destb;
+ ++fromb;
+ }
+
+ k1 = 0x80808080;
+ k2 = 0xfefefeff;
+
+ w = *((int*)(fromb));
+ t = w + k2;
+ t &= k1;
+ if (t) {
+ goto bytecopy;
+ }
+
+ --((int*)(destb));
+
+ do {
+ *(++((int*)(destb))) = w;
+ w = *(++((int*)(fromb)));
+
+ t = w + k2;
+ t &= k1;
+ if (t)
+ goto adjust;
+ } while (1);
+
+adjust:
+ ++((int*)(destb));
+
+bytecopy:
+ if ((*destb = *fromb) == 0)
+ return (dst);
+ do {
+ if ((*(++destb) = *(++fromb)) == 0)
+ return dst;
+ } while (1);
+
+ return dst;
+}
+
+char* strncpy(char* dst, const char* src, size_t n) {
+ const unsigned char* p = (const unsigned char*)src - 1;
+ unsigned char* q = (unsigned char*)dst - 1;
+ unsigned char zero = 0;
+
+ n++;
+
+ while (--n)
+ if (!(*++q = *++p)) {
+ while (--n)
+ *++q = 0;
+ break;
+ }
+
+ return dst;
+}
+
+int strcmp(const char* str1, const char* str2) {
+ unsigned char* left = (unsigned char*)str1;
+ unsigned char* right = (unsigned char*)str2;
+ unsigned int k1, k2, align, l1, r1, x;
+
+ l1 = *left;
+ r1 = *right;
+ if (l1 - r1) {
+ return l1 - r1;
+ }
+
+ if ((align = ((int)left & 3)) != ((int)right & 3)) {
+ goto bytecopy;
+ }
+ if (align) {
+ if (l1 == 0) {
+ return 0;
+ }
+ for (align = 3 - align; align; align--) {
+ l1 = *(++left);
+ r1 = *(++right);
+ if (l1 - r1) {
+ return l1 - r1;
+ }
+ if (l1 == 0) {
+ return 0;
+ }
+ }
+ left++;
+ right++;
+ }
+
+ k1 = 0x80808080;
+ k2 = 0xfefefeff;
+
+ l1 = *(int*)left;
+ r1 = *(int*)right;
+ x = l1 + k2;
+ if (x & k1) {
+ goto adjust;
+ }
+ while (l1 == r1) {
+ l1 = *(++((int*)(left)));
+ r1 = *(++((int*)(right)));
+ x = l1 + k2;
+ if (x & k1) {
+ goto adjust;
+ }
+ }
+
+ if (l1 > r1) {
+ return 1;
+ }
+
+ return -1;
+
+adjust:
+ l1 = *left;
+ r1 = *right;
+ if (l1 - r1) {
+ return l1 - r1;
+ }
+
+bytecopy:
+ if (l1 == 0) {
+ return 0;
+ }
+
+ do {
+ l1 = *(++left);
+ r1 = *(++right);
+ if (l1 - r1) {
+ return l1 - r1;
+ }
+ if (l1 == 0) {
+ return 0;
+ }
+ } while (1);
+}
+
+int strncmp(const char* str1, const char* str2, size_t n) {
+ const unsigned char* p1 = (unsigned char*)str1 - 1;
+ const unsigned char* p2 = (unsigned char*)str2 - 1;
+ unsigned long c1, c2;
+
+ n++;
+
+ while (--n) {
+ if ((c1 = *++p1) != (c2 = *++p2)) {
+ return (c1 - c2);
+ } else if (!c1) {
+ break;
+ }
+ }
+
+ return 0;
+}
+
+char* strchr(const char* str, int chr) {
+ const unsigned char* p = (unsigned char*)str - 1;
+ unsigned long c = (chr & 0xff);
+ unsigned long ch;
+
+ while (ch = *++p) {
+ if (ch == c)
+ return ((char*)p);
+ }
+
+ return (c ? 0 : (char*)p);
+}