Implemented lots of new functions
This commit is contained in:
12
photon/libc/string/fread.c
Normal file
12
photon/libc/string/fread.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <__fio.h>
|
||||
|
||||
size_t fread(void *ptr, size_t size, size_t count, FILE *fp)
|
||||
{
|
||||
if (!size || !count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int written = __fio_read(fp, ptr, size * count);
|
||||
return written / size;
|
||||
}
|
||||
0
photon/libc/string/fwrite.c
Normal file
0
photon/libc/string/fwrite.c
Normal file
19
photon/libc/string/strcmp.c
Normal file
19
photon/libc/string/strcmp.c
Normal file
@@ -0,0 +1,19 @@
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; s1[i] == s2[i]; i++)
|
||||
if (s1[i] == '\0')
|
||||
return 0;
|
||||
|
||||
return s1[i] - s2[i];
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, unsigned int n)
|
||||
{
|
||||
for (; n > 0; s1++, s2++, --n)
|
||||
if (*s1 != *s2)
|
||||
return ((*(unsigned char *)s1 < *(unsigned char *)s2) ? -1 : 1);
|
||||
else if (*s1 == '\0')
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
26
photon/libc/string/strcpy.c
Normal file
26
photon/libc/string/strcpy.c
Normal file
@@ -0,0 +1,26 @@
|
||||
char *strcpy(char *output, const char *input)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; input[i] != 0; i++) {
|
||||
output[i] = input[i];
|
||||
}
|
||||
|
||||
output[i] = '\0';
|
||||
return output;
|
||||
}
|
||||
|
||||
char *strncpy(char *output, const char *input, unsigned int count)
|
||||
{
|
||||
unsigned int size = count;
|
||||
unsigned int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
output[i] = input[i];
|
||||
|
||||
if (input[i] == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
output[i] = '\0';
|
||||
return output;
|
||||
}
|
||||
11
photon/libc/string/strdup.c
Normal file
11
photon/libc/string/strdup.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *strdup(const char *str)
|
||||
{
|
||||
size_t len = strlen(str);
|
||||
char *out = malloc(len + 1);
|
||||
memcpy(out, str, len);
|
||||
out[len] = 0;
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user