Rev 1157 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1157 | 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 | |||
1163 | andrew_pro | 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"); |
||
1157 | andrew_pro | 31 | |
1163 | andrew_pro | 32 | } |
1157 | andrew_pro | 33 | return(value); |
34 | } |
||
35 | |||
36 | static size_t strlen(const char *s) |
||
37 | { |
||
38 | size_t i; |
||
39 | |||
40 | i=0; |
||
41 | while(*s!='\0') |
||
42 | { |
||
43 | i++; |
||
44 | s++; |
||
45 | } |
||
46 | return(i); |
||
47 | } |
||
48 | |||
49 | static char* strchr(const char *string, int c) |
||
50 | { |
||
51 | while(*string!='\0') |
||
52 | { |
||
53 | if (*string==(char)c) return((char*)string); |
||
54 | string++; |
||
55 | } |
||
56 | return(NULL); |
||
57 | } |
||
58 | |||
59 | static char* strrchr(const char *string, int c) |
||
60 | { |
||
61 | char *s; |
||
62 | int i,j; |
||
63 | |||
64 | s=(char*)string; |
||
65 | while(*s!='\0') {s++;} |
||
66 | |||
67 | j=(int)(s-string); |
||
68 | s--; |
||
69 | |||
70 | for(i=0;i |
||
71 | { |
||
72 | if (*s==(char)c) return(s); |
||
73 | s--; |
||
74 | } |
||
75 | |||
76 | return(NULL); |
||
77 | } |
||
78 | |||
79 | static char* strstr(const char *s1,const char *s2) |
||
80 | { |
||
81 | char *s; |
||
82 | int i,j,len1,len2; |
||
83 | |||
84 | len2=strlen(s2); |
||
85 | if (len2==0) return((char*)s1); |
||
86 | |||
87 | len1=strlen(s1); |
||
88 | for(i=0;i |
||
89 | { |
||
90 | if (s1[i]==s2[0]) |
||
91 | { |
||
92 | for(j=0;j |
||
93 | { |
||
94 | if (s1[i+j]!=s2[j]) break; |
||
95 | } |
||
96 | if (j==len2) return((char*)(s1+i)); |
||
97 | } |
||
98 | } |
||
99 | return(NULL); |
||
100 | } |
||
101 | |||
102 | static int strcmp(const char* string1, const char* string2) |
||
103 | { |
||
104 | while (1) |
||
105 | { |
||
106 | if (*string1<*string2) |
||
107 | return -1; |
||
108 | if (*string1>*string2) |
||
109 | return 1; |
||
110 | if (*string1=='\0') |
||
111 | return 0; |
||
112 | string1++; |
||
113 | string2++; |
||
114 | } |
||
115 | } |
||
116 | |||
117 | static int strncmp(const char* string1, const char* string2, int count) |
||
118 | { |
||
119 | while(count>0 && *string1==*string2) |
||
120 | { |
||
121 | if (*string1) return 0; |
||
122 | ++string1; |
||
123 | ++string2; |
||
124 | --count; |
||
125 | } |
||
126 | if(count) return (*string1 - *string2); |
||
127 | return 0; |
||
128 | } |
||
129 | |||
130 | static int sprintf(char *dest,const char *format,...) |
||
131 | { |
||
132 | va_list arg; |
||
133 | va_start (arg, format); |
||
134 | return format_print(dest,4096, format, arg); |
||
135 | } |
||
136 | |||
137 | static int snprintf(char *dest, size_t size,const char *format,...) |
||
138 | { |
||
139 | va_list arg; |
||
140 | va_start (arg, format); |
||
141 | return format_print(dest,size, format, arg); |
||
142 | } |
||
143 | |||
144 | static int vsnprintf(char *dest, size_t size,const char *format,va_list ap) |
||
145 | { |
||
146 | return format_print(dest,size, format, ap); |
||
147 | }*string2) |
||
148 | |||
149 |