util.h revision 1.2
1/* $OpenBSD: util.h,v 1.2 2002/04/09 19:59:47 drahn Exp $ */ 2 3/* 4 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed under OpenBSD by 17 * Per Fogelstrom, Opsycon AB, Sweden. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 */ 34 35#ifndef __DL_UTIL_H__ 36#define __DL_UTIL_H__ 37int _dl_write __P((int, const char *, int)); 38void *_dl_malloc(const int size); 39void _dl_free(void *); 40char *_dl_strdup(const char *); 41void _dl_printf(const char *fmt, ...); 42 43/* 44 * The following functions are declared inline so they can 45 * be used before bootstrap linking has been finished. 46 */ 47static inline void 48_dl_wrstderr(const char *s) 49{ 50 while(*s) { 51 _dl_write(2, s, 1); 52 s++; 53 } 54} 55 56static inline void * 57_dl_memset(void *p, const char v, size_t c) 58{ 59 char *ip = p; 60 61 while(c--) 62 *ip++ = v; 63 return(p); 64} 65 66static inline int 67_dl_strlen(const char *p) 68{ 69 const char *s = p; 70 71 while(*s != '\0') 72 s++; 73 return(s - p); 74} 75 76static inline char * 77_dl_strcpy(char *d, const char *s) 78{ 79 char *rd = d; 80 81 while((*d++ = *s++) != '\0'); 82 83 return(rd); 84} 85 86static inline int 87_dl_strncmp(const char *d, const char *s, int c) 88{ 89 while(c-- && *d && *d == *s) { 90 d++; 91 s++; 92 }; 93 if(c < 0) { 94 return(0); 95 } 96 return(*d - *s); 97} 98 99static inline int 100_dl_strcmp(const char *d, const char *s) 101{ 102 while(*d && *d == *s) { 103 d++; 104 s++; 105 } 106 return(*d - *s); 107} 108 109static inline const char * 110_dl_strchr(const char *p, const int c) 111{ 112 while(*p) { 113 if(*p == c) { 114 return(p); 115 } 116 p++; 117 } 118 return(0); 119} 120 121#endif /*__DL_UTIL_H__*/ 122