util.h revision 1.1
1#ifndef __DL_UTIL_H__
2#define __DL_UTIL_H__
3int _dl_write __P((int, const char *, int));
4void *_dl_malloc(const int size);
5void _dl_free(void *);
6char *_dl_strdup(const char *);
7void _dl_printf(const char *fmt, ...);
8
9/*
10 *	The following functions are declared inline so they can
11 *	be used before bootstrap linking has been finished.
12 */
13static inline void
14_dl_wrstderr(const char *s)
15{
16	while(*s) {
17		_dl_write(2, s, 1);
18		s++;
19	}
20}
21
22static inline void *
23_dl_memset(void *p, const char v, size_t c)
24{
25	char *ip = p;
26
27	while(c--)
28		*ip++ = v;
29	return(p);
30}
31
32static inline int
33_dl_strlen(const char *p)
34{
35	const char *s = p;
36
37	while(*s != '\0')
38		s++;
39	return(s - p);
40}
41
42static inline char *
43_dl_strcpy(char *d, const char *s)
44{
45	char *rd = d;
46
47	while((*d++ = *s++) != '\0');
48
49	return(rd);
50}
51
52static inline int
53_dl_strncmp(const char *d, const char *s, int c)
54{
55	while(c-- && *d && *d == *s) {
56		d++;
57		s++;
58	};
59	if(c < 0) {
60		return(0);
61	}
62	return(*d - *s);
63}
64
65static inline int
66_dl_strcmp(const char *d, const char *s)
67{
68	while(*d && *d == *s) {
69		d++;
70		s++;
71	}
72	return(*d - *s);
73}
74
75static inline const char *
76_dl_strchr(const char *p, const int c)
77{
78	while(*p) {
79		if(*p == c) {
80			return(p);
81		}
82		p++;
83	}
84	return(0);
85}
86
87#endif /*__DL_UTIL_H__*/
88