Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1176 | andrew_pro | 1 | /* |
2 | some libC function working with memory |
||
3 | */ |
||
4 | |||
5 | static void *memmove(void *dst,const void *src,size_t length) |
||
6 | { |
||
7 | void *value; |
||
8 | |||
9 | if (length & 3) |
||
10 | {//length not aligned in 4 bytes use reb movsb |
||
11 | __asm__ __volatile__( |
||
12 | "movl %%edi,%%eax\n\t" |
||
13 | "cld\n\t" |
||
14 | "rep\n\t" |
||
15 | "movsb" |
||
16 | :"=D"(value) |
||
17 | :"c"(length),"S"(src),"D"(dst) |
||
18 | :"eax"); |
||
19 | } |
||
20 | else |
||
21 | {//length aligned in 4 bytes use rep movsd |
||
22 | length=length >> 2;//length=length/4 |
||
23 | __asm__ __volatile__( |
||
24 | "movl %%edi,%%eax\n\t" |
||
25 | "cld\n\t" |
||
26 | "rep\n\t" |
||
27 | "movsd" |
||
28 | :"=D"(value) |
||
29 | :"c"(length),"S"(src),"D"(dst) |
||
30 | :"eax"); |
||
31 | |||
32 | } |
||
33 | return(value); |
||
34 | } |
||
35 | |||
36 | static void *memset(const void *dst, int c, size_t length) |
||
37 | { |
||
38 | unsigned char cfill; |
||
39 | |||
40 | cfill=c; |
||
41 | while(length) |
||
42 | { |
||
43 | *(char*)dst=c; |
||
44 | dst=(char*)dst+1; |
||
45 | length--; |
||
46 | } |
||
47 | return((void*)1); |
||
48 | } |
||
49 | |||
50 | static size_t strlen(const char *s) |
||
51 | { |
||
52 | size_t i; |
||
53 | |||
54 | i=0; |
||
55 | while(*s!='\0') |
||
56 | { |
||
57 | i++; |
||
58 | s++; |
||
59 | } |
||
60 | return(i); |
||
61 | } |
||
62 | |||
63 | static char* strchr(const char *string, int c) |
||
64 | { |
||
65 | while(*string!='\0') |
||
66 | { |
||
67 | if (*string==(char)c) return((char*)string); |
||
68 | string++; |
||
69 | } |
||
70 | return(NULL); |
||
71 | } |
||
72 | |||
73 | static char* strrchr(const char *string, int c) |
||
74 | { |
||
75 | char *s; |
||
76 | int i,j; |
||
77 | |||
78 | s=(char*)string; |
||
79 | while(*s!='\0') {s++;} |
||
80 | |||
81 | j=(int)(s-string); |
||
82 | s--; |
||
83 | |||
84 | for(i=0;i |
||
85 | { |
||
86 | if (*s==(char)c) return(s); |
||
87 | s--; |
||
88 | } |
||
89 | |||
90 | return(NULL); |
||
91 | } |
||
92 | |||
93 | static char* strstr(const char *s1,const char *s2) |
||
94 | { |
||
95 | char *s; |
||
96 | int i,j,len1,len2; |
||
97 | |||
98 | len2=strlen(s2); |
||
99 | if (len2==0) return((char*)s1); |
||
100 | |||
101 | len1=strlen(s1); |
||
102 | for(i=0;i |
||
103 | { |
||
104 | if (s1[i]==s2[0]) |
||
105 | { |
||
106 | for(j=0;j |
||
107 | { |
||
108 | if (s1[i+j]!=s2[j]) break; |
||
109 | } |
||
110 | if (j==len2) return((char*)(s1+i)); |
||
111 | } |
||
112 | } |
||
113 | return(NULL); |
||
114 | } |
||
115 | |||
116 | static int strcmp(const char* string1, const char* string2) |
||
117 | { |
||
118 | while (1) |
||
119 | { |
||
120 | if (*string1<*string2) |
||
121 | return -1; |
||
122 | if (*string1>*string2) |
||
123 | return 1; |
||
124 | if (*string1=='\0') |
||
125 | return 0; |
||
126 | string1++; |
||
127 | string2++; |
||
128 | } |
||
129 | } |
||
130 | |||
131 | static int strncmp(const char* string1, const char* string2,size_t count) |
||
132 | { |
||
133 | while(count>0 && *string1==*string2) |
||
134 | { |
||
135 | if (*string1) return 0; |
||
136 | ++string1; |
||
137 | ++string2; |
||
138 | --count; |
||
139 | } |
||
140 | if(count) return (*string1 - *string2); |
||
141 | return 0; |
||
142 | } |
||
143 | |||
144 | static int sprintf(char *dest,const char *format,...) |
||
145 | { |
||
146 | va_list arg; |
||
147 | va_start (arg, format); |
||
148 | return format_print(dest,strlen(dest), format, arg); |
||
149 | } |
||
150 | |||
151 | static int snprintf(char *dest, size_t size,const char *format,...) |
||
152 | { |
||
153 | va_list arg; |
||
154 | va_start (arg, format); |
||
155 | return format_print(dest,size, format, arg); |
||
156 | } |
||
157 | |||
158 | static int vsnprintf(char *dest, size_t size,const char *format,va_list ap) |
||
159 | { |
||
160 | return format_print(dest,size, format, ap); |
||
161 | }*string2) |
||
162 | |||
163 |