|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||
|
001 /* Copyright (C) 2003 The KOS Team 001 /* Copyright (C) 2003 The KOS Team 002 Copyright (C) 1999 Free Software Foundatio 002 Copyright (C) 1999 Free Software Foundation 003 003 004 This program is free software; you can redi 004 This program is free software; you can redistribute it and/or 005 modify it under the terms of the GNU Genera 005 modify it under the terms of the GNU General Public License 006 as published by the Free Software Foundatio 006 as published by the Free Software Foundation; either version 2 007 of the License, or (at your option) any lat 007 of the License, or (at your option) any later version. 008 008 009 This program is distributed in the hope tha 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU General Public License for more details 012 GNU General Public License for more details. 013 013 014 You should have received a copy of the GNU 014 You should have received a copy of the GNU General Public License 015 along with this program; if not, write to t 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place - Suite 3 016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 017 USA. 017 USA. 018 */ 018 */ 019 #ifndef _SOS_KLIBC_H_ 019 #ifndef _SOS_KLIBC_H_ 020 #define _SOS_KLIBC_H_ 020 #define _SOS_KLIBC_H_ 021 021 022 /** 022 /** 023 * @file klibc.h 023 * @file klibc.h 024 * 024 * 025 * Basic libc-style support for common useful 025 * Basic libc-style support for common useful functions (string.h, 026 * stdarg.h), some with slight non-standard be 026 * stdarg.h), some with slight non-standard behavior (see comments). 027 * 027 * 028 * Most of the prototypes of these functions a 028 * Most of the prototypes of these functions are borrowed from 029 * FreeBSD, but their implementation (in klibc 029 * FreeBSD, but their implementation (in klibc.c) come either from Kos 030 * (GPL v2) or from David Decotigny (SOS). 030 * (GPL v2) or from David Decotigny (SOS). 031 */ 031 */ 032 032 033 #include <sos/types.h> 033 #include <sos/types.h> 034 034 035 /* string.h functions */ 035 /* string.h functions */ 036 036 037 void *memcpy(void *dst, const void *src, regis 037 void *memcpy(void *dst, const void *src, register unsigned int size ) ; 038 void *memset(void *dst, register int c, regist 038 void *memset(void *dst, register int c, register unsigned int length ) ; 039 int memcmp(const void *s1, const void *s2, sos 039 int memcmp(const void *s1, const void *s2, sos_size_t n); 040 040 041 unsigned int strlen( register const char *str) 041 unsigned int strlen( register const char *str) ; 042 unsigned int strnlen(const char * s, sos_size_ 042 unsigned int strnlen(const char * s, sos_size_t maxlen); 043 043 044 /** 044 /** 045 * @note Same as strncpy(), with a slightly di 045 * @note Same as strncpy(), with a slightly different semantic. 046 * Actually, strncpy(3C) says " The result wil 046 * Actually, strncpy(3C) says " The result will not be null-terminated 047 * if the length of 'from' is n or more.". He 047 * if the length of 'from' is n or more.". Here, 'dst' is ALWAYS 048 * null-terminated. And its total len will ALW 048 * null-terminated. And its total len will ALWAYS be <= len, with 049 * null-terminating-char included. 049 * null-terminating-char included. 050 */ 050 */ 051 char *strzcpy( register char *dst, register co 051 char *strzcpy( register char *dst, register const char *src, 052 register int len ) ; 052 register int len ) ; 053 053 054 /** 054 /** 055 * @note Same as strncat(), with the same sema 055 * @note Same as strncat(), with the same semantic : 'dst' is ALWAYS 056 * null-terminated. And its total len will ALW 056 * null-terminated. And its total len will ALWAYS be <= len, with 057 * null-terminating-char included. 057 * null-terminating-char included. 058 */ 058 */ 059 char *strzcat (char *dest, const char *src, 059 char *strzcat (char *dest, const char *src, 060 const sos_size_t len); 060 const sos_size_t len); 061 061 062 int strcmp(register const char *s1, register c 062 int strcmp(register const char *s1, register const char *s2 ); 063 int strncmp(register const char *s1, register 063 int strncmp(register const char *s1, register const char *s2, 064 register int len ); 064 register int len ); 065 065 066 /* Basic stdarg.h macros. Taken from gcc suppo 066 /* Basic stdarg.h macros. Taken from gcc support files */ 067 #define __GNUC_VA_LIST 067 #define __GNUC_VA_LIST 068 typedef void *__gnuc_va_list; 068 typedef void *__gnuc_va_list; 069 typedef __gnuc_va_list va_list; 069 typedef __gnuc_va_list va_list; 070 #define __va_rounded_size(TYPE) \ 070 #define __va_rounded_size(TYPE) \ 071 (((sizeof (TYPE) + sizeof (int) - 1) / sizeo 071 (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) 072 #define va_start(AP, LASTARG) \ 072 #define va_start(AP, LASTARG) \ 073 (AP = ((__gnuc_va_list) __builtin_next_arg ( 073 (AP = ((__gnuc_va_list) __builtin_next_arg (LASTARG))) 074 #define va_end(AP) \ 074 #define va_end(AP) \ 075 ((void)0) 075 ((void)0) 076 #define va_arg(AP, TYPE) \ 076 #define va_arg(AP, TYPE) \ 077 (AP = (__gnuc_va_list) ((char *) (AP) + __va 077 (AP = (__gnuc_va_list) ((char *) (AP) + __va_rounded_size (TYPE)), \ 078 *((TYPE *) (void *) ((char *) (AP) - __va_r 078 *((TYPE *) (void *) ((char *) (AP) - __va_rounded_size (TYPE)))) 079 #define __va_copy(dest, src) \ 079 #define __va_copy(dest, src) \ 080 (dest) = (src) 080 (dest) = (src) 081 081 082 /* stdarg.h functions. There might be a non-st 082 /* stdarg.h functions. There might be a non-standard behavior: there 083 will always be a trailing '\0' in the resul 083 will always be a trailing '\0' in the resulting string */ 084 int vsnprintf(char *, sos_size_t, const char * 084 int vsnprintf(char *, sos_size_t, const char *, va_list); 085 int snprintf(char *, sos_size_t, const char *, 085 int snprintf(char *, sos_size_t, const char *, /*args*/ ...) 086 __attribute__ ((format (printf, 3, 4))); 086 __attribute__ ((format (printf, 3, 4))); 087 087 088 088 089 /* 089 /* 090 * Pseudo-random generation functions. Useful 090 * Pseudo-random generation functions. Useful to do some coverage 091 * tests. 091 * tests. 092 */ 092 */ 093 093 094 /* Amplitude of the random number generation * 094 /* Amplitude of the random number generation */ 095 #define RAND_MAX 4294967291U 095 #define RAND_MAX 4294967291U 096 096 097 /* Pseudo-random number generation (MT unsafe) 097 /* Pseudo-random number generation (MT unsafe) */ 098 unsigned long int random (void); 098 unsigned long int random (void); 099 099 100 /* Set random seed (MT unsafe) */ 100 /* Set random seed (MT unsafe) */ 101 void srandom (unsigned long int seed); 101 void srandom (unsigned long int seed); 102 102 103 #endif /* _SOS_KLIBC_H_ */ 103 #endif /* _SOS_KLIBC_H_ */
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |