summary |
shortlog |
changelog |
graph |
tags |
branches |
files |
changeset |
file |
revisions |
annotate |
diff |
raw
loader/common/lib.c
| author | Rink Springer <rink@rink.nu> |
| Sat Sep 18 21:18:19 2010 +0200 (2010-09-18 ago) | |
| changeset 547 | 500fdeba0928 |
| parent 446 | b45f21785652 |
| child 1133 | dc729b3e4699 |
| permissions | -rw-r--r-- |
Loader: Migrate the loader to the new include structure.
While here, get rid of the ugly <sys/lib.h> and <std*.h> includes to get memcpy/printf/etc and introduce loader/lib.h; this makes it clearer what the seperation between the loader and the kernel is.
While here, get rid of the ugly <sys/lib.h> and <std*.h> includes to get memcpy/printf/etc and introduce loader/lib.h; this makes it clearer what the seperation between the loader and the kernel is.
1 #include <ananas/types.h>
2 #include <loader/lib.h>
4 void*
5 memcpy(void* dest, const void* src, size_t len)
6 {
7 char* d = (char*)dest;
8 char* s = (char*)src;
9 while (len--) {
10 *d++ = *s++;
11 }
12 return dest;
13 }
15 void*
16 memset(void* b, int c, size_t len)
17 {
18 char* ptr = (char*)b;
19 while (len--) {
20 *ptr++ = c;
21 }
22 return b;
23 }
25 char*
26 strcpy(char* dst, const char* src)
27 {
28 char* s = dst;
30 while (*src) {
31 *dst++ = *src++;
32 }
33 *dst = '\0';
34 return s;
35 }
37 int
38 strcmp(const char* s1, const char* s2)
39 {
40 while (*s1 != '\0' && *s2 != '\0' && *s1 == *s2) {
41 s1++; s2++;
42 }
43 return *s1 - *s2;
44 }
46 int
47 strncmp(const char* s1, const char* s2, size_t n)
48 {
49 while (n > 0 && *s1 != '\0' && *s2 != '\0' && *s1 == *s2) {
50 n--; s1++; s2++;
51 }
52 return (n == 0) ? n : *s1 - *s2;
53 }
55 char*
56 strchr(const char* s, int c)
57 {
58 while (1) {
59 if (*s == c)
60 return (char*)s;
61 if (*s == '\0')
62 break;
63 s++;
64 }
65 return NULL;
66 }
68 size_t
69 strlen(const char* s)
70 {
71 size_t len = 0;
73 for (; *s != '\0'; s++, len++);
74 return len;
75 }
77 int
78 memcmp(const void* s1, const void* s2, size_t len)
79 {
80 const char* c1 = s1;
81 const char* c2 = s2;
83 while (len > 0 && *c1 == *c2) {
84 len--; c1++; c2++;
85 }
86 return len > 0 ? *c1 - *c2 : 0;
87 }