X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_string.c;h=7950934d8b91fb75971cf6e8baae121491cb8cba;hb=2cb41f7db5b9f89113432d6b3daff4807ba8e5f2;hp=effaf32a6580d5f74201c35310a0ac08f514597c;hpb=123a1ba27ea09c8fa77a1b36ce625b43d7c48b14;p=palacios.releases.git diff --git a/palacios/src/palacios/vmm_string.c b/palacios/src/palacios/vmm_string.c index effaf32..7950934 100644 --- a/palacios/src/palacios/vmm_string.c +++ b/palacios/src/palacios/vmm_string.c @@ -41,7 +41,7 @@ #include -#ifdef CONFIG_BUILT_IN_MEMSET +#ifdef V3_CONFIG_BUILT_IN_MEMSET void * memset(void * s, int c, size_t n) { uchar_t * p = (uchar_t *) s; @@ -54,7 +54,7 @@ void * memset(void * s, int c, size_t n) { } #endif -#ifdef CONFIG_BUILT_IN_MEMCPY +#ifdef V3_CONFIG_BUILT_IN_MEMCPY void * memcpy(void * dst, const void * src, size_t n) { uchar_t * d = (uchar_t *) dst; const uchar_t * s = (const uchar_t *)src; @@ -68,9 +68,14 @@ void * memcpy(void * dst, const void * src, size_t n) { } #endif -#ifdef CONFIG_BUILT_IN_MEMMOVE +#ifdef V3_CONFIG_BUILT_IN_MEMMOVE void * memmove(void * dst, const void * src, size_t n) { uint8_t * tmp = (uint8_t *)V3_Malloc(n); + + if (!tmp) { + PrintError(info->vm_info, info, "Cannot allocate in built-in memmove\n"); + return NULL; + } memcpy(tmp, src, n); memcpy(dst, tmp, n); @@ -81,7 +86,7 @@ void * memmove(void * dst, const void * src, size_t n) { #endif -#ifdef CONFIG_BUILT_IN_MEMCMP +#ifdef V3_CONFIG_BUILT_IN_MEMCMP int memcmp(const void * s1_, const void * s2_, size_t n) { const char * s1 = s1_; const char * s2 = s2_; @@ -102,7 +107,7 @@ int memcmp(const void * s1_, const void * s2_, size_t n) { #endif -#ifdef CONFIG_BUILT_IN_STRLEN +#ifdef V3_CONFIG_BUILT_IN_STRLEN size_t strlen(const char * s) { size_t len = 0; @@ -116,7 +121,7 @@ size_t strlen(const char * s) { -#ifdef CONFIG_BUILT_IN_STRNLEN +#ifdef V3_CONFIG_BUILT_IN_STRNLEN /* * This it a GNU extension. * It is like strlen(), but it will check at most maxlen @@ -137,7 +142,7 @@ size_t strnlen(const char * s, size_t maxlen) { #endif -#ifdef CONFIG_BUILT_IN_STRCMP +#ifdef V3_CONFIG_BUILT_IN_STRCMP int strcmp(const char * s1, const char * s2) { while (1) { int cmp = (*s1 - *s2); @@ -152,7 +157,7 @@ int strcmp(const char * s1, const char * s2) { } #endif -#ifdef CONFIG_BUILT_IN_STRCASECMP +#ifdef V3_CONFIG_BUILT_IN_STRCASECMP int strcasecmp(const char * s1, const char * s2) { while (1) { int cmp = (tolower(*s1) - tolower(*s2)); @@ -169,7 +174,7 @@ int strcasecmp(const char * s1, const char * s2) { #endif -#ifdef CONFIG_BUILT_IN_STRNCMP +#ifdef V3_CONFIG_BUILT_IN_STRNCMP int strncmp(const char * s1, const char * s2, size_t limit) { size_t i = 0; @@ -190,7 +195,7 @@ int strncmp(const char * s1, const char * s2, size_t limit) { } #endif -#ifdef CONFIG_BUILT_IN_STRNCASECMP +#ifdef V3_CONFIG_BUILT_IN_STRNCASECMP int strncasecmp(const char * s1, const char * s2, size_t limit) { size_t i = 0; @@ -211,7 +216,7 @@ int strncasecmp(const char * s1, const char * s2, size_t limit) { #endif -#ifdef CONFIG_BUILT_IN_STRCAT +#ifdef V3_CONFIG_BUILT_IN_STRCAT char * strcat(char * s1, const char * s2) { char * t1 = s1; @@ -225,7 +230,7 @@ char * strcat(char * s1, const char * s2) { #endif -#ifdef CONFIG_BUILT_IN_STRNCAT +#ifdef V3_CONFIG_BUILT_IN_STRNCAT char * strncat(char * s1, const char * s2, size_t limit) { size_t i = 0; char * t1; @@ -247,7 +252,7 @@ char * strncat(char * s1, const char * s2, size_t limit) { -#ifdef CONFIG_BUILT_IN_STRCPY +#ifdef V3_CONFIG_BUILT_IN_STRCPY char * strcpy(char * dest, const char * src) { char *ret = dest; @@ -262,7 +267,7 @@ char * strcpy(char * dest, const char * src) #endif -#ifdef CONFIG_BUILT_IN_STRNCPY +#ifdef V3_CONFIG_BUILT_IN_STRNCPY char * strncpy(char * dest, const char * src, size_t limit) { char * ret = dest; @@ -280,11 +285,17 @@ char * strncpy(char * dest, const char * src, size_t limit) { -#ifdef CONFIG_BUILT_IN_STRDUP +#ifdef V3_CONFIG_BUILT_IN_STRDUP char * strdup(const char * s1) { char *ret; ret = V3_Malloc(strlen(s1) + 1); + + if (!ret) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in built-in strdup\n"); + return NULL; + } + strcpy(ret, s1); return ret; @@ -294,7 +305,7 @@ char * strdup(const char * s1) { -#ifdef CONFIG_BUILT_IN_ATOI +#ifdef V3_CONFIG_BUILT_IN_ATOI int atoi(const char * buf) { int ret = 0; @@ -309,6 +320,7 @@ int atoi(const char * buf) { #endif +#ifdef V3_CONFIG_BUILT_IN_STRTOI int strtoi(const char * nptr, char ** endptr) { int ret = 0; char * buf = (char *)nptr; @@ -326,7 +338,9 @@ int strtoi(const char * nptr, char ** endptr) { return ret; } +#endif +#ifdef V3_CONFIG_BUILT_IN_ATOX uint64_t atox(const char * buf) { uint64_t ret = 0; @@ -348,7 +362,9 @@ uint64_t atox(const char * buf) { return ret; } +#endif +#ifdef V3_CONFIG_BUILT_IN_STRTOX uint64_t strtox(const char * nptr, char ** endptr) { uint64_t ret = 0; char * buf = (char *)nptr; @@ -376,10 +392,10 @@ uint64_t strtox(const char * nptr, char ** endptr) { return ret; } +#endif - -#ifdef CONFIG_BUILT_IN_STRCHR +#ifdef V3_CONFIG_BUILT_IN_STRCHR char * strchr(const char * s, int c) { while (*s != '\0') { if (*s == c) @@ -391,7 +407,7 @@ char * strchr(const char * s, int c) { #endif -#ifdef CONFIG_BUILT_IN_STRRCHR +#ifdef V3_CONFIG_BUILT_IN_STRRCHR char * strrchr(const char * s, int c) { size_t len = strlen(s); const char * p = s + len; @@ -407,7 +423,7 @@ char * strrchr(const char * s, int c) { } #endif -#ifdef CONFIG_BUILT_IN_STRPBRK +#ifdef V3_CONFIG_BUILT_IN_STRPBRK char * strpbrk(const char * s, const char * accept) { size_t setLen = strlen(accept); @@ -425,7 +441,7 @@ char * strpbrk(const char * s, const char * accept) { } #endif -#ifdef CONFIG_BUILT_IN_STRSPN +#ifdef V3_CONFIG_BUILT_IN_STRSPN size_t strspn(const char * s, const char * accept) { int match = 1; int cnt = 0; @@ -449,7 +465,7 @@ size_t strspn(const char * s, const char * accept) { #endif -#ifdef CONFIG_BUILT_IN_STRCSPN +#ifdef V3_CONFIG_BUILT_IN_STRCSPN size_t strcspn(const char * s, const char * reject) { int match = 0; int cnt = 0; @@ -460,10 +476,14 @@ size_t strcspn(const char * s, const char * reject) { for (i = 0; i < reject_len; i++) { if (s[cnt] == reject[i]) { match = 1; - cnt++; break; } } + + if (!match) { + cnt++; + } + } return cnt; @@ -471,7 +491,7 @@ size_t strcspn(const char * s, const char * reject) { #endif -#ifdef CONFIG_BUILT_IN_STRSTR +#ifdef V3_CONFIG_BUILT_IN_STRSTR char *strstr(const char *haystack, const char *needle) { int l1, l2; @@ -490,7 +510,7 @@ char *strstr(const char *haystack, const char *needle) } #endif - +#ifdef V3_CONFIG_BUILT_IN_STR_TOLOWER void str_tolower(char * s) { while (isalpha(*s)) { if (!islower(*s)) { @@ -499,8 +519,9 @@ void str_tolower(char * s) { s++; } } +#endif - +#ifdef V3_CONFIG_BUILT_IN_STR_TOUPPER void str_toupper(char * s) { while (isalpha(*s)) { if (!isupper(*s)) { @@ -509,3 +530,4 @@ void str_toupper(char * s) { s++; } } +#endif