2 * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
3 * Copyright (C) 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: MIT
9 #ifndef _COMPAT_STRING_H
10 #define _COMPAT_STRING_H
16 size_t lttng_strnlen(const char *str
, size_t max
)
18 return strnlen(str
, max
);
22 size_t lttng_strnlen(const char *str
, size_t max
)
27 end
= memchr(str
, 0, max
);
30 ret
= (size_t) (end
- str
);
37 #endif /* HAVE_STRNLEN */
41 char *lttng_strndup(const char *s
, size_t n
)
47 char *lttng_strndup(const char *s
, size_t n
)
58 navail
= strlen(s
) + 1;
59 if ((n
+ 1) < navail
) {
68 memcpy(ret
, s
, navail
);
69 ret
[navail
- 1] = '\0';
73 #endif /* HAVE_STRNDUP */
76 static inline int lttng_fls(int val
)
81 static inline int lttng_fls(int val
)
84 unsigned int x
= (unsigned int) val
;
88 if (!(x
& 0xFFFF0000U
)) {
92 if (!(x
& 0xFF000000U
)) {
96 if (!(x
& 0xF0000000U
)) {
100 if (!(x
& 0xC0000000U
)) {
104 if (!(x
& 0x80000000U
)) {
109 #endif /* HAVE_FLS */
113 void *lttng_memrchr(const void *s
, int c
, size_t n
)
115 return memrchr(s
, c
, n
);
119 void *lttng_memrchr(const void *s
, int c
, size_t n
)
123 for (i
= n
-1; i
>= 0; i
--) {
124 if (str
[i
] == (char)c
) {
125 return (void *)(str
+i
);
130 #endif /* HAVE_MEMRCHR */
132 #endif /* _COMPAT_STRING_H */
This page took 0.047626 seconds and 5 git commands to generate.