From 9cb9a9b4d7afb76c8cf4408e5992db7b2937798a Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 30 Jan 2021 10:29:07 +1000 Subject: [PATCH] Decompile strlen --- src/include/PR/os_misc.h | 2 +- src/lib/ultra/libc/string.c | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/include/PR/os_misc.h b/src/include/PR/os_misc.h index f72da88d3..cd5e47de4 100644 --- a/src/include/PR/os_misc.h +++ b/src/include/PR/os_misc.h @@ -13,7 +13,7 @@ f32 sinf(f32 arg0); f32 sqrtf(f32 arg0); void *memcpy(void *, const void *, size_t); -u32 strlen(char *str); +size_t strlen(const char *s); char *strchr(const char *s, int c); #endif diff --git a/src/lib/ultra/libc/string.c b/src/lib/ultra/libc/string.c index aaea58dbf..3e606be72 100644 --- a/src/lib/ultra/libc/string.c +++ b/src/lib/ultra/libc/string.c @@ -17,21 +17,16 @@ glabel memcpy /* 4a608: 00801025 */ or $v0,$a0,$zero ); -GLOBAL_ASM( -glabel strlen -/* 4a60c: 908e0000 */ lbu $t6,0x0($a0) -/* 4a610: 00801825 */ or $v1,$a0,$zero -/* 4a614: 11c00005 */ beqz $t6,.L0004a62c -/* 4a618: 00000000 */ nop -/* 4a61c: 906f0001 */ lbu $t7,0x1($v1) -.L0004a620: -/* 4a620: 24630001 */ addiu $v1,$v1,0x1 -/* 4a624: 55e0fffe */ bnezl $t7,.L0004a620 -/* 4a628: 906f0001 */ lbu $t7,0x1($v1) -.L0004a62c: -/* 4a62c: 03e00008 */ jr $ra -/* 4a630: 00641023 */ subu $v0,$v1,$a0 -); +size_t strlen(const char *s) +{ + const char *sc = s; + + while (*sc) { + sc++; + } + + return sc - s; +} char *strchr(const char *s, int c) {