OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [ldso/] [include/] [ld_string.h] - Blame information for rev 1776

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#ifndef _LINUX_STRING_H_
2
#define _LINUX_STRING_H_
3
 
4
extern void *_dl_malloc(int size);
5
extern char *_dl_getenv(const char *symbol, char **envp);
6
extern void _dl_unsetenv(const char *symbol, char **envp);
7
extern char *_dl_strdup(const char *string);
8
extern void _dl_dprintf(int, const char *, ...);
9
 
10
 
11
static size_t _dl_strlen(const char * str);
12
static char *_dl_strcat(char *dst, const char *src);
13
static char * _dl_strcpy(char * dst,const char *src);
14
static int _dl_strcmp(const char * s1,const char * s2);
15
static int _dl_strncmp(const char * s1,const char * s2,size_t len);
16
static char * _dl_strchr(const char * str,int c);
17
static char *_dl_strrchr(const char *str, int c);
18
static char *_dl_strstr(const char *s1, const char *s2);
19
static void * _dl_memcpy(void * dst, const void * src, size_t len);
20
static int _dl_memcmp(const void * s1,const void * s2,size_t len);
21
static void *_dl_memset(void * str,int c,size_t len);
22
static char *_dl_get_last_path_component(char *path);
23
static char *_dl_simple_ltoa(char * local, unsigned long i);
24
static char *_dl_simple_ltoahex(char * local, unsigned long i);
25
 
26
#ifndef NULL
27
#define NULL ((void *) 0)
28
#endif
29
 
30
static inline size_t _dl_strlen(const char * str)
31
{
32
        register char *ptr = (char *) str;
33
 
34
        while (*ptr)
35
                ptr++;
36
        return (ptr - str);
37
}
38
 
39
static inline char *_dl_strcat(char *dst, const char *src)
40
{
41
        register char *ptr = dst;
42
 
43
        while (*ptr)
44
                ptr++;
45
 
46
        while (*src)
47
                *ptr++ = *src++;
48
        *ptr = '\0';
49
 
50
        return dst;
51
}
52
 
53
static inline char * _dl_strcpy(char * dst,const char *src)
54
{
55
        register char *ptr = dst;
56
 
57
        while (*src)
58
                *dst++ = *src++;
59
        *dst = '\0';
60
 
61
        return ptr;
62
}
63
 
64
static inline int _dl_strcmp(const char * s1,const char * s2)
65
{
66
        register unsigned char c1, c2;
67
 
68
        do {
69
                c1 = (unsigned char) *s1++;
70
                c2 = (unsigned char) *s2++;
71
                if (c1 == '\0')
72
                        return c1 - c2;
73
        }
74
        while (c1 == c2);
75
 
76
        return c1 - c2;
77
}
78
 
79
static inline int _dl_strncmp(const char * s1,const char * s2,size_t len)
80
{
81
        register unsigned char c1 = '\0';
82
        register unsigned char c2 = '\0';
83
 
84
        while (len > 0) {
85
                c1 = (unsigned char) *s1++;
86
                c2 = (unsigned char) *s2++;
87
                if (c1 == '\0' || c1 != c2)
88
                        return c1 - c2;
89
                len--;
90
        }
91
 
92
        return c1 - c2;
93
}
94
 
95
static inline char * _dl_strchr(const char * str,int c)
96
{
97
        register char ch;
98
 
99
        do {
100
                if ((ch = *str) == c)
101
                        return (char *) str;
102
                str++;
103
        }
104
        while (ch);
105
 
106
        return 0;
107
}
108
 
109
static inline char *_dl_strrchr(const char *str, int c)
110
{
111
    register char *prev = 0;
112
    register char *ptr = (char *) str;
113
 
114
    while (*ptr != '\0') {
115
        if (*ptr == c)
116
            prev = ptr;
117
        ptr++;
118
    }
119
    if (c == '\0')
120
        return(ptr);
121
    return(prev);
122
}
123
 
124
 
125
static inline char *_dl_strstr(const char *s1, const char *s2)
126
{
127
    register const char *s = s1;
128
    register const char *p = s2;
129
 
130
    do {
131
        if (!*p) {
132
            return (char *) s1;;
133
        }
134
        if (*p == *s) {
135
            ++p;
136
            ++s;
137
        } else {
138
            p = s2;
139
            if (!*s) {
140
              return NULL;
141
            }
142
            s = ++s1;
143
        }
144
    } while (1);
145
}
146
 
147
static inline void * _dl_memcpy(void * dst, const void * src, size_t len)
148
{
149
        register char *a = dst;
150
        register const char *b = src;
151
 
152
        while (len--)
153
                *a++ = *b++;
154
 
155
        return dst;
156
}
157
 
158
 
159
static inline int _dl_memcmp(const void * s1,const void * s2,size_t len)
160
{
161
        unsigned char *c1 = (unsigned char *)s1;
162
        unsigned char *c2 = (unsigned char *)s2;
163
 
164
        while (len--) {
165
                if (*c1 != *c2)
166
                        return *c1 - *c2;
167
                c1++;
168
                c2++;
169
        }
170
        return 0;
171
}
172
 
173
static inline void * _dl_memset(void * str,int c,size_t len)
174
{
175
        register char *a = str;
176
 
177
        while (len--)
178
                *a++ = c;
179
 
180
        return str;
181
}
182
 
183
static inline char *_dl_get_last_path_component(char *path)
184
{
185
        char *s;
186
        register char *ptr = path;
187
        register char *prev = 0;
188
 
189
        while (*ptr)
190
                ptr++;
191
        s = ptr - 1;
192
 
193
        /* strip trailing slashes */
194
        while (s != path && *s == '/') {
195
                *s-- = '\0';
196
        }
197
 
198
        /* find last component */
199
        ptr = path;
200
        while (*ptr != '\0') {
201
            if (*ptr == '/')
202
                prev = ptr;
203
            ptr++;
204
        }
205
        s = prev;
206
 
207
        if (s == NULL || s[1] == '\0')
208
                return path;
209
        else
210
                return s+1;
211
}
212
 
213
/* Early on, we can't call printf, so use this to print out
214
 * numbers using the SEND_STDERR() macro */
215
static inline char *_dl_simple_ltoa(char * local, unsigned long i)
216
{
217
        /* 21 digits plus null terminator, good for 64-bit or smaller ints */
218
        char *p = &local[22];
219
        *p-- = '\0';
220
        do {
221
                *p-- = '0' + i % 10;
222
                i /= 10;
223
        } while (i > 0);
224
        return p + 1;
225
}
226
 
227
static inline char *_dl_simple_ltoahex(char * local, unsigned long i)
228
{
229
        /* 21 digits plus null terminator, good for 64-bit or smaller ints */
230
        char *p = &local[22];
231
        *p-- = '\0';
232
        do {
233
                char temp = i % 0x10;
234
                if (temp <= 0x09)
235
                    *p-- = '0' + temp;
236
                else
237
                    *p-- = 'a' - 0x0a + temp;
238
                i /= 0x10;
239
        } while (i > 0);
240
        *p-- = 'x';
241
        *p-- = '0';
242
        return p + 1;
243
}
244
 
245
 
246
#if defined(mc68000) || defined(__arm__) || defined(__mips__) || defined(__sh__) ||  defined(__powerpc__)
247
/* On some arches constant strings are referenced through the GOT. */
248
/* XXX Requires load_addr to be defined. */
249
#define SEND_STDERR(X)                          \
250
  { const char *__s = (X);                      \
251
    if (__s < (const char *) load_addr) __s += load_addr;       \
252
    _dl_write (2, __s, _dl_strlen (__s));       \
253
  }
254
#else
255
#define SEND_STDERR(X) _dl_write(2, X, _dl_strlen(X));
256
#endif
257
 
258
#define SEND_ADDRESS_STDERR(X, add_a_newline) { \
259
    char tmp[22], *tmp1; \
260
    _dl_memset(tmp, 0, sizeof(tmp)); \
261
    tmp1=_dl_simple_ltoahex( tmp, (unsigned long)(X)); \
262
    _dl_write(2, tmp1, _dl_strlen(tmp1)); \
263
    if (add_a_newline) { \
264
        tmp[0]='\n'; \
265
        _dl_write(2, tmp, 1); \
266
    } \
267
};
268
 
269
#define SEND_NUMBER_STDERR(X, add_a_newline) { \
270
    char tmp[22], *tmp1; \
271
    _dl_memset(tmp, 0, sizeof(tmp)); \
272
    tmp1=_dl_simple_ltoa( tmp, (unsigned long)(X)); \
273
    _dl_write(2, tmp1, _dl_strlen(tmp1)); \
274
    if (add_a_newline) { \
275
        tmp[0]='\n'; \
276
        _dl_write(2, tmp, 1); \
277
    } \
278
};
279
 
280
 
281
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.