summaryrefslogtreecommitdiff
path: root/miniany/libc-freestanding.c
diff options
context:
space:
mode:
Diffstat (limited to 'miniany/libc-freestanding.c')
-rw-r--r--miniany/libc-freestanding.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/miniany/libc-freestanding.c b/miniany/libc-freestanding.c
index 31808e7..a68a0c5 100644
--- a/miniany/libc-freestanding.c
+++ b/miniany/libc-freestanding.c
@@ -30,6 +30,33 @@ int strcmp( char *s1, char *s2 )
return *s1 - *s2;
}
+int memcmp( char *s1, char *s2, int n )
+{
+ while( n > 0 ) {
+ if( *s1 != *s2 ) {
+ return *s1 - *s2;
+ }
+ n--;
+ s1++;
+ s2++;
+ }
+
+ return 0;
+}
+
+char *memset( char *d, int c, int n )
+{
+ char *s = d;
+
+ while( n > 0 ) {
+ *s = (char)c;
+ s++;
+ n--;
+ }
+
+ return d;
+}
+
int isspace( int c )
{
if( c == ' ' || c == '\r' || c == '\n' || c == '\t' ) return 1;
@@ -132,9 +159,10 @@ enum {
static void print_char( int fd, int c )
{
- /* gcc 10 and 11 think on -O1 and -O2 that s can be held in registers, thus
- * clobbering the output? Let's put a volatile here seems to help. Neither
- * clang nor tcc show this behaviour..
+ /* gcc 10 and 11 think on -Os, -O1 and -O2 that 's' can be held
+ * in registers, thus clobbering the output? Let's put a
+ * volatile here seems to help. Neither clang, pcc or tcc show
+ * this behaviour..
*/
volatile char s[1];
s[0] = c;
@@ -396,17 +424,18 @@ void free( char *ptr )
}
}
-char *memcpy( char *d, char *s, int len )
+char *memcpy( char *d, char *s, int n )
{
char *p;
char *q;
p = s;
q = d;
- while( len-- ) {
+ while( n > 0 ) {
*q = *p;
q++;
p++;
+ n--;
}
return d;