/uspace/trunk/libc/include/limits.h |
---|
0,0 → 1,66 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __LIBC__LIMITS_H__ |
#define __LIBC__LIMITS_H__ |
#include <stdint.h> |
#include <libarch/limits.h> |
/* char */ |
#define SCHAR_MIN MIN_INT8 |
#define SCHAR_MAX MAX_INT8 |
#define UCHAR_MIN MIN_UINT8 |
#define UCHAR_MAX MAX_UINT8 |
#ifdef __CHAR_UNSIGNED__ |
# define CHAR_MIN UCHAR_MIN |
# define CHAR_MAX UCHAR_MAX |
#else |
# define CHAR_MIN SCHAR_MIN |
# define CHAR_MAX SCHAR_MAX |
#endif |
/* short int */ |
#define SHRT_MIN MIN_INT16 |
#define SHRT_MAX MAX_INT16 |
#define USHRT_MIN MIN_UINT16 |
#define USHRT_MAX MAX_UINT16 |
#define INT_MIN MIN_INT32 |
#define INT_MAX MAX_INT32 |
#define UINT_MIN MIN_UINT32 |
#define UINT_MAX MAX_UINT32 |
#define LLONG_MIN MIN_INT64 |
#define LLONG_MAX MAX_INT64 |
#define ULLONG_MIN MIN_UINT64 |
#define ULLONG_MAX MAX_UINT64 |
#endif |
/uspace/trunk/libc/include/string.h |
---|
38,9 → 38,12 |
void * memcpy(void *dest, void *src, size_t n); |
size_t strlen(const char *str); |
int strcmp(const char *str1, const char *str2); |
char *strchr(const char *str, int c); |
char *strrchr(const char *str, int c); |
unsigned long strtol(const char *nptr, char **endptr, int base); |
long int strtol(const char *nptr, char **endptr, int base); |
unsigned long strtoul(const char *nptr, char **endptr, int base); |
#endif |
/uspace/trunk/libc/include/ctype.h |
---|
34,5 → 34,21 |
return ((c >= '0' )&&( c <= '9')); |
} |
static inline int isspace(int c) |
{ |
switch(c) { |
case ' ': |
case '\n': |
case '\t': |
case '\f': |
case '\r': |
case '\v': |
return 1; |
break; |
default: |
return 0; |
} |
} |
#endif |
/uspace/trunk/libc/generic/string.c |
---|
27,7 → 27,11 |
*/ |
#include <string.h> |
#include <unistd.h> |
#include <ctype.h> |
#include <limits.h> |
/* Dummy implementation of mem/ functions */ |
void * memset(void *s, int c, size_t n) |
47,6 → 51,10 |
return dest; |
} |
/** Count the number of characters in the string, not including terminating 0. |
* @param str string |
* @return number of characters in string. |
*/ |
size_t strlen(const char *str) |
{ |
size_t counter = 0; |
57,3 → 65,172 |
return counter; |
} |
/** Return pointer to the first occurence of character c in string |
* @param str scanned string |
* @param c searched character (taken as one byte) |
* @return pointer to the matched character or NULL if it is not found in given string. |
*/ |
char *strchr(const char *str, int c) |
{ |
while (*str != '\0') { |
if (*str == (char)c) |
return (char *)str; |
str++; |
} |
return NULL; |
} |
/** Return pointer to the last occurence of character c in string |
* @param str scanned string |
* @param c searched character (taken as one byte) |
* @return pointer to the matched character or NULL if it is not found in given string. |
*/ |
char *strrchr(const char *str, int c) |
{ |
char *retval = NULL; |
while (*str != '\0') { |
if (*str == (char)c) |
retval = (char *)str; |
str++; |
} |
return (char *)retval; |
} |
/** Convert string to a number. |
* Core of strtol and strtoul functions. |
* @param nptr pointer to string |
* @param endptr if not NULL, function stores here pointer to the first invalid character |
* @param base zero or number between 2 and 36 inclusive |
* @param sgn its set to 1 if minus found |
* @return result of conversion. |
*/ |
static unsigned long _strtoul(const char *nptr, char **endptr, int base, char *sgn) |
{ |
unsigned char c; |
unsigned long result = 0; |
unsigned long a, b; |
const char *str = nptr; |
const char *tmpptr; |
while (isspace(*str)) |
str++; |
if (*str == '-') { |
*sgn = 1; |
++str; |
} else if (*str == '+') |
++str; |
if (base) { |
if ((base == 1) || (base > 36)) { |
/* FIXME: set errno to EINVAL */ |
return 0; |
} |
if ((base == 16) && (*str == '0') && ((str[1] == 'x') || (str[1] == 'X'))) { |
str += 2; |
} |
} else { |
base = 10; |
if (*str == '0') { |
base = 8; |
if ((str[1] == 'X') || (str[1] == 'x')) { |
base = 16; |
str += 2; |
} |
} |
} |
tmpptr = str; |
while (*str) { |
c = *str; |
c = ( c >= 'a'? c-'a'+10:(c >= 'A'?c-'A'+10:(c <= '9'?c-'0':0xff))); |
if (c > base) { |
break; |
} |
a = (result & 0xff) * base + c; |
b = (result >> 8) * base + (a >> 8); |
if (b > (ULONG_MAX >> 8)) { |
/* overflow */ |
/* FIXME: errno = ERANGE*/ |
return ULONG_MAX; |
} |
result = (b << 8) + (a & 0xff); |
++str; |
} |
if (str == tmpptr) { |
/* no number was found => first invalid character is the first character of the string */ |
/* FIXME: set errno to EINVAL */ |
str = nptr; |
result = 0; |
} |
if (endptr) |
*endptr = (char *)str; |
if (nptr == str) { |
/*FIXME: errno = EINVAL*/ |
return 0; |
} |
return result; |
} |
/** Convert initial part of string to long int according to given base. |
* The number may begin with an arbitrary number of whitespaces followed by optional sign (`+' or `-'). |
* If the base is 0 or 16, the prefix `0x' may be inserted and the number will be taken as hexadecimal one. |
* If the base is 0 and the number begin with a zero, number will be taken as octal one (as with base 8). |
* Otherwise the base 0 is taken as decimal. |
* @param nptr pointer to string |
* @param endptr if not NULL, function stores here pointer to the first invalid character |
* @param base zero or number between 2 and 36 inclusive |
* @return result of conversion. |
*/ |
long int strtol(const char *nptr, char **endptr, int base) |
{ |
char sgn = 0; |
unsigned long number = 0; |
number = _strtoul(nptr, endptr, base, &sgn); |
if (number > LONG_MAX) { |
if ((sgn) && (number == (unsigned long)(LONG_MAX) + 1)) { |
/* FIXME: set 0 to errno */ |
return number; |
} |
/* FIXME: set ERANGE to errno */ |
return (sgn?LONG_MIN:LONG_MAX); |
} |
return (sgn?-number:number); |
} |
/** Convert initial part of string to unsigned long according to given base. |
* The number may begin with an arbitrary number of whitespaces followed by optional sign (`+' or `-'). |
* If the base is 0 or 16, the prefix `0x' may be inserted and the number will be taken as hexadecimal one. |
* If the base is 0 and the number begin with a zero, number will be taken as octal one (as with base 8). |
* Otherwise the base 0 is taken as decimal. |
* @param nptr pointer to string |
* @param endptr if not NULL, function stores here pointer to the first invalid character |
* @param base zero or number between 2 and 36 inclusive |
* @return result of conversion. |
*/ |
unsigned long strtoul(const char *nptr, char **endptr, int base) |
{ |
char sgn = 0; |
unsigned long number = 0; |
number = _strtoul(nptr, endptr, base, &sgn); |
return (sgn?-number:number); |
} |
/uspace/trunk/libc/arch/ia64/include/limits.h |
---|
0,0 → 1,40 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __ia64__LIMITS_H__ |
#define __ia64__LIMITS_H__ |
# define LONG_MIN MIN_INT64 |
# define LONG_MAX MAX_INT64 |
# define ULONG_MIN MIN_UINT64 |
# define ULONG_MAX MAX_UINT64 |
#endif |
/uspace/trunk/libc/arch/mips32eb/include/limits.h |
---|
0,0 → 1,0 |
link ../../mips32/include/limits.h |
Property changes: |
Added: svn:special |
+* |
\ No newline at end of property |
/uspace/trunk/libc/arch/ppc32/include/limits.h |
---|
0,0 → 1,39 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __ppc32__LIMITS_H__ |
#define __ppc32__LIMITS_H__ |
# define LONG_MIN MIN_INT32 |
# define LONG_MAX MAX_INT32 |
# define ULONG_MIN MIN_UINT32 |
# define ULONG_MAX MAX_UINT32 |
#endif |
/uspace/trunk/libc/arch/amd64/include/limits.h |
---|
0,0 → 1,39 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __amd64__LIMITS_H__ |
#define __amd64__LIMITS_H__ |
# define LONG_MIN MIN_INT64 |
# define LONG_MAX MAX_INT64 |
# define ULONG_MIN MIN_UINT64 |
# define ULONG_MAX MAX_UINT64 |
#endif |
/uspace/trunk/libc/arch/mips32/include/limits.h |
---|
0,0 → 1,39 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __mips32__LIMITS_H__ |
#define __mips32__LIMITS_H__ |
# define LONG_MIN MIN_INT32 |
# define LONG_MAX MAX_INT32 |
# define ULONG_MIN MIN_UINT32 |
# define ULONG_MAX MAX_UINT32 |
#endif |
/uspace/trunk/libc/arch/ia32/include/limits.h |
---|
0,0 → 1,38 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __ia32__LIMITS_H__ |
#define __ia32__LIMITS_H__ |
# define LONG_MIN MIN_INT32 |
# define LONG_MAX MAX_INT32 |
# define ULONG_MIN MIN_UINT32 |
# define ULONG_MAX MAX_UINT32 |
#endif |