bullshit commit, sync for travel (to zn00H!) :)
[my-code/arm.git] / betty / functions.c
1 /*
2  * * functions.c - severla functions usually served by libc
3  *
4  * author: hackbard@hackdaworld.org
5  *
6  */
7
8 #include "functions.h"
9
10 /*
11  * functions
12  */
13
14 #define modulo(d,x,y)   (d)=(x); \
15                         while((d)>=(y)) \
16                                 (d)-=(y);
17
18 int strlen(char *s) {
19
20         int n;
21
22         n=0;
23
24         while(s[n])
25                 n++;
26
27         return n;
28 }
29
30 int strncmp(char *a,char *b,int n) {
31
32         if(!n)
33                 return 0;
34
35         while(n--) {
36                 if(*a!=*b)
37                         return (*(u8 *)a-*(u8 *)b++);
38                 if(!*a++)
39                         break;
40         }
41
42         return 0;
43 }
44
45 int strncpy(char *d,char *s,int n) {
46
47         while(n) {
48                 n--;
49                 d[n]=s[n];
50         }
51         
52         return 0;
53 }
54
55 int memset(u8 *d,int v,int n) {
56
57         while(n)
58                 d[--n]=v;
59
60         return 0;
61 }
62
63 int memcpy(u8 *d,u8 *s,int n) {
64
65         while(n--)
66                 *d++=*s++;
67
68         return n;
69 }
70
71 int counttok(u8 *s,u8 delim) {
72
73         int n;
74
75         n=0;
76         while(*s++!=delim)
77                 n++;
78         
79         return n;
80 }
81