mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
string: memcmp()
This commit is contained in:
+18
-7
@@ -6,7 +6,7 @@ void *memcpy(void *d, void *s, size_t c) {
|
||||
uint8_t *sc = (uint8_t *)s;
|
||||
uint8_t *dc = (uint8_t *)d;
|
||||
|
||||
while(c--)
|
||||
while (c--)
|
||||
*dc++ = *sc++;
|
||||
|
||||
return d;
|
||||
@@ -14,7 +14,7 @@ void *memcpy(void *d, void *s, size_t c) {
|
||||
|
||||
void *memset(void *ptr, unsigned long value, size_t num) {
|
||||
char *p = (char *)ptr;
|
||||
while(num--)
|
||||
while (num--)
|
||||
*p++ = value;
|
||||
|
||||
return ptr;
|
||||
@@ -29,18 +29,18 @@ char *strcat(char *dest, const char *src) {
|
||||
|
||||
}
|
||||
int strcmp(const char *a, const char *b) {
|
||||
while(*a && (*a == *b)) {
|
||||
while (*a && (*a == *b)) {
|
||||
++a;
|
||||
++b;
|
||||
}
|
||||
|
||||
return *(const unsigned char *)a - *(const unsigned char *)b;
|
||||
return *(const unsigned char *)a - *(const unsigned char *)b;
|
||||
}
|
||||
|
||||
char *strcpy(char *p, const char *s) {
|
||||
const char *temp1 = s;
|
||||
char *temp2 = p;
|
||||
while(*temp1 != '\0') {
|
||||
while (*temp1 != '\0') {
|
||||
*temp2 = *temp1;
|
||||
temp1++;
|
||||
temp2++;
|
||||
@@ -52,7 +52,7 @@ char *strcpy(char *p, const char *s) {
|
||||
size_t strlen(const char *a) {
|
||||
size_t s = 0;
|
||||
|
||||
while(a[s] != '\0')
|
||||
while (a[s] != '\0')
|
||||
++s;
|
||||
|
||||
return s;
|
||||
@@ -61,8 +61,19 @@ size_t strlen(const char *a) {
|
||||
int strncmp(const char *a, const char *b, size_t c) {
|
||||
int diff = 0;
|
||||
|
||||
while(c-- && diff == 0)
|
||||
while (c-- && diff == 0)
|
||||
diff += *a++ - *b++;
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
int memcmp(const void *_a, const void *_b, size_t s) {
|
||||
const uint8_t *a = _a;
|
||||
const uint8_t *b = _b;
|
||||
int diff = 0;
|
||||
|
||||
while (s-- && diff == 0)
|
||||
diff += *a++ - *b++;
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user