X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fcompat%2Fstring.h;h=4a96cb1456ffd2a928d18439007cfc3959b2b5e5;hb=4878de5c7deb512bbdac4fdfc498907efa06fb7c;hp=7c426ef3de3bd97e5056ef469f6db6cb528b1c61;hpb=afc5df0361caae100946d58aa557433891d52cb3;p=lttng-tools.git diff --git a/src/common/compat/string.h b/src/common/compat/string.h index 7c426ef3d..4a96cb145 100644 --- a/src/common/compat/string.h +++ b/src/common/compat/string.h @@ -1,30 +1,16 @@ /* * Copyright (C) 2015 Michael Jeanson - * 2015 Jérémie Galarneau + * Copyright (C) 2015 Jérémie Galarneau * - * 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: + * SPDX-License-Identifier: MIT * - * 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. */ #ifndef _COMPAT_STRING_H #define _COMPAT_STRING_H #include +#include #ifdef HAVE_STRNLEN static inline @@ -39,7 +25,7 @@ size_t lttng_strnlen(const char *str, size_t max) size_t ret; const char *end; - end = memchr(str, 0, max); + end = (const char *) memchr(str, 0, max); if (end) { ret = (size_t) (end - str); @@ -75,7 +61,7 @@ char *lttng_strndup(const char *s, size_t n) navail = n + 1; } - ret = malloc(navail); + ret = (char *) malloc(navail); if (!ret) { goto end; } @@ -117,11 +103,31 @@ static inline int lttng_fls(int val) r -= 2; } if (!(x & 0x80000000U)) { - x <<= 1; r -= 1; } return r; } #endif /* HAVE_FLS */ +#ifdef HAVE_MEMRCHR +static inline +void *lttng_memrchr(const void *s, int c, size_t n) +{ + return (void *) memrchr(s, c, n); +} +#else +static inline +void *lttng_memrchr(const void *s, int c, size_t n) +{ + int i; + const char *str = (const char *) s; + for (i = n-1; i >= 0; i--) { + if (str[i] == (char)c) { + return (void *)(str+i); + } + } + return NULL; +} +#endif /* HAVE_MEMRCHR */ + #endif /* _COMPAT_STRING_H */