root / Whitix / branches / hybrid / lib / string.c

Revision 499, 2.7 kB (checked in by mwhitworth, 4 months ago)

Add symbol exports.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#include <module.h>
20#include <string.h>
21
22int strncpy(char* dest,char* src,int len)
23{
24        while (*src != '\0' && len--)
25                *dest++=*src++;
26
27        while (len--)
28                *dest++='\0';
29
30        return 0;
31}
32
33SYMBOL_EXPORT(strncpy);
34
35int strcpy(char* dest,char* src)
36{
37        while ((*dest++=*src++));
38        return 0;
39}
40
41SYMBOL_EXPORT(strcpy);
42
43int strncmp(const char* s1,const char* s2,int num)
44{
45        unsigned char res=0;
46
47    while (num)
48        {
49                if ((res=*s1-*s2++) || !*s1++)
50                        break;
51
52                --num;
53        }
54
55        return res;
56}
57
58SYMBOL_EXPORT(strncmp);
59
60int strnicmp(const char* s1,const char* s2,int num)
61{
62        unsigned char res=0;
63
64        while (num)
65        {
66                char a=toupper(*s1),b=toupper(*s2);
67                if ((res=a-b))
68                        break;
69
70                s1++; s2++;
71                --num;
72        }
73
74        return res;
75}
76
77SYMBOL_EXPORT(strnicmp);
78
79int strlen(char* str)
80{
81        int ret=0;
82
83        while (*str++)
84                ++ret;
85
86        return ret;
87}
88
89SYMBOL_EXPORT(strlen);
90
91char* strcat(char *str1,const char *str2)
92{
93        char* target=str1;
94        while (*target)
95                target++;
96       
97        const char* src=str2;
98        while((*target++=*src++) != '\0');
99       
100        return str1;
101}
102
103SYMBOL_EXPORT(strcat);
104
105char* strchr(char* string,int c)
106{
107        for (; *string; string++)
108                if (*string == (char)c)
109                        return (char*)string;
110
111        return 0;
112}
113
114SYMBOL_EXPORT(strchr);
115
116char* strrchr(char* string,int c)
117{
118        for (string+=strlen(string); *string; string--)
119                if (*string == (char)c)
120                        return (char*)string;
121
122        return 0;
123}
124
125SYMBOL_EXPORT(strrchr);
126
127void* memset(void* pointer,int size,char value)
128{
129        char* iterate=(char*)pointer;
130
131        while (size--)
132                *iterate++=value;
133
134        return pointer;
135}
136
137SYMBOL_EXPORT(memset);
138
139void* memsetw(void* pointer,int size,WORD value)
140{
141        WORD* iterate=(WORD*)pointer;
142
143        while (size--)
144                *iterate++=value;
145
146        return pointer;
147}
148
149SYMBOL_EXPORT(memsetw);
150
151int memcmp(const void *s1, const void *s2, int n)
152{
153        unsigned char* c1, *c2;
154        int res=0;
155
156        for (c1=(unsigned char*)s1, c2=(unsigned char*)s2; n; ++c1, ++c2, n--)
157        {
158                if ((res=*c1-*c2))
159                        break;
160        }
161
162        return res;
163}
164
165SYMBOL_EXPORT(memcmp);
166
167int toupper(char ch)
168{
169        if (ch>=97 && ch<=122)
170                ch-=0x20;
171   
172        return ch; 
173}
Note: See TracBrowser for help on using the browser.