X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_string.c;h=efe5a7df29394f4f81109b00e4dc446ce242a75b;hb=0dc6c1ec345d5c48e348b7e6532e5dcec00fa2ff;hp=af912b4d9bd63805f57b96854caff3dc6545d234;hpb=101529b6eae500272347287df43ec51aa003d0aa;p=palacios.git diff --git a/palacios/src/palacios/vmm_string.c b/palacios/src/palacios/vmm_string.c index af912b4..efe5a7d 100644 --- a/palacios/src/palacios/vmm_string.c +++ b/palacios/src/palacios/vmm_string.c @@ -1,14 +1,30 @@ /* - * String library - * Copyright (c) 2001,2004 David H. Hovemeyer - * (c) 2008, Jack Lange - * (c) 2008, The V3VEE Project - * $Revision: 1.2 $ - * - * This is free software. You are permitted to use, - * redistribute, and modify it as specified in the file "COPYING". + * String library + * Copyright (c) 2001,2003,2004 David H. Hovemeyer + * Copyright (c) 2003, Jeffrey K. Hollingsworth + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF + * ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT + * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - +/* Modifications by Jack Lange */ @@ -20,21 +36,31 @@ */ -#include -#include +#define NEED_MEMSET 0 +#define NEED_MEMCPY 0 +#define NEED_MEMCMP 0 +#define NEED_STRLEN 0 +#define NEED_STRNLEN 0 +#define NEED_STRCMP 0 +#define NEED_STRNCMP 0 +#define NEED_STRCAT 0 +#define NEED_STRNCAT 0 +#define NEED_STRCPY 0 +#define NEED_STRNCPY 0 +#define NEED_STRDUP 0 +#define NEED_ATOI 0 +#define NEED_STRCHR 0 +#define NEED_STRRCHR 0 +#define NEED_STRPBRK 0 -static float e = 0.00000001; -double ceil(double x) { - if ((double)(x - (int)x) == 0) { - return (int)x; - } - return (int)(x + e) + 1; -} +#include +#include + -#if 0 +#if NEED_MEMSET void* memset(void* s, int c, size_t n) { unsigned char* p = (unsigned char*) s; @@ -46,8 +72,9 @@ void* memset(void* s, int c, size_t n) return s; } +#endif - +#if NEED_MEMCPY void* memcpy(void *dst, const void* src, size_t n) { unsigned char* d = (unsigned char*) dst; @@ -60,8 +87,10 @@ void* memcpy(void *dst, const void* src, size_t n) return dst; } +#endif +#if NEED_CMP int memcmp(const void *s1_, const void *s2_, size_t n) { const signed char *s1 = s1_, *s2 = s2_; @@ -76,7 +105,10 @@ int memcmp(const void *s1_, const void *s2_, size_t n) return 0; } +#endif + +#if NEED_STRLEN size_t strlen(const char* s) { size_t len = 0; @@ -84,7 +116,11 @@ size_t strlen(const char* s) ++len; return len; } +#endif + + +#if NEED_STRNLEN /* * This it a GNU extension. * It is like strlen(), but it will check at most maxlen @@ -100,7 +136,10 @@ size_t strnlen(const char *s, size_t maxlen) ++len; return len; } +#endif + +#if NEED_STRCMP int strcmp(const char* s1, const char* s2) { while (1) { @@ -111,7 +150,10 @@ int strcmp(const char* s1, const char* s2) ++s2; } } +#endif + +#if NEED_STRNCMP int strncmp(const char* s1, const char* s2, size_t limit) { size_t i = 0; @@ -127,7 +169,10 @@ int strncmp(const char* s1, const char* s2, size_t limit) /* limit reached and equal */ return 0; } +#endif + +#if NEED_STRCAT char *strcat(char *s1, const char *s2) { char *t1; @@ -139,7 +184,28 @@ char *strcat(char *s1, const char *s2) return t1; } +#endif + +#if NEED_STRNCAT +char *strncat(char *s1, const char *s2, size_t limit) +{ + size_t i = 0; + char *t1; + t1 = s1; + while (*s1) s1++; + while (i < limit) { + if(*s2 == '\0') break; + *s1++ = *s2++; + } + *s1 = '\0'; + return t1; +} +#endif + + + +#if NEED_STRCPY char *strcpy(char *dest, const char *src) { char *ret = dest; @@ -151,7 +217,10 @@ char *strcpy(char *dest, const char *src) return ret; } +#endif + +#if NEED_STRNCPY char *strncpy(char *dest, const char *src, size_t limit) { char *ret = dest; @@ -165,7 +234,11 @@ char *strncpy(char *dest, const char *src, size_t limit) return ret; } +#endif + + +#if NEED_STRDUP char *strdup(const char *s1) { char *ret; @@ -175,20 +248,28 @@ char *strdup(const char *s1) return ret; } +#endif + + + +#if NEED_ATOI int atoi(const char *buf) { int ret = 0; while (*buf >= '0' && *buf <= '9') { - ret *= 10; - ret += *buf - '0'; - buf++; + ret *= 10; + ret += *buf - '0'; + buf++; } return ret; } +#endif + +#if NEED_STRCHR char *strchr(const char *s, int c) { while (*s != '\0') { @@ -198,7 +279,10 @@ char *strchr(const char *s, int c) } return 0; } +#endif + +#if NEED_STRRCHR char *strrchr(const char *s, int c) { size_t len = strlen(s); @@ -211,7 +295,9 @@ char *strrchr(const char *s, int c) } return 0; } +#endif +#if NEED_STRPBRK char *strpbrk(const char *s, const char *accept) { size_t setLen = strlen(accept); @@ -227,5 +313,5 @@ char *strpbrk(const char *s, const char *accept) return 0; } - #endif +