1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
--- uClibc-0.9.28/ldso/include/dl-string.h.orig 2006-08-14 17:20:02.000000000 +0200
+++ uClibc-0.9.28/ldso/include/dl-string.h 2006-08-14 17:19:38.000000000 +0200
@@ -1,9 +1,24 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
+ *
+ * GNU Lesser General Public License version 2.1 or later.
+ */
+
#ifndef _LINUX_STRING_H_
#define _LINUX_STRING_H_
-#include <dl-sysdep.h> // for do_rem
+#include <dl-sysdep.h> /* for do_rem */
#include <features.h>
+/* provide some sane defaults */
+#ifndef do_rem
+# define do_rem(result, n, base) ((result) = (n) % (base))
+#endif
+#ifndef do_div_10
+# define do_div_10(result, remain) ((result) /= 10)
+#endif
+
static size_t _dl_strlen(const char * str);
static char *_dl_strcat(char *dst, const char *src);
static char * _dl_strcpy(char * dst,const char *src);
@@ -26,8 +41,8 @@
static __always_inline size_t _dl_strlen(const char * str)
{
register const char *ptr = (char *) str-1;
-
- while (*++ptr);
+ while (*++ptr)
+ ;/* empty */
return (ptr - str);
}
@@ -49,7 +64,8 @@
register char *ptr = dst;
dst--;src--;
- while ((*++dst = *++src) != 0);
+ while ((*++dst = *++src) != 0)
+ ;/* empty */
return ptr;
}
@@ -63,8 +79,7 @@
c2 = (unsigned char) *++s2;
if (c1 == '\0')
return c1 - c2;
- }
- while (c1 == c2);
+ } while (c1 == c2);
return c1 - c2;
}
@@ -98,43 +113,41 @@
return 0;
}
-static inline char * _dl_strrchr(const char *str, int c)
+static __always_inline char * _dl_strrchr(const char *str, int c)
{
- register char *prev = 0;
- register char *ptr = (char *) str-1;
+ register char *prev = 0;
+ register char *ptr = (char *) str-1;
- while (*++ptr != '\0') {
- if (*ptr == c)
- prev = ptr;
- }
- if (c == '\0')
- return(ptr);
- return(prev);
+ while (*++ptr != '\0') {
+ if (*ptr == c)
+ prev = ptr;
+ }
+ if (c == '\0')
+ return(ptr);
+ return(prev);
}
-static inline char * _dl_strstr(const char *s1, const char *s2)
+static __always_inline char * _dl_strstr(const char *s1, const char *s2)
{
- register const char *s = s1;
- register const char *p = s2;
+ register const char *s = s1;
+ register const char *p = s2;
- do {
- if (!*p) {
- return (char *) s1;;
- }
- if (*p == *s) {
- ++p;
- ++s;
- } else {
- p = s2;
- if (!*s) {
- return NULL;
- }
- s = ++s1;
- }
- } while (1);
+ do {
+ if (!*p)
+ return (char *) s1;;
+ if (*p == *s) {
+ ++p;
+ ++s;
+ } else {
+ p = s2;
+ if (!*s)
+ return NULL;
+ s = ++s1;
+ }
+ } while (1);
}
-static inline void * _dl_memcpy(void * dst, const void * src, size_t len)
+static __always_inline void * _dl_memcpy(void * dst, const void * src, size_t len)
{
register char *a = dst-1;
register const char *b = src-1;
@@ -163,27 +176,28 @@
/* Will generate smaller and faster code due to loop unrolling.*/
static __always_inline void * _dl_memset(void *to, int c, size_t n)
{
- unsigned long chunks;
- unsigned long *tmp_to;
+ unsigned long chunks;
+ unsigned long *tmp_to;
unsigned char *tmp_char;
- chunks = n / 4;
- tmp_to = to + n;
- c = c << 8 | c;
- c = c << 16 | c;
- if (!chunks)
- goto lessthan4;
- do {
- *--tmp_to = c;
- } while (--chunks);
- lessthan4:
- n = n % 4;
- if (!n ) return to;
- tmp_char = (unsigned char *)tmp_to;
- do {
- *--tmp_char = c;
- } while (--n);
- return to;
+ chunks = n / 4;
+ tmp_to = to + n;
+ c = c << 8 | c;
+ c = c << 16 | c;
+ if (!chunks)
+ goto lessthan4;
+ do {
+ *--tmp_to = c;
+ } while (--chunks);
+lessthan4:
+ n = n % 4;
+ if (!n)
+ return to;
+ tmp_char = (unsigned char *)tmp_to;
+ do {
+ *--tmp_char = c;
+ } while (--n);
+ return to;
}
#else
static __always_inline void * _dl_memset(void * str,int c,size_t len)
@@ -225,10 +239,10 @@
char *p = &local[22];
*--p = '\0';
do {
- char temp;
- do_rem(temp, i, 10);
- *--p = '0' + temp;
- i /= 10;
+ char temp;
+ do_rem(temp, i, 10);
+ *--p = '0' + temp;
+ do_div_10(i, temp);
} while (i > 0);
return p;
}
@@ -242,9 +256,9 @@
do {
char temp = i & 0xf;
if (temp <= 0x09)
- *--p = '0' + temp;
+ *--p = '0' + temp;
else
- *--p = 'a' - 0x0a + temp;
+ *--p = 'a' - 0x0a + temp;
i >>= 4;
} while (i > 0);
*--p = 'x';
@@ -270,8 +284,8 @@
/* On some arches constant strings are referenced through the GOT.
* This requires that load_addr must already be defined... */
-#if defined(mc68000) || defined(__arm__) || defined(__thumb__) || defined(__mips__) \
- || defined(__sh__) || defined(__powerpc__)
+#if defined(mc68000) || defined(__arm__) || defined(__thumb__) || \
+ defined(__mips__) || defined(__sh__) || defined(__powerpc__)
# define CONSTANT_STRING_GOT_FIXUP(X) \
if ((X) < (const char *) load_addr) (X) += load_addr
# define NO_EARLY_SEND_STDERR
@@ -318,7 +332,7 @@
do { \
do_rem(v, (X), 10); \
*--tmp2 = '0' + v; \
- (X) /= 10; \
+ do_div_10((X), v); \
} while ((X) > 0); \
_dl_write(2, tmp2, tmp1 - tmp2 + sizeof(tmp) - 1); \
}
|