From: Philippe Proulx Date: Tue, 4 Apr 2017 18:49:10 +0000 (-0400) Subject: Add `-internal` suffix to all internal header files X-Git-Tag: v2.0.0-pre1~382 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=3d9990ac8bcbb870300869ed217b80151b52bf4e Add `-internal` suffix to all internal header files Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/cli/babeltrace-cfg.h b/cli/babeltrace-cfg.h index ca2f9950..508840e4 100644 --- a/cli/babeltrace-cfg.h +++ b/cli/babeltrace-cfg.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/cli/babeltrace-log.c b/cli/babeltrace-log.c index 38cf8392..27070fc5 100644 --- a/cli/babeltrace-log.c +++ b/cli/babeltrace-log.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include @@ -43,10 +43,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #define NSEC_PER_USEC 1000UL #define NSEC_PER_MSEC 1000000UL diff --git a/compat/compat_uuid.c b/compat/compat_uuid.c index a775da47..03ca1675 100644 --- a/compat/compat_uuid.c +++ b/compat/compat_uuid.c @@ -26,7 +26,7 @@ #include #include -#include +#include /* MinGW does not provide byteswap - implement our own version. */ static diff --git a/include/Makefile.am b/include/Makefile.am index ae8d6dcc..8aef2965 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -65,12 +65,12 @@ babeltracegraphinclude_HEADERS = \ babeltrace/graph/private-port.h noinst_HEADERS = \ - babeltrace/align.h \ + babeltrace/align-internal.h \ babeltrace/babeltrace-internal.h \ - babeltrace/bitfield.h \ + babeltrace/bitfield-internal.h \ babeltrace/common-internal.h \ - babeltrace/compiler.h \ - babeltrace/prio_heap.h \ + babeltrace/compiler-internal.h \ + babeltrace/prio-heap-internal.h \ babeltrace/ref-internal.h \ babeltrace/object-internal.h \ babeltrace/ctf-writer/writer-internal.h \ @@ -91,20 +91,20 @@ noinst_HEADERS = \ babeltrace/ctf-ir/visitor-internal.h \ babeltrace/ctf-writer/clock-internal.h \ babeltrace/ctf-writer/functor-internal.h \ - babeltrace/compat/uuid.h \ - babeltrace/compat/memstream.h \ - babeltrace/compat/string.h \ - babeltrace/compat/utc.h \ - babeltrace/compat/limits.h \ - babeltrace/compat/glib.h \ - babeltrace/compat/send.h \ - babeltrace/compat/fcntl.h \ - babeltrace/compat/stdlib.h \ - babeltrace/compat/dirent.h \ - babeltrace/compat/stdio.h \ - babeltrace/compat/mman.h \ - babeltrace/endian.h \ - babeltrace/mmap-align.h \ + babeltrace/compat/uuid-internal.h \ + babeltrace/compat/memstream-internal.h \ + babeltrace/compat/string-internal.h \ + babeltrace/compat/utc-internal.h \ + babeltrace/compat/limits-internal.h \ + babeltrace/compat/glib-internal.h \ + babeltrace/compat/send-internal.h \ + babeltrace/compat/fcntl-internal.h \ + babeltrace/compat/stdlib-internal.h \ + babeltrace/compat/dirent-internal.h \ + babeltrace/compat/stdio-internal.h \ + babeltrace/compat/mman-internal.h \ + babeltrace/endian-internal.h \ + babeltrace/mmap-align-internal.h \ babeltrace/plugin/plugin-internal.h \ babeltrace/plugin/plugin-so-internal.h \ babeltrace/graph/component-class-internal.h \ diff --git a/include/babeltrace/align-internal.h b/include/babeltrace/align-internal.h new file mode 100644 index 00000000..a2566c99 --- /dev/null +++ b/include/babeltrace/align-internal.h @@ -0,0 +1,82 @@ +#ifndef _BABELTRACE_ALIGN_H +#define _BABELTRACE_ALIGN_H + +/* + * BabelTrace align.h - alignment header + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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. + */ + +#include +#include +#include + +#ifndef PAGE_SIZE /* Cygwin limits.h defines its own PAGE_SIZE */ +#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) +#endif + +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1) +#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) +#define PTR_ALIGN(p, a) ((typeof(p)) ALIGN((unsigned long) (p), a)) +#define ALIGN_FLOOR(x, a) __ALIGN_FLOOR_MASK(x, (typeof(x)) (a) - 1) +#define __ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask)) +#define PTR_ALIGN_FLOOR(p, a) \ + ((typeof(p)) ALIGN_FLOOR((unsigned long) (p), a)) +#define IS_ALIGNED(x, a) (((x) & ((typeof(x)) (a) - 1)) == 0) + +/* + * Align pointer on natural object alignment. + */ +#define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj))) +#define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj))) + +/** + * offset_align - Calculate the offset needed to align an object on its natural + * alignment towards higher addresses. + * @align_drift: object offset from an "alignment"-aligned address. + * @alignment: natural object alignment. Must be non-zero, power of 2. + * + * Returns the offset that must be added to align towards higher + * addresses. + */ +#define offset_align(align_drift, alignment) \ + ({ \ + MAYBE_BUILD_BUG_ON((alignment) == 0 \ + || ((alignment) & ((alignment) - 1))); \ + (((alignment) - (align_drift)) & ((alignment) - 1)); \ + }) + +/** + * offset_align_floor - Calculate the offset needed to align an object + * on its natural alignment towards lower addresses. + * @align_drift: object offset from an "alignment"-aligned address. + * @alignment: natural object alignment. Must be non-zero, power of 2. + * + * Returns the offset that must be substracted to align towards lower addresses. + */ +#define offset_align_floor(align_drift, alignment) \ + ({ \ + MAYBE_BUILD_BUG_ON((alignment) == 0 \ + || ((alignment) & ((alignment) - 1))); \ + (((align_drift) - (alignment)) & ((alignment) - 1)); \ + }) + +#endif /* _BABELTRACE_ALIGN_H */ diff --git a/include/babeltrace/align.h b/include/babeltrace/align.h deleted file mode 100644 index 67ece4dd..00000000 --- a/include/babeltrace/align.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef _BABELTRACE_ALIGN_H -#define _BABELTRACE_ALIGN_H - -/* - * BabelTrace align.h - alignment header - * - * Copyright 2010 - Mathieu Desnoyers - * - * 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. - */ - -#include -#include -#include - -#ifndef PAGE_SIZE /* Cygwin limits.h defines its own PAGE_SIZE */ -#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) -#endif - -#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1) -#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) -#define PTR_ALIGN(p, a) ((typeof(p)) ALIGN((unsigned long) (p), a)) -#define ALIGN_FLOOR(x, a) __ALIGN_FLOOR_MASK(x, (typeof(x)) (a) - 1) -#define __ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask)) -#define PTR_ALIGN_FLOOR(p, a) \ - ((typeof(p)) ALIGN_FLOOR((unsigned long) (p), a)) -#define IS_ALIGNED(x, a) (((x) & ((typeof(x)) (a) - 1)) == 0) - -/* - * Align pointer on natural object alignment. - */ -#define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj))) -#define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj))) - -/** - * offset_align - Calculate the offset needed to align an object on its natural - * alignment towards higher addresses. - * @align_drift: object offset from an "alignment"-aligned address. - * @alignment: natural object alignment. Must be non-zero, power of 2. - * - * Returns the offset that must be added to align towards higher - * addresses. - */ -#define offset_align(align_drift, alignment) \ - ({ \ - MAYBE_BUILD_BUG_ON((alignment) == 0 \ - || ((alignment) & ((alignment) - 1))); \ - (((alignment) - (align_drift)) & ((alignment) - 1)); \ - }) - -/** - * offset_align_floor - Calculate the offset needed to align an object - * on its natural alignment towards lower addresses. - * @align_drift: object offset from an "alignment"-aligned address. - * @alignment: natural object alignment. Must be non-zero, power of 2. - * - * Returns the offset that must be substracted to align towards lower addresses. - */ -#define offset_align_floor(align_drift, alignment) \ - ({ \ - MAYBE_BUILD_BUG_ON((alignment) == 0 \ - || ((alignment) & ((alignment) - 1))); \ - (((align_drift) - (alignment)) & ((alignment) - 1)); \ - }) - -#endif /* _BABELTRACE_ALIGN_H */ diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h index 535f9909..367762ab 100644 --- a/include/babeltrace/babeltrace-internal.h +++ b/include/babeltrace/babeltrace-internal.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #define PERROR_BUFLEN 200 diff --git a/include/babeltrace/bitfield-internal.h b/include/babeltrace/bitfield-internal.h new file mode 100644 index 00000000..d3609e3c --- /dev/null +++ b/include/babeltrace/bitfield-internal.h @@ -0,0 +1,407 @@ +#ifndef _BABELTRACE_BITFIELD_H +#define _BABELTRACE_BITFIELD_H + +/* + * BabelTrace + * + * Bitfields read/write functions. + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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. + */ + +#include /* C99 5.2.4.2 Numerical limits */ +#include /* C99 5.2.4.2 Numerical limits */ +#include +#include /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */ + +/* We can't shift a int from 32 bit, >> 32 and << 32 on int is undefined */ +#define _bt_piecewise_rshift(_v, _shift) \ +({ \ + typeof(_v) ___v = (_v); \ + typeof(_shift) ___shift = (_shift); \ + unsigned long sb = (___shift) / (sizeof(___v) * CHAR_BIT - 1); \ + unsigned long final = (___shift) % (sizeof(___v) * CHAR_BIT - 1); \ + \ + for (; sb; sb--) \ + ___v >>= sizeof(___v) * CHAR_BIT - 1; \ + ___v >>= final; \ +}) + +#define _bt_piecewise_lshift(_v, _shift) \ +({ \ + typeof(_v) ___v = (_v); \ + typeof(_shift) ___shift = (_shift); \ + unsigned long sb = (___shift) / (sizeof(___v) * CHAR_BIT - 1); \ + unsigned long final = (___shift) % (sizeof(___v) * CHAR_BIT - 1); \ + \ + for (; sb; sb--) \ + ___v <<= sizeof(___v) * CHAR_BIT - 1; \ + ___v <<= final; \ +}) + +#define _bt_is_signed_type(type) ((type) -1 < (type) 0) + +#define _bt_unsigned_cast(type, v) \ +({ \ + (sizeof(v) < sizeof(type)) ? \ + ((type) (v)) & (~(~(type) 0 << (sizeof(v) * CHAR_BIT))) : \ + (type) (v); \ +}) + +/* + * bt_bitfield_write - write integer to a bitfield in native endianness + * + * Save integer to the bitfield, which starts at the "start" bit, has "len" + * bits. + * The inside of a bitfield is from high bits to low bits. + * Uses native endianness. + * For unsigned "v", pad MSB with 0 if bitfield is larger than v. + * For signed "v", sign-extend v if bitfield is larger than v. + * + * On little endian, bytes are placed from the less significant to the most + * significant. Also, consecutive bitfields are placed from lower bits to higher + * bits. + * + * On big endian, bytes are places from most significant to less significant. + * Also, consecutive bitfields are placed from higher to lower bits. + */ + +#define _bt_bitfield_write_le(_ptr, type, _start, _length, _v) \ +do { \ + typeof(_v) __v = (_v); \ + type *__ptr = (void *) (_ptr); \ + unsigned long __start = (_start), __length = (_length); \ + type mask, cmask; \ + unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ + unsigned long start_unit, end_unit, this_unit; \ + unsigned long end, cshift; /* cshift is "complement shift" */ \ + \ + if (!__length) \ + break; \ + \ + end = __start + __length; \ + start_unit = __start / ts; \ + end_unit = (end + (ts - 1)) / ts; \ + \ + /* Trim v high bits */ \ + if (__length < sizeof(__v) * CHAR_BIT) \ + __v &= ~((~(typeof(__v)) 0) << __length); \ + \ + /* We can now append v with a simple "or", shift it piece-wise */ \ + this_unit = start_unit; \ + if (start_unit == end_unit - 1) { \ + mask = ~((~(type) 0) << (__start % ts)); \ + if (end % ts) \ + mask |= (~(type) 0) << (end % ts); \ + cmask = (type) __v << (__start % ts); \ + cmask &= ~mask; \ + __ptr[this_unit] &= mask; \ + __ptr[this_unit] |= cmask; \ + break; \ + } \ + if (__start % ts) { \ + cshift = __start % ts; \ + mask = ~((~(type) 0) << cshift); \ + cmask = (type) __v << cshift; \ + cmask &= ~mask; \ + __ptr[this_unit] &= mask; \ + __ptr[this_unit] |= cmask; \ + __v = _bt_piecewise_rshift(__v, ts - cshift); \ + __start += ts - cshift; \ + this_unit++; \ + } \ + for (; this_unit < end_unit - 1; this_unit++) { \ + __ptr[this_unit] = (type) __v; \ + __v = _bt_piecewise_rshift(__v, ts); \ + __start += ts; \ + } \ + if (end % ts) { \ + mask = (~(type) 0) << (end % ts); \ + cmask = (type) __v; \ + cmask &= ~mask; \ + __ptr[this_unit] &= mask; \ + __ptr[this_unit] |= cmask; \ + } else \ + __ptr[this_unit] = (type) __v; \ +} while (0) + +#define _bt_bitfield_write_be(_ptr, type, _start, _length, _v) \ +do { \ + typeof(_v) __v = (_v); \ + type *__ptr = (void *) (_ptr); \ + unsigned long __start = (_start), __length = (_length); \ + type mask, cmask; \ + unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ + unsigned long start_unit, end_unit, this_unit; \ + unsigned long end, cshift; /* cshift is "complement shift" */ \ + \ + if (!__length) \ + break; \ + \ + end = __start + __length; \ + start_unit = __start / ts; \ + end_unit = (end + (ts - 1)) / ts; \ + \ + /* Trim v high bits */ \ + if (__length < sizeof(__v) * CHAR_BIT) \ + __v &= ~((~(typeof(__v)) 0) << __length); \ + \ + /* We can now append v with a simple "or", shift it piece-wise */ \ + this_unit = end_unit - 1; \ + if (start_unit == end_unit - 1) { \ + mask = ~((~(type) 0) << ((ts - (end % ts)) % ts)); \ + if (__start % ts) \ + mask |= (~((type) 0)) << (ts - (__start % ts)); \ + cmask = (type) __v << ((ts - (end % ts)) % ts); \ + cmask &= ~mask; \ + __ptr[this_unit] &= mask; \ + __ptr[this_unit] |= cmask; \ + break; \ + } \ + if (end % ts) { \ + cshift = end % ts; \ + mask = ~((~(type) 0) << (ts - cshift)); \ + cmask = (type) __v << (ts - cshift); \ + cmask &= ~mask; \ + __ptr[this_unit] &= mask; \ + __ptr[this_unit] |= cmask; \ + __v = _bt_piecewise_rshift(__v, cshift); \ + end -= cshift; \ + this_unit--; \ + } \ + for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \ + __ptr[this_unit] = (type) __v; \ + __v = _bt_piecewise_rshift(__v, ts); \ + end -= ts; \ + } \ + if (__start % ts) { \ + mask = (~(type) 0) << (ts - (__start % ts)); \ + cmask = (type) __v; \ + cmask &= ~mask; \ + __ptr[this_unit] &= mask; \ + __ptr[this_unit] |= cmask; \ + } else \ + __ptr[this_unit] = (type) __v; \ +} while (0) + +/* + * bt_bitfield_write - write integer to a bitfield in native endianness + * bt_bitfield_write_le - write integer to a bitfield in little endian + * bt_bitfield_write_be - write integer to a bitfield in big endian + */ + +#if (BYTE_ORDER == LITTLE_ENDIAN) + +#define bt_bitfield_write(ptr, type, _start, _length, _v) \ + _bt_bitfield_write_le(ptr, type, _start, _length, _v) + +#define bt_bitfield_write_le(ptr, type, _start, _length, _v) \ + _bt_bitfield_write_le(ptr, type, _start, _length, _v) + +#define bt_bitfield_write_be(ptr, type, _start, _length, _v) \ + _bt_bitfield_write_be(ptr, unsigned char, _start, _length, _v) + +#elif (BYTE_ORDER == BIG_ENDIAN) + +#define bt_bitfield_write(ptr, type, _start, _length, _v) \ + _bt_bitfield_write_be(ptr, type, _start, _length, _v) + +#define bt_bitfield_write_le(ptr, type, _start, _length, _v) \ + _bt_bitfield_write_le(ptr, unsigned char, _start, _length, _v) + +#define bt_bitfield_write_be(ptr, type, _start, _length, _v) \ + _bt_bitfield_write_be(ptr, type, _start, _length, _v) + +#else /* (BYTE_ORDER == PDP_ENDIAN) */ + +#error "Byte order not supported" + +#endif + +#define _bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) \ +do { \ + typeof(*(_vptr)) *__vptr = (_vptr); \ + typeof(*__vptr) __v; \ + type *__ptr = (void *) (_ptr); \ + unsigned long __start = (_start), __length = (_length); \ + type mask, cmask; \ + unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ + unsigned long start_unit, end_unit, this_unit; \ + unsigned long end, cshift; /* cshift is "complement shift" */ \ + \ + if (!__length) { \ + *__vptr = 0; \ + break; \ + } \ + \ + end = __start + __length; \ + start_unit = __start / ts; \ + end_unit = (end + (ts - 1)) / ts; \ + \ + this_unit = end_unit - 1; \ + if (_bt_is_signed_type(typeof(__v)) \ + && (__ptr[this_unit] & ((type) 1 << ((end % ts ? : ts) - 1)))) \ + __v = ~(typeof(__v)) 0; \ + else \ + __v = 0; \ + if (start_unit == end_unit - 1) { \ + cmask = __ptr[this_unit]; \ + cmask >>= (__start % ts); \ + if ((end - __start) % ts) { \ + mask = ~((~(type) 0) << (end - __start)); \ + cmask &= mask; \ + } \ + __v = _bt_piecewise_lshift(__v, end - __start); \ + __v |= _bt_unsigned_cast(typeof(__v), cmask); \ + *__vptr = __v; \ + break; \ + } \ + if (end % ts) { \ + cshift = end % ts; \ + mask = ~((~(type) 0) << cshift); \ + cmask = __ptr[this_unit]; \ + cmask &= mask; \ + __v = _bt_piecewise_lshift(__v, cshift); \ + __v |= _bt_unsigned_cast(typeof(__v), cmask); \ + end -= cshift; \ + this_unit--; \ + } \ + for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \ + __v = _bt_piecewise_lshift(__v, ts); \ + __v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\ + end -= ts; \ + } \ + if (__start % ts) { \ + mask = ~((~(type) 0) << (ts - (__start % ts))); \ + cmask = __ptr[this_unit]; \ + cmask >>= (__start % ts); \ + cmask &= mask; \ + __v = _bt_piecewise_lshift(__v, ts - (__start % ts)); \ + __v |= _bt_unsigned_cast(typeof(__v), cmask); \ + } else { \ + __v = _bt_piecewise_lshift(__v, ts); \ + __v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\ + } \ + *__vptr = __v; \ +} while (0) + +#define _bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) \ +do { \ + typeof(*(_vptr)) *__vptr = (_vptr); \ + typeof(*__vptr) __v; \ + type *__ptr = (void *) (_ptr); \ + unsigned long __start = (_start), __length = (_length); \ + type mask, cmask; \ + unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ + unsigned long start_unit, end_unit, this_unit; \ + unsigned long end, cshift; /* cshift is "complement shift" */ \ + \ + if (!__length) { \ + *__vptr = 0; \ + break; \ + } \ + \ + end = __start + __length; \ + start_unit = __start / ts; \ + end_unit = (end + (ts - 1)) / ts; \ + \ + this_unit = start_unit; \ + if (_bt_is_signed_type(typeof(__v)) \ + && (__ptr[this_unit] & ((type) 1 << (ts - (__start % ts) - 1)))) \ + __v = ~(typeof(__v)) 0; \ + else \ + __v = 0; \ + if (start_unit == end_unit - 1) { \ + cmask = __ptr[this_unit]; \ + cmask >>= (ts - (end % ts)) % ts; \ + if ((end - __start) % ts) { \ + mask = ~((~(type) 0) << (end - __start)); \ + cmask &= mask; \ + } \ + __v = _bt_piecewise_lshift(__v, end - __start); \ + __v |= _bt_unsigned_cast(typeof(__v), cmask); \ + *__vptr = __v; \ + break; \ + } \ + if (__start % ts) { \ + cshift = __start % ts; \ + mask = ~((~(type) 0) << (ts - cshift)); \ + cmask = __ptr[this_unit]; \ + cmask &= mask; \ + __v = _bt_piecewise_lshift(__v, ts - cshift); \ + __v |= _bt_unsigned_cast(typeof(__v), cmask); \ + __start += ts - cshift; \ + this_unit++; \ + } \ + for (; this_unit < end_unit - 1; this_unit++) { \ + __v = _bt_piecewise_lshift(__v, ts); \ + __v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\ + __start += ts; \ + } \ + if (end % ts) { \ + mask = ~((~(type) 0) << (end % ts)); \ + cmask = __ptr[this_unit]; \ + cmask >>= ts - (end % ts); \ + cmask &= mask; \ + __v = _bt_piecewise_lshift(__v, end % ts); \ + __v |= _bt_unsigned_cast(typeof(__v), cmask); \ + } else { \ + __v = _bt_piecewise_lshift(__v, ts); \ + __v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\ + } \ + *__vptr = __v; \ +} while (0) + +/* + * bt_bitfield_read - read integer from a bitfield in native endianness + * bt_bitfield_read_le - read integer from a bitfield in little endian + * bt_bitfield_read_be - read integer from a bitfield in big endian + */ + +#if (BYTE_ORDER == LITTLE_ENDIAN) + +#define bt_bitfield_read(_ptr, type, _start, _length, _vptr) \ + _bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) + +#define bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) \ + _bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) + +#define bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) \ + _bt_bitfield_read_be(_ptr, unsigned char, _start, _length, _vptr) + +#elif (BYTE_ORDER == BIG_ENDIAN) + +#define bt_bitfield_read(_ptr, type, _start, _length, _vptr) \ + _bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) + +#define bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) \ + _bt_bitfield_read_le(_ptr, unsigned char, _start, _length, _vptr) + +#define bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) \ + _bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) + +#else /* (BYTE_ORDER == PDP_ENDIAN) */ + +#error "Byte order not supported" + +#endif + +#endif /* _BABELTRACE_BITFIELD_H */ diff --git a/include/babeltrace/bitfield.h b/include/babeltrace/bitfield.h deleted file mode 100644 index 6cf804ed..00000000 --- a/include/babeltrace/bitfield.h +++ /dev/null @@ -1,407 +0,0 @@ -#ifndef _BABELTRACE_BITFIELD_H -#define _BABELTRACE_BITFIELD_H - -/* - * BabelTrace - * - * Bitfields read/write functions. - * - * Copyright 2010 - Mathieu Desnoyers - * - * 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. - */ - -#include /* C99 5.2.4.2 Numerical limits */ -#include /* C99 5.2.4.2 Numerical limits */ -#include -#include /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */ - -/* We can't shift a int from 32 bit, >> 32 and << 32 on int is undefined */ -#define _bt_piecewise_rshift(_v, _shift) \ -({ \ - typeof(_v) ___v = (_v); \ - typeof(_shift) ___shift = (_shift); \ - unsigned long sb = (___shift) / (sizeof(___v) * CHAR_BIT - 1); \ - unsigned long final = (___shift) % (sizeof(___v) * CHAR_BIT - 1); \ - \ - for (; sb; sb--) \ - ___v >>= sizeof(___v) * CHAR_BIT - 1; \ - ___v >>= final; \ -}) - -#define _bt_piecewise_lshift(_v, _shift) \ -({ \ - typeof(_v) ___v = (_v); \ - typeof(_shift) ___shift = (_shift); \ - unsigned long sb = (___shift) / (sizeof(___v) * CHAR_BIT - 1); \ - unsigned long final = (___shift) % (sizeof(___v) * CHAR_BIT - 1); \ - \ - for (; sb; sb--) \ - ___v <<= sizeof(___v) * CHAR_BIT - 1; \ - ___v <<= final; \ -}) - -#define _bt_is_signed_type(type) ((type) -1 < (type) 0) - -#define _bt_unsigned_cast(type, v) \ -({ \ - (sizeof(v) < sizeof(type)) ? \ - ((type) (v)) & (~(~(type) 0 << (sizeof(v) * CHAR_BIT))) : \ - (type) (v); \ -}) - -/* - * bt_bitfield_write - write integer to a bitfield in native endianness - * - * Save integer to the bitfield, which starts at the "start" bit, has "len" - * bits. - * The inside of a bitfield is from high bits to low bits. - * Uses native endianness. - * For unsigned "v", pad MSB with 0 if bitfield is larger than v. - * For signed "v", sign-extend v if bitfield is larger than v. - * - * On little endian, bytes are placed from the less significant to the most - * significant. Also, consecutive bitfields are placed from lower bits to higher - * bits. - * - * On big endian, bytes are places from most significant to less significant. - * Also, consecutive bitfields are placed from higher to lower bits. - */ - -#define _bt_bitfield_write_le(_ptr, type, _start, _length, _v) \ -do { \ - typeof(_v) __v = (_v); \ - type *__ptr = (void *) (_ptr); \ - unsigned long __start = (_start), __length = (_length); \ - type mask, cmask; \ - unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ - unsigned long start_unit, end_unit, this_unit; \ - unsigned long end, cshift; /* cshift is "complement shift" */ \ - \ - if (!__length) \ - break; \ - \ - end = __start + __length; \ - start_unit = __start / ts; \ - end_unit = (end + (ts - 1)) / ts; \ - \ - /* Trim v high bits */ \ - if (__length < sizeof(__v) * CHAR_BIT) \ - __v &= ~((~(typeof(__v)) 0) << __length); \ - \ - /* We can now append v with a simple "or", shift it piece-wise */ \ - this_unit = start_unit; \ - if (start_unit == end_unit - 1) { \ - mask = ~((~(type) 0) << (__start % ts)); \ - if (end % ts) \ - mask |= (~(type) 0) << (end % ts); \ - cmask = (type) __v << (__start % ts); \ - cmask &= ~mask; \ - __ptr[this_unit] &= mask; \ - __ptr[this_unit] |= cmask; \ - break; \ - } \ - if (__start % ts) { \ - cshift = __start % ts; \ - mask = ~((~(type) 0) << cshift); \ - cmask = (type) __v << cshift; \ - cmask &= ~mask; \ - __ptr[this_unit] &= mask; \ - __ptr[this_unit] |= cmask; \ - __v = _bt_piecewise_rshift(__v, ts - cshift); \ - __start += ts - cshift; \ - this_unit++; \ - } \ - for (; this_unit < end_unit - 1; this_unit++) { \ - __ptr[this_unit] = (type) __v; \ - __v = _bt_piecewise_rshift(__v, ts); \ - __start += ts; \ - } \ - if (end % ts) { \ - mask = (~(type) 0) << (end % ts); \ - cmask = (type) __v; \ - cmask &= ~mask; \ - __ptr[this_unit] &= mask; \ - __ptr[this_unit] |= cmask; \ - } else \ - __ptr[this_unit] = (type) __v; \ -} while (0) - -#define _bt_bitfield_write_be(_ptr, type, _start, _length, _v) \ -do { \ - typeof(_v) __v = (_v); \ - type *__ptr = (void *) (_ptr); \ - unsigned long __start = (_start), __length = (_length); \ - type mask, cmask; \ - unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ - unsigned long start_unit, end_unit, this_unit; \ - unsigned long end, cshift; /* cshift is "complement shift" */ \ - \ - if (!__length) \ - break; \ - \ - end = __start + __length; \ - start_unit = __start / ts; \ - end_unit = (end + (ts - 1)) / ts; \ - \ - /* Trim v high bits */ \ - if (__length < sizeof(__v) * CHAR_BIT) \ - __v &= ~((~(typeof(__v)) 0) << __length); \ - \ - /* We can now append v with a simple "or", shift it piece-wise */ \ - this_unit = end_unit - 1; \ - if (start_unit == end_unit - 1) { \ - mask = ~((~(type) 0) << ((ts - (end % ts)) % ts)); \ - if (__start % ts) \ - mask |= (~((type) 0)) << (ts - (__start % ts)); \ - cmask = (type) __v << ((ts - (end % ts)) % ts); \ - cmask &= ~mask; \ - __ptr[this_unit] &= mask; \ - __ptr[this_unit] |= cmask; \ - break; \ - } \ - if (end % ts) { \ - cshift = end % ts; \ - mask = ~((~(type) 0) << (ts - cshift)); \ - cmask = (type) __v << (ts - cshift); \ - cmask &= ~mask; \ - __ptr[this_unit] &= mask; \ - __ptr[this_unit] |= cmask; \ - __v = _bt_piecewise_rshift(__v, cshift); \ - end -= cshift; \ - this_unit--; \ - } \ - for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \ - __ptr[this_unit] = (type) __v; \ - __v = _bt_piecewise_rshift(__v, ts); \ - end -= ts; \ - } \ - if (__start % ts) { \ - mask = (~(type) 0) << (ts - (__start % ts)); \ - cmask = (type) __v; \ - cmask &= ~mask; \ - __ptr[this_unit] &= mask; \ - __ptr[this_unit] |= cmask; \ - } else \ - __ptr[this_unit] = (type) __v; \ -} while (0) - -/* - * bt_bitfield_write - write integer to a bitfield in native endianness - * bt_bitfield_write_le - write integer to a bitfield in little endian - * bt_bitfield_write_be - write integer to a bitfield in big endian - */ - -#if (BYTE_ORDER == LITTLE_ENDIAN) - -#define bt_bitfield_write(ptr, type, _start, _length, _v) \ - _bt_bitfield_write_le(ptr, type, _start, _length, _v) - -#define bt_bitfield_write_le(ptr, type, _start, _length, _v) \ - _bt_bitfield_write_le(ptr, type, _start, _length, _v) - -#define bt_bitfield_write_be(ptr, type, _start, _length, _v) \ - _bt_bitfield_write_be(ptr, unsigned char, _start, _length, _v) - -#elif (BYTE_ORDER == BIG_ENDIAN) - -#define bt_bitfield_write(ptr, type, _start, _length, _v) \ - _bt_bitfield_write_be(ptr, type, _start, _length, _v) - -#define bt_bitfield_write_le(ptr, type, _start, _length, _v) \ - _bt_bitfield_write_le(ptr, unsigned char, _start, _length, _v) - -#define bt_bitfield_write_be(ptr, type, _start, _length, _v) \ - _bt_bitfield_write_be(ptr, type, _start, _length, _v) - -#else /* (BYTE_ORDER == PDP_ENDIAN) */ - -#error "Byte order not supported" - -#endif - -#define _bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) \ -do { \ - typeof(*(_vptr)) *__vptr = (_vptr); \ - typeof(*__vptr) __v; \ - type *__ptr = (void *) (_ptr); \ - unsigned long __start = (_start), __length = (_length); \ - type mask, cmask; \ - unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ - unsigned long start_unit, end_unit, this_unit; \ - unsigned long end, cshift; /* cshift is "complement shift" */ \ - \ - if (!__length) { \ - *__vptr = 0; \ - break; \ - } \ - \ - end = __start + __length; \ - start_unit = __start / ts; \ - end_unit = (end + (ts - 1)) / ts; \ - \ - this_unit = end_unit - 1; \ - if (_bt_is_signed_type(typeof(__v)) \ - && (__ptr[this_unit] & ((type) 1 << ((end % ts ? : ts) - 1)))) \ - __v = ~(typeof(__v)) 0; \ - else \ - __v = 0; \ - if (start_unit == end_unit - 1) { \ - cmask = __ptr[this_unit]; \ - cmask >>= (__start % ts); \ - if ((end - __start) % ts) { \ - mask = ~((~(type) 0) << (end - __start)); \ - cmask &= mask; \ - } \ - __v = _bt_piecewise_lshift(__v, end - __start); \ - __v |= _bt_unsigned_cast(typeof(__v), cmask); \ - *__vptr = __v; \ - break; \ - } \ - if (end % ts) { \ - cshift = end % ts; \ - mask = ~((~(type) 0) << cshift); \ - cmask = __ptr[this_unit]; \ - cmask &= mask; \ - __v = _bt_piecewise_lshift(__v, cshift); \ - __v |= _bt_unsigned_cast(typeof(__v), cmask); \ - end -= cshift; \ - this_unit--; \ - } \ - for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \ - __v = _bt_piecewise_lshift(__v, ts); \ - __v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\ - end -= ts; \ - } \ - if (__start % ts) { \ - mask = ~((~(type) 0) << (ts - (__start % ts))); \ - cmask = __ptr[this_unit]; \ - cmask >>= (__start % ts); \ - cmask &= mask; \ - __v = _bt_piecewise_lshift(__v, ts - (__start % ts)); \ - __v |= _bt_unsigned_cast(typeof(__v), cmask); \ - } else { \ - __v = _bt_piecewise_lshift(__v, ts); \ - __v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\ - } \ - *__vptr = __v; \ -} while (0) - -#define _bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) \ -do { \ - typeof(*(_vptr)) *__vptr = (_vptr); \ - typeof(*__vptr) __v; \ - type *__ptr = (void *) (_ptr); \ - unsigned long __start = (_start), __length = (_length); \ - type mask, cmask; \ - unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ - unsigned long start_unit, end_unit, this_unit; \ - unsigned long end, cshift; /* cshift is "complement shift" */ \ - \ - if (!__length) { \ - *__vptr = 0; \ - break; \ - } \ - \ - end = __start + __length; \ - start_unit = __start / ts; \ - end_unit = (end + (ts - 1)) / ts; \ - \ - this_unit = start_unit; \ - if (_bt_is_signed_type(typeof(__v)) \ - && (__ptr[this_unit] & ((type) 1 << (ts - (__start % ts) - 1)))) \ - __v = ~(typeof(__v)) 0; \ - else \ - __v = 0; \ - if (start_unit == end_unit - 1) { \ - cmask = __ptr[this_unit]; \ - cmask >>= (ts - (end % ts)) % ts; \ - if ((end - __start) % ts) { \ - mask = ~((~(type) 0) << (end - __start)); \ - cmask &= mask; \ - } \ - __v = _bt_piecewise_lshift(__v, end - __start); \ - __v |= _bt_unsigned_cast(typeof(__v), cmask); \ - *__vptr = __v; \ - break; \ - } \ - if (__start % ts) { \ - cshift = __start % ts; \ - mask = ~((~(type) 0) << (ts - cshift)); \ - cmask = __ptr[this_unit]; \ - cmask &= mask; \ - __v = _bt_piecewise_lshift(__v, ts - cshift); \ - __v |= _bt_unsigned_cast(typeof(__v), cmask); \ - __start += ts - cshift; \ - this_unit++; \ - } \ - for (; this_unit < end_unit - 1; this_unit++) { \ - __v = _bt_piecewise_lshift(__v, ts); \ - __v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\ - __start += ts; \ - } \ - if (end % ts) { \ - mask = ~((~(type) 0) << (end % ts)); \ - cmask = __ptr[this_unit]; \ - cmask >>= ts - (end % ts); \ - cmask &= mask; \ - __v = _bt_piecewise_lshift(__v, end % ts); \ - __v |= _bt_unsigned_cast(typeof(__v), cmask); \ - } else { \ - __v = _bt_piecewise_lshift(__v, ts); \ - __v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\ - } \ - *__vptr = __v; \ -} while (0) - -/* - * bt_bitfield_read - read integer from a bitfield in native endianness - * bt_bitfield_read_le - read integer from a bitfield in little endian - * bt_bitfield_read_be - read integer from a bitfield in big endian - */ - -#if (BYTE_ORDER == LITTLE_ENDIAN) - -#define bt_bitfield_read(_ptr, type, _start, _length, _vptr) \ - _bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) - -#define bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) \ - _bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) - -#define bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) \ - _bt_bitfield_read_be(_ptr, unsigned char, _start, _length, _vptr) - -#elif (BYTE_ORDER == BIG_ENDIAN) - -#define bt_bitfield_read(_ptr, type, _start, _length, _vptr) \ - _bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) - -#define bt_bitfield_read_le(_ptr, type, _start, _length, _vptr) \ - _bt_bitfield_read_le(_ptr, unsigned char, _start, _length, _vptr) - -#define bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) \ - _bt_bitfield_read_be(_ptr, type, _start, _length, _vptr) - -#else /* (BYTE_ORDER == PDP_ENDIAN) */ - -#error "Byte order not supported" - -#endif - -#endif /* _BABELTRACE_BITFIELD_H */ diff --git a/include/babeltrace/compat/dirent-internal.h b/include/babeltrace/compat/dirent-internal.h new file mode 100644 index 00000000..5373c667 --- /dev/null +++ b/include/babeltrace/compat/dirent-internal.h @@ -0,0 +1,49 @@ +#ifndef _BABELTRACE_COMPAT_DIRENT_H +#define _BABELTRACE_COMPAT_DIRENT_H + +/* + * babeltrace/compat/dirent.h + * + * Copyright (C) 2015 Michael Jeanson + * + * 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. + */ + +#include + +#ifdef HAVE_DIRFD +static inline +int bt_dirfd(DIR *dir) { + return dirfd(dir); +} +#else +# ifndef __XOPEN_OR_POSIX +static inline +int bt_dirfd(DIR *dir) { + return dir->dd_fd; +} +# else +static inline +int bt_dirfd(DIR *dir) { + return dir->d_fd; +} +# endif +#endif + +#endif /* _BABELTRACE_COMPAT_DIRENT_H */ diff --git a/include/babeltrace/compat/dirent.h b/include/babeltrace/compat/dirent.h deleted file mode 100644 index 5373c667..00000000 --- a/include/babeltrace/compat/dirent.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_DIRENT_H -#define _BABELTRACE_COMPAT_DIRENT_H - -/* - * babeltrace/compat/dirent.h - * - * Copyright (C) 2015 Michael Jeanson - * - * 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. - */ - -#include - -#ifdef HAVE_DIRFD -static inline -int bt_dirfd(DIR *dir) { - return dirfd(dir); -} -#else -# ifndef __XOPEN_OR_POSIX -static inline -int bt_dirfd(DIR *dir) { - return dir->dd_fd; -} -# else -static inline -int bt_dirfd(DIR *dir) { - return dir->d_fd; -} -# endif -#endif - -#endif /* _BABELTRACE_COMPAT_DIRENT_H */ diff --git a/include/babeltrace/compat/fcntl-internal.h b/include/babeltrace/compat/fcntl-internal.h new file mode 100644 index 00000000..47e5effc --- /dev/null +++ b/include/babeltrace/compat/fcntl-internal.h @@ -0,0 +1,181 @@ +#ifndef _BABELTRACE_COMPAT_FCNTL_H +#define _BABELTRACE_COMPAT_FCNTL_H + +/* + * babeltrace/compat/fcntl.h + * + * Copyright 2015 (c) - Jérémie Galarneau + * + * fcntl compatibility layer. + * + * 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. + */ + +#ifdef BABELTRACE_HAVE_POSIX_FALLOCATE + +#include + +static inline +int bt_posix_fallocate(int fd, off_t offset, off_t len) +{ + return posix_fallocate(fd, offset, len); +} + +#else /* #ifdef BABELTRACE_HAVE_POSIX_FALLOCATE */ + +#include +#include +#include + +#define BABELTRACE_FALLOCATE_BUFLEN 256 + +#ifndef min_t +#define min_t(type, a, b) \ + ((type) (a) < (type) (b) ? (type) (a) : (type) (b)) +#endif + +static inline +int bt_posix_fallocate(int fd, off_t offset, off_t len) +{ + int ret = 0; + ssize_t copy_len; + char buf[BABELTRACE_FALLOCATE_BUFLEN]; + off_t i, file_pos, orig_end_offset, range_end; + + if (offset < 0 || len < 0) { + ret = EINVAL; + goto end; + } + + range_end = offset + len; + if (range_end < 0) { + ret = EFBIG; + goto end; + } + + file_pos = lseek(fd, 0, SEEK_CUR); + if (file_pos < 0) { + ret = errno; + goto end; + } + + orig_end_offset = lseek(fd, 0, SEEK_END); + if (orig_end_offset < 0) { + ret = errno; + goto end; + } + + /* Seek back to original position. */ + ret = lseek(fd, file_pos, SEEK_SET); + if (ret) { + ret = errno; + goto end; + } + + /* + * The file may not need to grow, but we want to ensure the + * space has actually been reserved by the file system. First, copy + * the "existing" region of the file, then grow the file if needed. + */ + for (i = file_pos; i < min_t(off_t, range_end, orig_end_offset); + i += copy_len) { + ssize_t copy_ret; + + copy_len = min_t(size_t, BABELTRACE_FALLOCATE_BUFLEN, + min_t(off_t, range_end - i, + orig_end_offset - i)); + copy_ret = pread(fd, &buf, copy_len, i); + if (copy_ret < copy_len) { + /* + * The caller must handle any EINTR. + * POSIX_FALLOCATE(3) does not mention EINTR. + * However, glibc does forward to fallocate() + * directly on Linux, which may be interrupted. + */ + ret = errno; + goto end; + } + + copy_ret = pwrite(fd, &buf, copy_len, i); + if (copy_ret < copy_len) { + /* Same caveat as noted at pread() */ + ret = errno; + goto end; + } + } + + /* Grow file, as necessary. */ + memset(&buf, 0, BABELTRACE_FALLOCATE_BUFLEN); + for (i = orig_end_offset; i < range_end; i += copy_len) { + ssize_t write_ret; + + copy_len = min_t(size_t, BABELTRACE_FALLOCATE_BUFLEN, + range_end - i); + write_ret = pwrite(fd, &buf, copy_len, i); + if (write_ret < copy_len) { + ret = errno; + goto end; + } + } +end: + return ret; +} +#endif /* #else #ifdef BABELTRACE_HAVE_POSIX_FALLOCATE */ + + +#ifdef BABELTRACE_HAVE_FACCESSAT + +#include +#include + +static inline +int bt_faccessat(int dirfd, const char *dirname, + const char *pathname, int mode, int flags) +{ + return faccessat(dirfd, pathname, mode, flags); +} + +#else /* #ifdef BABELTRACE_HAVE_FACCESSAT */ + +#include +#include + +static inline +int bt_faccessat(int dirfd, const char *dirname, + const char *pathname, int mode, int flags) +{ + char cpath[PATH_MAX]; + + if (flags != 0) { + errno = EINVAL; + return -1; + } + /* Includes middle / and final \0. */ + if (strlen(dirname) + strlen(pathname) + 2 > PATH_MAX) { + return -1; + } + strcpy(cpath, dirname); + strcat(cpath, "/"); + strcat(cpath, pathname); + return access(cpath, mode); +} + +#endif /* #else #ifdef BABELTRACE_HAVE_FACCESSAT */ + +#endif /* _BABELTRACE_COMPAT_FCNTL_H */ diff --git a/include/babeltrace/compat/fcntl.h b/include/babeltrace/compat/fcntl.h deleted file mode 100644 index 47e5effc..00000000 --- a/include/babeltrace/compat/fcntl.h +++ /dev/null @@ -1,181 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_FCNTL_H -#define _BABELTRACE_COMPAT_FCNTL_H - -/* - * babeltrace/compat/fcntl.h - * - * Copyright 2015 (c) - Jérémie Galarneau - * - * fcntl compatibility layer. - * - * 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. - */ - -#ifdef BABELTRACE_HAVE_POSIX_FALLOCATE - -#include - -static inline -int bt_posix_fallocate(int fd, off_t offset, off_t len) -{ - return posix_fallocate(fd, offset, len); -} - -#else /* #ifdef BABELTRACE_HAVE_POSIX_FALLOCATE */ - -#include -#include -#include - -#define BABELTRACE_FALLOCATE_BUFLEN 256 - -#ifndef min_t -#define min_t(type, a, b) \ - ((type) (a) < (type) (b) ? (type) (a) : (type) (b)) -#endif - -static inline -int bt_posix_fallocate(int fd, off_t offset, off_t len) -{ - int ret = 0; - ssize_t copy_len; - char buf[BABELTRACE_FALLOCATE_BUFLEN]; - off_t i, file_pos, orig_end_offset, range_end; - - if (offset < 0 || len < 0) { - ret = EINVAL; - goto end; - } - - range_end = offset + len; - if (range_end < 0) { - ret = EFBIG; - goto end; - } - - file_pos = lseek(fd, 0, SEEK_CUR); - if (file_pos < 0) { - ret = errno; - goto end; - } - - orig_end_offset = lseek(fd, 0, SEEK_END); - if (orig_end_offset < 0) { - ret = errno; - goto end; - } - - /* Seek back to original position. */ - ret = lseek(fd, file_pos, SEEK_SET); - if (ret) { - ret = errno; - goto end; - } - - /* - * The file may not need to grow, but we want to ensure the - * space has actually been reserved by the file system. First, copy - * the "existing" region of the file, then grow the file if needed. - */ - for (i = file_pos; i < min_t(off_t, range_end, orig_end_offset); - i += copy_len) { - ssize_t copy_ret; - - copy_len = min_t(size_t, BABELTRACE_FALLOCATE_BUFLEN, - min_t(off_t, range_end - i, - orig_end_offset - i)); - copy_ret = pread(fd, &buf, copy_len, i); - if (copy_ret < copy_len) { - /* - * The caller must handle any EINTR. - * POSIX_FALLOCATE(3) does not mention EINTR. - * However, glibc does forward to fallocate() - * directly on Linux, which may be interrupted. - */ - ret = errno; - goto end; - } - - copy_ret = pwrite(fd, &buf, copy_len, i); - if (copy_ret < copy_len) { - /* Same caveat as noted at pread() */ - ret = errno; - goto end; - } - } - - /* Grow file, as necessary. */ - memset(&buf, 0, BABELTRACE_FALLOCATE_BUFLEN); - for (i = orig_end_offset; i < range_end; i += copy_len) { - ssize_t write_ret; - - copy_len = min_t(size_t, BABELTRACE_FALLOCATE_BUFLEN, - range_end - i); - write_ret = pwrite(fd, &buf, copy_len, i); - if (write_ret < copy_len) { - ret = errno; - goto end; - } - } -end: - return ret; -} -#endif /* #else #ifdef BABELTRACE_HAVE_POSIX_FALLOCATE */ - - -#ifdef BABELTRACE_HAVE_FACCESSAT - -#include -#include - -static inline -int bt_faccessat(int dirfd, const char *dirname, - const char *pathname, int mode, int flags) -{ - return faccessat(dirfd, pathname, mode, flags); -} - -#else /* #ifdef BABELTRACE_HAVE_FACCESSAT */ - -#include -#include - -static inline -int bt_faccessat(int dirfd, const char *dirname, - const char *pathname, int mode, int flags) -{ - char cpath[PATH_MAX]; - - if (flags != 0) { - errno = EINVAL; - return -1; - } - /* Includes middle / and final \0. */ - if (strlen(dirname) + strlen(pathname) + 2 > PATH_MAX) { - return -1; - } - strcpy(cpath, dirname); - strcat(cpath, "/"); - strcat(cpath, pathname); - return access(cpath, mode); -} - -#endif /* #else #ifdef BABELTRACE_HAVE_FACCESSAT */ - -#endif /* _BABELTRACE_COMPAT_FCNTL_H */ diff --git a/include/babeltrace/compat/glib-internal.h b/include/babeltrace/compat/glib-internal.h new file mode 100644 index 00000000..dd03b19c --- /dev/null +++ b/include/babeltrace/compat/glib-internal.h @@ -0,0 +1,83 @@ +#ifndef _BABELTRACE_COMPAT_GLIB_H +#define _BABELTRACE_COMPAT_GLIB_H + +/* + * babeltrace/compat/glib.h + * + * Copyright (C) 2015 Michael Jeanson + * + * 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. + */ + +#include + +#if GLIB_CHECK_VERSION(2,31,8) + +static inline gboolean +bt_g_hash_table_contains(GHashTable *hash_table, gconstpointer key) +{ + return g_hash_table_contains(hash_table, key); +} + +#else + +static inline gboolean +bt_g_hash_table_contains(GHashTable *hash_table, gconstpointer key) +{ + const char *value; + + value = g_hash_table_lookup(hash_table, key); + if (value == NULL) { + return FALSE; + } + + return TRUE; +} + +#endif + + +#if GLIB_CHECK_VERSION(2,29,16) + +static inline GPtrArray * +bt_g_ptr_array_new_full(guint reserved_size, + GDestroyNotify element_free_func) +{ + return g_ptr_array_new_full(reserved_size, element_free_func); +} + +#else + +static inline GPtrArray * +bt_g_ptr_array_new_full(guint reserved_size, + GDestroyNotify element_free_func) +{ + GPtrArray *array; + + array = g_ptr_array_sized_new(reserved_size); + if (!array) { + goto end; + } + g_ptr_array_set_free_func(array, element_free_func); +end: + return array; +} +#endif + +#endif /* _BABELTRACE_COMPAT_GLIB_H */ diff --git a/include/babeltrace/compat/glib.h b/include/babeltrace/compat/glib.h deleted file mode 100644 index dd03b19c..00000000 --- a/include/babeltrace/compat/glib.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_GLIB_H -#define _BABELTRACE_COMPAT_GLIB_H - -/* - * babeltrace/compat/glib.h - * - * Copyright (C) 2015 Michael Jeanson - * - * 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. - */ - -#include - -#if GLIB_CHECK_VERSION(2,31,8) - -static inline gboolean -bt_g_hash_table_contains(GHashTable *hash_table, gconstpointer key) -{ - return g_hash_table_contains(hash_table, key); -} - -#else - -static inline gboolean -bt_g_hash_table_contains(GHashTable *hash_table, gconstpointer key) -{ - const char *value; - - value = g_hash_table_lookup(hash_table, key); - if (value == NULL) { - return FALSE; - } - - return TRUE; -} - -#endif - - -#if GLIB_CHECK_VERSION(2,29,16) - -static inline GPtrArray * -bt_g_ptr_array_new_full(guint reserved_size, - GDestroyNotify element_free_func) -{ - return g_ptr_array_new_full(reserved_size, element_free_func); -} - -#else - -static inline GPtrArray * -bt_g_ptr_array_new_full(guint reserved_size, - GDestroyNotify element_free_func) -{ - GPtrArray *array; - - array = g_ptr_array_sized_new(reserved_size); - if (!array) { - goto end; - } - g_ptr_array_set_free_func(array, element_free_func); -end: - return array; -} -#endif - -#endif /* _BABELTRACE_COMPAT_GLIB_H */ diff --git a/include/babeltrace/compat/limits-internal.h b/include/babeltrace/compat/limits-internal.h new file mode 100644 index 00000000..b2761837 --- /dev/null +++ b/include/babeltrace/compat/limits-internal.h @@ -0,0 +1,46 @@ +#ifndef _BABELTRACE_LIMITS_H +#define _BABELTRACE_LIMITS_H + +/* + * Copyright (C) 2014 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: + * + * 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. + */ + +#include + +#ifdef __linux__ + +#define BABELTRACE_HOST_NAME_MAX HOST_NAME_MAX + +#elif defined(__FreeBSD__) + +#define BABELTRACE_HOST_NAME_MAX MAXHOSTNAMELEN + +#elif defined(_POSIX_HOST_NAME_MAX) + +#define BABELTRACE_HOST_NAME_MAX _POSIX_HOST_NAME_MAX + +#else + +#define BABELTRACE_HOST_NAME_MAX 256 + +#endif /* __linux__, __FreeBSD__, _POSIX_HOST_NAME_MAX */ + +#endif /* _BABELTRACE_LIMITS_H */ diff --git a/include/babeltrace/compat/limits.h b/include/babeltrace/compat/limits.h deleted file mode 100644 index b2761837..00000000 --- a/include/babeltrace/compat/limits.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _BABELTRACE_LIMITS_H -#define _BABELTRACE_LIMITS_H - -/* - * Copyright (C) 2014 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: - * - * 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. - */ - -#include - -#ifdef __linux__ - -#define BABELTRACE_HOST_NAME_MAX HOST_NAME_MAX - -#elif defined(__FreeBSD__) - -#define BABELTRACE_HOST_NAME_MAX MAXHOSTNAMELEN - -#elif defined(_POSIX_HOST_NAME_MAX) - -#define BABELTRACE_HOST_NAME_MAX _POSIX_HOST_NAME_MAX - -#else - -#define BABELTRACE_HOST_NAME_MAX 256 - -#endif /* __linux__, __FreeBSD__, _POSIX_HOST_NAME_MAX */ - -#endif /* _BABELTRACE_LIMITS_H */ diff --git a/include/babeltrace/compat/memstream-internal.h b/include/babeltrace/compat/memstream-internal.h new file mode 100644 index 00000000..38b6e3fa --- /dev/null +++ b/include/babeltrace/compat/memstream-internal.h @@ -0,0 +1,233 @@ +#ifndef _BABELTRACE_FORMAT_CTF_MEMSTREAM_H +#define _BABELTRACE_FORMAT_CTF_MEMSTREAM_H + +/* + * format/ctf/memstream.h + * + * Copyright 2012 (c) - Mathieu Desnoyers + * + * memstream compatibility layer. + * + * 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. + */ + +#ifdef BABELTRACE_HAVE_FMEMOPEN +#include + +static inline +FILE *bt_fmemopen(void *buf, size_t size, const char *mode) +{ + return fmemopen(buf, size, mode); +} + +#else /* BABELTRACE_HAVE_FMEMOPEN */ + +#include +#include + +/* + * Fallback for systems which don't have fmemopen. Copy buffer to a + * temporary file, and use that file as FILE * input. + */ +static inline +FILE *bt_fmemopen(void *buf, size_t size, const char *mode) +{ + char tmpname[PATH_MAX]; + size_t len; + FILE *fp; + int ret; + + /* + * Support reading only. + */ + if (strcmp(mode, "rb") != 0) { + return NULL; + } + strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX); + ret = mkstemp(tmpname); + if (ret < 0) { + return NULL; + } + /* + * We need to write to the file. + */ + fp = fdopen(ret, "w+"); + if (!fp) { + goto error_unlink; + } + /* Copy the entire buffer to the file */ + len = fwrite(buf, sizeof(char), size, fp); + if (len != size) { + goto error_close; + } + ret = fseek(fp, 0L, SEEK_SET); + if (ret < 0) { + perror("fseek"); + goto error_close; + } + /* We keep the handle open, but can unlink the file on the VFS. */ + ret = unlink(tmpname); + if (ret < 0) { + perror("unlink"); + } + return fp; + +error_close: + ret = fclose(fp); + if (ret < 0) { + perror("close"); + } +error_unlink: + ret = unlink(tmpname); + if (ret < 0) { + perror("unlink"); + } + return NULL; +} + +#endif /* BABELTRACE_HAVE_FMEMOPEN */ + +#ifdef BABELTRACE_HAVE_OPEN_MEMSTREAM + +#include + +static inline +FILE *bt_open_memstream(char **ptr, size_t *sizeloc) +{ + return open_memstream(ptr, sizeloc); +} + +static inline +int bt_close_memstream(char **buf, size_t *size, FILE *fp) +{ + return fclose(fp); +} + +#else /* BABELTRACE_HAVE_OPEN_MEMSTREAM */ + +#include +#include + +/* + * Fallback for systems which don't have open_memstream. Create FILE * + * with bt_open_memstream, but require call to + * bt_close_memstream to flush all data written to the FILE * + * into the buffer (which we allocate). + */ +static inline +FILE *bt_open_memstream(char **ptr, size_t *sizeloc) +{ + char tmpname[PATH_MAX]; + int ret; + FILE *fp; + + strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX); + ret = mkstemp(tmpname); + if (ret < 0) { + return NULL; + } + fp = fdopen(ret, "w+"); + if (!fp) { + goto error_unlink; + } + /* + * babeltrace_flush_memstream will update the buffer content + * with read from fp. No need to keep the file around, just the + * handle. + */ + ret = unlink(tmpname); + if (ret < 0) { + perror("unlink"); + } + return fp; + +error_unlink: + ret = unlink(tmpname); + if (ret < 0) { + perror("unlink"); + } + return NULL; +} + +/* Get file size, allocate buffer, copy. */ +static inline +int bt_close_memstream(char **buf, size_t *size, FILE *fp) +{ + size_t len, n; + long pos; + int ret; + + ret = fflush(fp); + if (ret < 0) { + perror("fflush"); + return ret; + } + ret = fseek(fp, 0L, SEEK_END); + if (ret < 0) { + perror("fseek"); + return ret; + } + pos = ftell(fp); + if (ret < 0) { + perror("ftell"); + return ret; + } + *size = pos; + /* add final \0 */ + *buf = calloc(pos + 1, sizeof(char)); + if (!*buf) { + return -ENOMEM; + } + ret = fseek(fp, 0L, SEEK_SET); + if (ret < 0) { + perror("fseek"); + goto error_free; + } + /* Copy the entire file into the buffer */ + n = 0; + clearerr(fp); + while (!feof(fp) && !ferror(fp) && (*size - n > 0)) { + len = fread(*buf, sizeof(char), *size - n, fp); + n += len; + } + if (n != *size) { + ret = -1; + goto error_close; + } + ret = fclose(fp); + if (ret < 0) { + perror("fclose"); + return ret; + } + return 0; + +error_close: + ret = fclose(fp); + if (ret < 0) { + perror("fclose"); + } +error_free: + free(*buf); + *buf = NULL; + return ret; +} + +#endif /* BABELTRACE_HAVE_OPEN_MEMSTREAM */ + +#endif /* _BABELTRACE_FORMAT_CTF_MEMSTREAM_H */ diff --git a/include/babeltrace/compat/memstream.h b/include/babeltrace/compat/memstream.h deleted file mode 100644 index 38b6e3fa..00000000 --- a/include/babeltrace/compat/memstream.h +++ /dev/null @@ -1,233 +0,0 @@ -#ifndef _BABELTRACE_FORMAT_CTF_MEMSTREAM_H -#define _BABELTRACE_FORMAT_CTF_MEMSTREAM_H - -/* - * format/ctf/memstream.h - * - * Copyright 2012 (c) - Mathieu Desnoyers - * - * memstream compatibility layer. - * - * 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. - */ - -#ifdef BABELTRACE_HAVE_FMEMOPEN -#include - -static inline -FILE *bt_fmemopen(void *buf, size_t size, const char *mode) -{ - return fmemopen(buf, size, mode); -} - -#else /* BABELTRACE_HAVE_FMEMOPEN */ - -#include -#include - -/* - * Fallback for systems which don't have fmemopen. Copy buffer to a - * temporary file, and use that file as FILE * input. - */ -static inline -FILE *bt_fmemopen(void *buf, size_t size, const char *mode) -{ - char tmpname[PATH_MAX]; - size_t len; - FILE *fp; - int ret; - - /* - * Support reading only. - */ - if (strcmp(mode, "rb") != 0) { - return NULL; - } - strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX); - ret = mkstemp(tmpname); - if (ret < 0) { - return NULL; - } - /* - * We need to write to the file. - */ - fp = fdopen(ret, "w+"); - if (!fp) { - goto error_unlink; - } - /* Copy the entire buffer to the file */ - len = fwrite(buf, sizeof(char), size, fp); - if (len != size) { - goto error_close; - } - ret = fseek(fp, 0L, SEEK_SET); - if (ret < 0) { - perror("fseek"); - goto error_close; - } - /* We keep the handle open, but can unlink the file on the VFS. */ - ret = unlink(tmpname); - if (ret < 0) { - perror("unlink"); - } - return fp; - -error_close: - ret = fclose(fp); - if (ret < 0) { - perror("close"); - } -error_unlink: - ret = unlink(tmpname); - if (ret < 0) { - perror("unlink"); - } - return NULL; -} - -#endif /* BABELTRACE_HAVE_FMEMOPEN */ - -#ifdef BABELTRACE_HAVE_OPEN_MEMSTREAM - -#include - -static inline -FILE *bt_open_memstream(char **ptr, size_t *sizeloc) -{ - return open_memstream(ptr, sizeloc); -} - -static inline -int bt_close_memstream(char **buf, size_t *size, FILE *fp) -{ - return fclose(fp); -} - -#else /* BABELTRACE_HAVE_OPEN_MEMSTREAM */ - -#include -#include - -/* - * Fallback for systems which don't have open_memstream. Create FILE * - * with bt_open_memstream, but require call to - * bt_close_memstream to flush all data written to the FILE * - * into the buffer (which we allocate). - */ -static inline -FILE *bt_open_memstream(char **ptr, size_t *sizeloc) -{ - char tmpname[PATH_MAX]; - int ret; - FILE *fp; - - strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX); - ret = mkstemp(tmpname); - if (ret < 0) { - return NULL; - } - fp = fdopen(ret, "w+"); - if (!fp) { - goto error_unlink; - } - /* - * babeltrace_flush_memstream will update the buffer content - * with read from fp. No need to keep the file around, just the - * handle. - */ - ret = unlink(tmpname); - if (ret < 0) { - perror("unlink"); - } - return fp; - -error_unlink: - ret = unlink(tmpname); - if (ret < 0) { - perror("unlink"); - } - return NULL; -} - -/* Get file size, allocate buffer, copy. */ -static inline -int bt_close_memstream(char **buf, size_t *size, FILE *fp) -{ - size_t len, n; - long pos; - int ret; - - ret = fflush(fp); - if (ret < 0) { - perror("fflush"); - return ret; - } - ret = fseek(fp, 0L, SEEK_END); - if (ret < 0) { - perror("fseek"); - return ret; - } - pos = ftell(fp); - if (ret < 0) { - perror("ftell"); - return ret; - } - *size = pos; - /* add final \0 */ - *buf = calloc(pos + 1, sizeof(char)); - if (!*buf) { - return -ENOMEM; - } - ret = fseek(fp, 0L, SEEK_SET); - if (ret < 0) { - perror("fseek"); - goto error_free; - } - /* Copy the entire file into the buffer */ - n = 0; - clearerr(fp); - while (!feof(fp) && !ferror(fp) && (*size - n > 0)) { - len = fread(*buf, sizeof(char), *size - n, fp); - n += len; - } - if (n != *size) { - ret = -1; - goto error_close; - } - ret = fclose(fp); - if (ret < 0) { - perror("fclose"); - return ret; - } - return 0; - -error_close: - ret = fclose(fp); - if (ret < 0) { - perror("fclose"); - } -error_free: - free(*buf); - *buf = NULL; - return ret; -} - -#endif /* BABELTRACE_HAVE_OPEN_MEMSTREAM */ - -#endif /* _BABELTRACE_FORMAT_CTF_MEMSTREAM_H */ diff --git a/include/babeltrace/compat/mman-internal.h b/include/babeltrace/compat/mman-internal.h new file mode 100644 index 00000000..061e244b --- /dev/null +++ b/include/babeltrace/compat/mman-internal.h @@ -0,0 +1,36 @@ +#ifndef _BABELTRACE_COMPAT_MMAN_H +#define _BABELTRACE_COMPAT_MMAN_H + +/* + * babeltrace/compat/mman.h + * + * Copyright (C) 2015 Michael Jeanson + * + * 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. + */ + +#include + +#ifndef MAP_ANONYMOUS +# ifdef MAP_ANON +# define MAP_ANONYMOUS MAP_ANON +# endif +#endif + +#endif /* _BABELTRACE_COMPAT_MMAN_H */ diff --git a/include/babeltrace/compat/mman.h b/include/babeltrace/compat/mman.h deleted file mode 100644 index 061e244b..00000000 --- a/include/babeltrace/compat/mman.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_MMAN_H -#define _BABELTRACE_COMPAT_MMAN_H - -/* - * babeltrace/compat/mman.h - * - * Copyright (C) 2015 Michael Jeanson - * - * 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. - */ - -#include - -#ifndef MAP_ANONYMOUS -# ifdef MAP_ANON -# define MAP_ANONYMOUS MAP_ANON -# endif -#endif - -#endif /* _BABELTRACE_COMPAT_MMAN_H */ diff --git a/include/babeltrace/compat/send-internal.h b/include/babeltrace/compat/send-internal.h new file mode 100644 index 00000000..39986945 --- /dev/null +++ b/include/babeltrace/compat/send-internal.h @@ -0,0 +1,117 @@ +#ifndef _BABELTRACE_COMPAT_SEND_H +#define _BABELTRACE_COMPAT_SEND_H + +/* + * babeltrace/compat/send.h + * + * Copyright (C) 2015 Michael Jeanson + * 2015 Mathieu Desnoyers + * + * 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. + */ + +/* + * This wrapper is used on platforms that have no way of ignoring SIGPIPE + * during a send(). + */ + +#ifndef MSG_NOSIGNAL +# ifdef SO_NOSIGPIPE +# define MSG_NOSIGNAL SO_NOSIGPIPE +# endif +#endif + +#if defined(MSG_NOSIGNAL) +static inline +ssize_t bt_send_nosigpipe(int fd, const void *buffer, size_t size) +{ + return send(fd, buffer, size, MSG_NOSIGNAL); +} +#else + +#include + +static inline +ssize_t bt_send_nosigpipe(int fd, const void *buffer, size_t size) +{ + ssize_t sent; + int saved_err; + sigset_t sigpipe_set, pending_set, old_set; + int sigpipe_was_pending; + + /* + * Discard the SIGPIPE from send(), not disturbing any SIGPIPE + * that might be already pending. If a bogus SIGPIPE is sent to + * the entire process concurrently by a malicious user, it may + * be simply discarded. + */ + if (sigemptyset(&pending_set)) { + return -1; + } + /* + * sigpending returns the mask of signals that are _both_ + * blocked for the thread _and_ pending for either the thread or + * the entire process. + */ + if (sigpending(&pending_set)) { + return -1; + } + sigpipe_was_pending = sigismember(&pending_set, SIGPIPE); + /* + * If sigpipe was pending, it means it was already blocked, so + * no need to block it. + */ + if (!sigpipe_was_pending) { + if (sigemptyset(&sigpipe_set)) { + return -1; + } + if (sigaddset(&sigpipe_set, SIGPIPE)) { + return -1; + } + if (pthread_sigmask(SIG_BLOCK, &sigpipe_set, &old_set)) { + return -1; + } + } + + /* Send and save errno. */ + sent = send(fd, buffer, size, 0); + saved_err = errno; + + if (sent == -1 && errno == EPIPE && !sigpipe_was_pending) { + struct timespec timeout = { 0, 0 }; + int ret; + + do { + ret = sigtimedwait(&sigpipe_set, NULL, + &timeout); + } while (ret == -1 && errno == EINTR); + } + if (!sigpipe_was_pending) { + if (pthread_sigmask(SIG_SETMASK, &old_set, NULL)) { + return -1; + } + } + /* Restore send() errno */ + errno = saved_err; + + return sent; +} +#endif + +#endif /* _BABELTRACE_COMPAT_SEND_H */ diff --git a/include/babeltrace/compat/send.h b/include/babeltrace/compat/send.h deleted file mode 100644 index 39986945..00000000 --- a/include/babeltrace/compat/send.h +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_SEND_H -#define _BABELTRACE_COMPAT_SEND_H - -/* - * babeltrace/compat/send.h - * - * Copyright (C) 2015 Michael Jeanson - * 2015 Mathieu Desnoyers - * - * 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. - */ - -/* - * This wrapper is used on platforms that have no way of ignoring SIGPIPE - * during a send(). - */ - -#ifndef MSG_NOSIGNAL -# ifdef SO_NOSIGPIPE -# define MSG_NOSIGNAL SO_NOSIGPIPE -# endif -#endif - -#if defined(MSG_NOSIGNAL) -static inline -ssize_t bt_send_nosigpipe(int fd, const void *buffer, size_t size) -{ - return send(fd, buffer, size, MSG_NOSIGNAL); -} -#else - -#include - -static inline -ssize_t bt_send_nosigpipe(int fd, const void *buffer, size_t size) -{ - ssize_t sent; - int saved_err; - sigset_t sigpipe_set, pending_set, old_set; - int sigpipe_was_pending; - - /* - * Discard the SIGPIPE from send(), not disturbing any SIGPIPE - * that might be already pending. If a bogus SIGPIPE is sent to - * the entire process concurrently by a malicious user, it may - * be simply discarded. - */ - if (sigemptyset(&pending_set)) { - return -1; - } - /* - * sigpending returns the mask of signals that are _both_ - * blocked for the thread _and_ pending for either the thread or - * the entire process. - */ - if (sigpending(&pending_set)) { - return -1; - } - sigpipe_was_pending = sigismember(&pending_set, SIGPIPE); - /* - * If sigpipe was pending, it means it was already blocked, so - * no need to block it. - */ - if (!sigpipe_was_pending) { - if (sigemptyset(&sigpipe_set)) { - return -1; - } - if (sigaddset(&sigpipe_set, SIGPIPE)) { - return -1; - } - if (pthread_sigmask(SIG_BLOCK, &sigpipe_set, &old_set)) { - return -1; - } - } - - /* Send and save errno. */ - sent = send(fd, buffer, size, 0); - saved_err = errno; - - if (sent == -1 && errno == EPIPE && !sigpipe_was_pending) { - struct timespec timeout = { 0, 0 }; - int ret; - - do { - ret = sigtimedwait(&sigpipe_set, NULL, - &timeout); - } while (ret == -1 && errno == EINTR); - } - if (!sigpipe_was_pending) { - if (pthread_sigmask(SIG_SETMASK, &old_set, NULL)) { - return -1; - } - } - /* Restore send() errno */ - errno = saved_err; - - return sent; -} -#endif - -#endif /* _BABELTRACE_COMPAT_SEND_H */ diff --git a/include/babeltrace/compat/stdio-internal.h b/include/babeltrace/compat/stdio-internal.h new file mode 100644 index 00000000..41d1df35 --- /dev/null +++ b/include/babeltrace/compat/stdio-internal.h @@ -0,0 +1,126 @@ +#ifndef _BABELTRACE_COMPAT_STDIO_H +#define _BABELTRACE_COMPAT_STDIO_H + +/* + * Copyright (C) 2015 Mathieu Desnoyers + * + * 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. + */ + +#include +#include +#include + +#define BT_GETLINE_MINBUFLEN 64 + +static inline +char * _bt_getline_bufalloc(char **lineptr, size_t *n, size_t linelen) +{ + size_t buflen = *n; + char *buf = *lineptr; + + if (buflen >= linelen && buf != NULL) { + return buf; + } + if (buf == NULL) { + buflen = BT_GETLINE_MINBUFLEN; + } else { + buflen = buflen << 1; + if (buflen < BT_GETLINE_MINBUFLEN) { + buflen = BT_GETLINE_MINBUFLEN; + } + } + /* Check below not strictly needed, extra safety. */ + if (buflen < linelen) { + buflen = linelen; + } + buf = realloc(buf, buflen); + if (!buf) { + errno = ENOMEM; + return NULL; + } + *n = buflen; + *lineptr = buf; + return buf; +} + +/* + * Returns line length (including possible final \n, excluding final + * \0). On end of file, returns -1 with nonzero feof(stream) and errno + * set to 0. On error, returns -1 with errno set. + * + * This interface is similar to the getline(3) man page part of the + * Linux man-pages project, release 3.74. One major difference from the + * Open Group POSIX specification is that this implementation does not + * necessarily set the ferror() flag on error (because it is internal to + * libc). + */ +static inline +ssize_t bt_getline(char **lineptr, size_t *n, FILE *stream) +{ + size_t linelen = 0; + char *buf; + int found_eof = 0; + + if (lineptr == NULL || n == NULL) { + errno = EINVAL; + return -1; + } + for (;;) { + char c; + int ret; + + ret = fgetc(stream); + if (ret == EOF) { + if (ferror(stream)) { + /* ferror() is set, errno set by fgetc(). */ + return -1; + } + assert(feof(stream)); + found_eof = 1; + break; + } + c = (char) ret; + if (linelen == SSIZE_MAX) { + errno = EOVERFLOW; + return -1; + } + buf = _bt_getline_bufalloc(lineptr, n, ++linelen); + if (!buf) { + return -1; + } + buf[linelen - 1] = c; + if (c == '\n') { + break; + } + } + if (!linelen && found_eof) { + /* feof() is set. */ + errno = 0; + return -1; + } + buf = _bt_getline_bufalloc(lineptr, n, ++linelen); + if (!buf) { + return -1; + } + buf[linelen - 1] = '\0'; + return linelen - 1; /* Count don't include final \0. */ +} + +#endif /* _BABELTRACE_COMPAT_STDIO_H */ diff --git a/include/babeltrace/compat/stdio.h b/include/babeltrace/compat/stdio.h deleted file mode 100644 index 41d1df35..00000000 --- a/include/babeltrace/compat/stdio.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_STDIO_H -#define _BABELTRACE_COMPAT_STDIO_H - -/* - * Copyright (C) 2015 Mathieu Desnoyers - * - * 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. - */ - -#include -#include -#include - -#define BT_GETLINE_MINBUFLEN 64 - -static inline -char * _bt_getline_bufalloc(char **lineptr, size_t *n, size_t linelen) -{ - size_t buflen = *n; - char *buf = *lineptr; - - if (buflen >= linelen && buf != NULL) { - return buf; - } - if (buf == NULL) { - buflen = BT_GETLINE_MINBUFLEN; - } else { - buflen = buflen << 1; - if (buflen < BT_GETLINE_MINBUFLEN) { - buflen = BT_GETLINE_MINBUFLEN; - } - } - /* Check below not strictly needed, extra safety. */ - if (buflen < linelen) { - buflen = linelen; - } - buf = realloc(buf, buflen); - if (!buf) { - errno = ENOMEM; - return NULL; - } - *n = buflen; - *lineptr = buf; - return buf; -} - -/* - * Returns line length (including possible final \n, excluding final - * \0). On end of file, returns -1 with nonzero feof(stream) and errno - * set to 0. On error, returns -1 with errno set. - * - * This interface is similar to the getline(3) man page part of the - * Linux man-pages project, release 3.74. One major difference from the - * Open Group POSIX specification is that this implementation does not - * necessarily set the ferror() flag on error (because it is internal to - * libc). - */ -static inline -ssize_t bt_getline(char **lineptr, size_t *n, FILE *stream) -{ - size_t linelen = 0; - char *buf; - int found_eof = 0; - - if (lineptr == NULL || n == NULL) { - errno = EINVAL; - return -1; - } - for (;;) { - char c; - int ret; - - ret = fgetc(stream); - if (ret == EOF) { - if (ferror(stream)) { - /* ferror() is set, errno set by fgetc(). */ - return -1; - } - assert(feof(stream)); - found_eof = 1; - break; - } - c = (char) ret; - if (linelen == SSIZE_MAX) { - errno = EOVERFLOW; - return -1; - } - buf = _bt_getline_bufalloc(lineptr, n, ++linelen); - if (!buf) { - return -1; - } - buf[linelen - 1] = c; - if (c == '\n') { - break; - } - } - if (!linelen && found_eof) { - /* feof() is set. */ - errno = 0; - return -1; - } - buf = _bt_getline_bufalloc(lineptr, n, ++linelen); - if (!buf) { - return -1; - } - buf[linelen - 1] = '\0'; - return linelen - 1; /* Count don't include final \0. */ -} - -#endif /* _BABELTRACE_COMPAT_STDIO_H */ diff --git a/include/babeltrace/compat/stdlib-internal.h b/include/babeltrace/compat/stdlib-internal.h new file mode 100644 index 00000000..be0518f5 --- /dev/null +++ b/include/babeltrace/compat/stdlib-internal.h @@ -0,0 +1,78 @@ +#ifndef _BABELTRACE_COMPAT_STDLIB_H +#define _BABELTRACE_COMPAT_STDLIB_H + +/* + * babeltrace/compat/stdlib.h + * + * Copyright (C) 2015 Michael Jeanson + * + * 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. + */ + +/* + * This compat wrapper can be removed and replaced by g_mkdtemp() when we bump + * the requirement on glib to version 2.30. + */ + +#include +#include +#include + +#ifdef HAVE_MKDTEMP + +static inline +char *bt_mkdtemp(char *template) +{ + return mkdtemp(template); +} + +#elif GLIB_CHECK_VERSION(2,30,0) + +#include +static inline +char *bt_mkdtemp(char *template) +{ + return g_mkdtemp(template); +} + +#else + +static inline +char *bt_mkdtemp(char *template) +{ + char *ret; + + ret = mktemp(template); + if (!ret) { + goto end; + } + + if(mkdir(template, 0700)) { + ret = NULL; + goto end; + } + + ret = template; +end: + return ret; +} + +#endif + +#endif /* _BABELTRACE_COMPAT_STDLIB_H */ diff --git a/include/babeltrace/compat/stdlib.h b/include/babeltrace/compat/stdlib.h deleted file mode 100644 index be0518f5..00000000 --- a/include/babeltrace/compat/stdlib.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_STDLIB_H -#define _BABELTRACE_COMPAT_STDLIB_H - -/* - * babeltrace/compat/stdlib.h - * - * Copyright (C) 2015 Michael Jeanson - * - * 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. - */ - -/* - * This compat wrapper can be removed and replaced by g_mkdtemp() when we bump - * the requirement on glib to version 2.30. - */ - -#include -#include -#include - -#ifdef HAVE_MKDTEMP - -static inline -char *bt_mkdtemp(char *template) -{ - return mkdtemp(template); -} - -#elif GLIB_CHECK_VERSION(2,30,0) - -#include -static inline -char *bt_mkdtemp(char *template) -{ - return g_mkdtemp(template); -} - -#else - -static inline -char *bt_mkdtemp(char *template) -{ - char *ret; - - ret = mktemp(template); - if (!ret) { - goto end; - } - - if(mkdir(template, 0700)) { - ret = NULL; - goto end; - } - - ret = template; -end: - return ret; -} - -#endif - -#endif /* _BABELTRACE_COMPAT_STDLIB_H */ diff --git a/include/babeltrace/compat/string-internal.h b/include/babeltrace/compat/string-internal.h new file mode 100644 index 00000000..2aa7bc3c --- /dev/null +++ b/include/babeltrace/compat/string-internal.h @@ -0,0 +1,116 @@ +#ifndef _BABELTRACE_COMPAT_STRING_H +#define _BABELTRACE_COMPAT_STRING_H + +/* + * Copyright (C) 2013 Mathieu Desnoyers + * + * 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. + */ + +#include +#include + +#if !defined(__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)) + +/* XSI-compliant strerror_r */ +static inline +int bt_strerror_r(int errnum, char *buf, size_t buflen) +{ + return strerror_r(errnum, buf, buflen); +} + +#else + +/* GNU-compliant strerror_r */ +static inline +int bt_strerror_r(int errnum, char *buf, size_t buflen) +{ + char *retbuf; + + retbuf = strerror_r(errnum, buf, buflen); + if (retbuf != buf) + strncpy(buf, retbuf, buflen); + buf[buflen - 1] = '\0'; + return 0; +} + +#endif + +#ifdef HAVE_STRNLEN +static inline +size_t bt_strnlen(const char *str, size_t max) +{ + return strnlen(str, max); +} +#else +static inline +size_t bt_strnlen(const char *str, size_t max) +{ + size_t ret; + const char *end; + + end = memchr(str, 0, max); + + if (end) { + ret = (size_t) (end - str); + } else { + ret = max; + } + + return ret; +} +#endif /* HAVE_STRNLEN */ + +#ifdef HAVE_STRNDUP +static inline +char *bt_strndup(const char *s, size_t n) +{ + return strndup(s, n); +} +#else +static inline +char *bt_strndup(const char *s, size_t n) +{ + char *ret; + size_t navail; + + if (!s) { + ret = NULL; + goto end; + } + + /* min() */ + navail = strlen(s) + 1; + if ((n + 1) < navail) { + navail = n + 1; + } + + ret = malloc(navail); + if (!ret) { + goto end; + } + + memcpy(ret, s, navail); + ret[navail - 1] = '\0'; +end: + return ret; +} +#endif /* HAVE_STRNDUP */ + +#endif /* _BABELTRACE_COMPAT_STRING_H */ diff --git a/include/babeltrace/compat/string.h b/include/babeltrace/compat/string.h deleted file mode 100644 index 2aa7bc3c..00000000 --- a/include/babeltrace/compat/string.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_STRING_H -#define _BABELTRACE_COMPAT_STRING_H - -/* - * Copyright (C) 2013 Mathieu Desnoyers - * - * 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. - */ - -#include -#include - -#if !defined(__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)) - -/* XSI-compliant strerror_r */ -static inline -int bt_strerror_r(int errnum, char *buf, size_t buflen) -{ - return strerror_r(errnum, buf, buflen); -} - -#else - -/* GNU-compliant strerror_r */ -static inline -int bt_strerror_r(int errnum, char *buf, size_t buflen) -{ - char *retbuf; - - retbuf = strerror_r(errnum, buf, buflen); - if (retbuf != buf) - strncpy(buf, retbuf, buflen); - buf[buflen - 1] = '\0'; - return 0; -} - -#endif - -#ifdef HAVE_STRNLEN -static inline -size_t bt_strnlen(const char *str, size_t max) -{ - return strnlen(str, max); -} -#else -static inline -size_t bt_strnlen(const char *str, size_t max) -{ - size_t ret; - const char *end; - - end = memchr(str, 0, max); - - if (end) { - ret = (size_t) (end - str); - } else { - ret = max; - } - - return ret; -} -#endif /* HAVE_STRNLEN */ - -#ifdef HAVE_STRNDUP -static inline -char *bt_strndup(const char *s, size_t n) -{ - return strndup(s, n); -} -#else -static inline -char *bt_strndup(const char *s, size_t n) -{ - char *ret; - size_t navail; - - if (!s) { - ret = NULL; - goto end; - } - - /* min() */ - navail = strlen(s) + 1; - if ((n + 1) < navail) { - navail = n + 1; - } - - ret = malloc(navail); - if (!ret) { - goto end; - } - - memcpy(ret, s, navail); - ret[navail - 1] = '\0'; -end: - return ret; -} -#endif /* HAVE_STRNDUP */ - -#endif /* _BABELTRACE_COMPAT_STRING_H */ diff --git a/include/babeltrace/compat/utc-internal.h b/include/babeltrace/compat/utc-internal.h new file mode 100644 index 00000000..fd41f620 --- /dev/null +++ b/include/babeltrace/compat/utc-internal.h @@ -0,0 +1,86 @@ +#ifndef _BABELTRACE_UTC_H +#define _BABELTRACE_UTC_H + +/* + * Copyright (C) 2011-2013 Mathieu Desnoyers + * + * 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. + */ + +#include + +/* If set, use GNU or BSD timegm(3) */ +#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) + +static inline +time_t bt_timegm(struct tm *tm) +{ + return timegm(tm); +} + +#else + +#include +#include + +/* + * Note: Below implementation of timegm() is not thread safe + * as it changes the environment + * variable TZ. It is OK as long as it is kept in self-contained program, + * but should not be used within thread-safe library code. + */ + +static inline +time_t bt_timegm(struct tm *tm) +{ + time_t ret; + char *tz; + + tz = getenv("TZ"); + /* + * Make a temporary copy, as the environment variable will be + * modified. + */ + if (tz) { + tz = strdup(tz); + if (!tz) { + /* + * Memory allocation error. + */ + return (time_t) -1; + } + } + + /* Temporarily setting TZ to 1 for UTC */ + setenv("TZ", "", 1); + tzset(); + ret = mktime(tm); + if (tz) { + setenv("TZ", tz, 1); + free(tz); + } else { + unsetenv("TZ"); + } + tzset(); + return ret; +} + +#endif + +#endif /* _BABELTRACE_UTC_H */ diff --git a/include/babeltrace/compat/utc.h b/include/babeltrace/compat/utc.h deleted file mode 100644 index fd41f620..00000000 --- a/include/babeltrace/compat/utc.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef _BABELTRACE_UTC_H -#define _BABELTRACE_UTC_H - -/* - * Copyright (C) 2011-2013 Mathieu Desnoyers - * - * 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. - */ - -#include - -/* If set, use GNU or BSD timegm(3) */ -#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) - -static inline -time_t bt_timegm(struct tm *tm) -{ - return timegm(tm); -} - -#else - -#include -#include - -/* - * Note: Below implementation of timegm() is not thread safe - * as it changes the environment - * variable TZ. It is OK as long as it is kept in self-contained program, - * but should not be used within thread-safe library code. - */ - -static inline -time_t bt_timegm(struct tm *tm) -{ - time_t ret; - char *tz; - - tz = getenv("TZ"); - /* - * Make a temporary copy, as the environment variable will be - * modified. - */ - if (tz) { - tz = strdup(tz); - if (!tz) { - /* - * Memory allocation error. - */ - return (time_t) -1; - } - } - - /* Temporarily setting TZ to 1 for UTC */ - setenv("TZ", "", 1); - tzset(); - ret = mktime(tm); - if (tz) { - setenv("TZ", tz, 1); - free(tz); - } else { - unsetenv("TZ"); - } - tzset(); - return ret; -} - -#endif - -#endif /* _BABELTRACE_UTC_H */ diff --git a/include/babeltrace/compat/uuid-internal.h b/include/babeltrace/compat/uuid-internal.h new file mode 100644 index 00000000..4237eb55 --- /dev/null +++ b/include/babeltrace/compat/uuid-internal.h @@ -0,0 +1,159 @@ +#ifndef _BABELTRACE_COMPAT_UUID_H +#define _BABELTRACE_COMPAT_UUID_H + +/* + * babeltrace/compat/uuid.h + * + * Copyright (C) 2011 Mathieu Desnoyers + * + * 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. + */ + +/* Includes final \0. */ +#define BABELTRACE_UUID_STR_LEN 37 +#define BABELTRACE_UUID_LEN 16 + +#ifdef BABELTRACE_HAVE_LIBUUID +#include + +static inline +int bt_uuid_generate(unsigned char *uuid_out) +{ + uuid_generate(uuid_out); + return 0; +} + +/* Sun's libuuid lacks const qualifiers */ +#if defined(__sun__) +static inline +int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out) +{ + uuid_unparse((unsigned char *) uuid_in, str_out); + return 0; +} + +static inline +int bt_uuid_parse(const char *str_in, unsigned char *uuid_out) +{ + return uuid_parse((char *) str_in, uuid_out); +} + +static inline +int bt_uuid_compare(const unsigned char *uuid_a, + const unsigned char *uuid_b) +{ + return uuid_compare((unsigned char *) uuid_a, + (unsigned char *) uuid_b); +} +#else +static inline +int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out) +{ + uuid_unparse(uuid_in, str_out); + return 0; +} + +static inline +int bt_uuid_parse(const char *str_in, unsigned char *uuid_out) +{ + return uuid_parse(str_in, uuid_out); +} + +static inline +int bt_uuid_compare(const unsigned char *uuid_a, + const unsigned char *uuid_b) +{ + return uuid_compare(uuid_a, uuid_b); +} +#endif + +#elif defined(BABELTRACE_HAVE_LIBC_UUID) +#include +#include +#include +#include + +static inline +int bt_uuid_generate(unsigned char *uuid_out) +{ + uint32_t status; + + uuid_create((uuid_t *) uuid_out, &status); + if (status == uuid_s_ok) + return 0; + else + return -1; +} + +static inline +int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out) +{ + uint32_t status; + char *alloc_str; + int ret; + + uuid_to_string((uuid_t *) uuid_in, &alloc_str, &status); + if (status == uuid_s_ok) { + strcpy(str_out, alloc_str); + ret = 0; + } else { + ret = -1; + } + free(alloc_str); + return ret; +} + +static inline +int bt_uuid_parse(const char *str_in, unsigned char *uuid_out) +{ + uint32_t status; + + uuid_from_string(str_in, (uuid_t *) uuid_out, &status); + if (status == uuid_s_ok) + return 0; + else + return -1; +} + +static inline +int bt_uuid_compare(const unsigned char *uuid_a, + const unsigned char *uuid_b) +{ + uint32_t status; + + uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status); + if (status == uuid_s_ok) + return 0; + else + return -1; +} + +#elif defined(__MINGW32__) + +int bt_uuid_generate(unsigned char *uuid_out); +int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out); +int bt_uuid_parse(const char *str_in, unsigned char *uuid_out); +int bt_uuid_compare(const unsigned char *uuid_a, + const unsigned char *uuid_b); + +#else +#error "Babeltrace needs to have a UUID generator configured." +#endif + +#endif /* _BABELTRACE_COMPAT_UUID_H */ diff --git a/include/babeltrace/compat/uuid.h b/include/babeltrace/compat/uuid.h deleted file mode 100644 index 4237eb55..00000000 --- a/include/babeltrace/compat/uuid.h +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_UUID_H -#define _BABELTRACE_COMPAT_UUID_H - -/* - * babeltrace/compat/uuid.h - * - * Copyright (C) 2011 Mathieu Desnoyers - * - * 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. - */ - -/* Includes final \0. */ -#define BABELTRACE_UUID_STR_LEN 37 -#define BABELTRACE_UUID_LEN 16 - -#ifdef BABELTRACE_HAVE_LIBUUID -#include - -static inline -int bt_uuid_generate(unsigned char *uuid_out) -{ - uuid_generate(uuid_out); - return 0; -} - -/* Sun's libuuid lacks const qualifiers */ -#if defined(__sun__) -static inline -int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out) -{ - uuid_unparse((unsigned char *) uuid_in, str_out); - return 0; -} - -static inline -int bt_uuid_parse(const char *str_in, unsigned char *uuid_out) -{ - return uuid_parse((char *) str_in, uuid_out); -} - -static inline -int bt_uuid_compare(const unsigned char *uuid_a, - const unsigned char *uuid_b) -{ - return uuid_compare((unsigned char *) uuid_a, - (unsigned char *) uuid_b); -} -#else -static inline -int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out) -{ - uuid_unparse(uuid_in, str_out); - return 0; -} - -static inline -int bt_uuid_parse(const char *str_in, unsigned char *uuid_out) -{ - return uuid_parse(str_in, uuid_out); -} - -static inline -int bt_uuid_compare(const unsigned char *uuid_a, - const unsigned char *uuid_b) -{ - return uuid_compare(uuid_a, uuid_b); -} -#endif - -#elif defined(BABELTRACE_HAVE_LIBC_UUID) -#include -#include -#include -#include - -static inline -int bt_uuid_generate(unsigned char *uuid_out) -{ - uint32_t status; - - uuid_create((uuid_t *) uuid_out, &status); - if (status == uuid_s_ok) - return 0; - else - return -1; -} - -static inline -int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out) -{ - uint32_t status; - char *alloc_str; - int ret; - - uuid_to_string((uuid_t *) uuid_in, &alloc_str, &status); - if (status == uuid_s_ok) { - strcpy(str_out, alloc_str); - ret = 0; - } else { - ret = -1; - } - free(alloc_str); - return ret; -} - -static inline -int bt_uuid_parse(const char *str_in, unsigned char *uuid_out) -{ - uint32_t status; - - uuid_from_string(str_in, (uuid_t *) uuid_out, &status); - if (status == uuid_s_ok) - return 0; - else - return -1; -} - -static inline -int bt_uuid_compare(const unsigned char *uuid_a, - const unsigned char *uuid_b) -{ - uint32_t status; - - uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status); - if (status == uuid_s_ok) - return 0; - else - return -1; -} - -#elif defined(__MINGW32__) - -int bt_uuid_generate(unsigned char *uuid_out); -int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out); -int bt_uuid_parse(const char *str_in, unsigned char *uuid_out); -int bt_uuid_compare(const unsigned char *uuid_a, - const unsigned char *uuid_b); - -#else -#error "Babeltrace needs to have a UUID generator configured." -#endif - -#endif /* _BABELTRACE_COMPAT_UUID_H */ diff --git a/include/babeltrace/compiler-internal.h b/include/babeltrace/compiler-internal.h new file mode 100644 index 00000000..4eaa0e6e --- /dev/null +++ b/include/babeltrace/compiler-internal.h @@ -0,0 +1,42 @@ +#ifndef _BABELTRACE_COMPILER_H +#define _BABELTRACE_COMPILER_H + +/* + * compiler.h + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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. + */ + +#include /* for offsetof */ + +#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) + +#ifndef container_of +#define container_of(ptr, type, member) \ + ({ \ + const typeof(((type *)NULL)->member) * __ptr = (ptr); \ + (type *)((char *)__ptr - offsetof(type, member)); \ + }) +#endif + +#define BT_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +#endif /* _BABELTRACE_COMPILER_H */ diff --git a/include/babeltrace/compiler.h b/include/babeltrace/compiler.h deleted file mode 100644 index 4eaa0e6e..00000000 --- a/include/babeltrace/compiler.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _BABELTRACE_COMPILER_H -#define _BABELTRACE_COMPILER_H - -/* - * compiler.h - * - * Copyright 2010 - Mathieu Desnoyers - * - * 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. - */ - -#include /* for offsetof */ - -#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) - -#ifndef container_of -#define container_of(ptr, type, member) \ - ({ \ - const typeof(((type *)NULL)->member) * __ptr = (ptr); \ - (type *)((char *)__ptr - offsetof(type, member)); \ - }) -#endif - -#define BT_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) - -#endif /* _BABELTRACE_COMPILER_H */ diff --git a/include/babeltrace/ctf-ir/clock-class-internal.h b/include/babeltrace/ctf-ir/clock-class-internal.h index c43f7712..0d7d8917 100644 --- a/include/babeltrace/ctf-ir/clock-class-internal.h +++ b/include/babeltrace/ctf-ir/clock-class-internal.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include struct bt_ctf_clock_class { struct bt_object base; diff --git a/include/babeltrace/ctf-ir/event-fields b/include/babeltrace/ctf-ir/event-fields new file mode 100644 index 00000000..82460852 Binary files /dev/null and b/include/babeltrace/ctf-ir/event-fields differ diff --git a/include/babeltrace/ctf-writer/clock-internal.h b/include/babeltrace/ctf-writer/clock-internal.h index 967be1aa..b9e524a9 100644 --- a/include/babeltrace/ctf-writer/clock-internal.h +++ b/include/babeltrace/ctf-writer/clock-internal.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include struct bt_ctf_clock { struct bt_object base; diff --git a/include/babeltrace/ctf-writer/serialize-internal.h b/include/babeltrace/ctf-writer/serialize-internal.h index b04ec36c..15ced8de 100644 --- a/include/babeltrace/ctf-writer/serialize-internal.h +++ b/include/babeltrace/ctf-writer/serialize-internal.h @@ -35,8 +35,8 @@ #include #include #include -#include -#include +#include +#include struct bt_ctf_stream_pos { int fd; diff --git a/include/babeltrace/endian-internal.h b/include/babeltrace/endian-internal.h new file mode 100644 index 00000000..55f8d1ec --- /dev/null +++ b/include/babeltrace/endian-internal.h @@ -0,0 +1,231 @@ +#ifndef _BABELTRACE_ENDIAN_H +#define _BABELTRACE_ENDIAN_H + +/* + * babeltrace/endian.h + * + * Copyright 2012 (c) - Mathieu Desnoyers + * + * endian.h compatibility layer. + * + * 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. + */ + +#ifdef __FreeBSD__ +#include + +#elif defined(__sun__) +#include + +#ifndef __BIG_ENDIAN +#define __BIG_ENDIAN 4321 +#endif +#ifndef __LITTLE_ENDIAN +#define __LITTLE_ENDIAN 1234 +#endif + +#ifdef _LITTLE_ENDIAN +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif + +#ifdef _BIG_ENDIAN +#define __BYTE_ORDER __BIG_ENDIAN +#endif + +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#define BIG_ENDIAN __BIG_ENDIAN +#define BYTE_ORDER __BYTE_ORDER + +#define betoh16(x) BE_16(x) +#define letoh16(x) LE_16(x) +#define betoh32(x) BE_32(x) +#define letoh32(x) LE_32(x) +#define betoh64(x) BE_64(x) +#define letoh64(x) LE_64(x) +#define htobe16(x) BE_16(x) +#define be16toh(x) BE_16(x) +#define htobe32(x) BE_32(x) +#define be32toh(x) BE_32(x) +#define htobe64(x) BE_64(x) +#define be64toh(x) BE_64(x) + +#elif defined(__MINGW32__) +#ifndef __BIG_ENDIAN +#define __BIG_ENDIAN 4321 +#endif +#ifndef __LITTLE_ENDIAN +#define __LITTLE_ENDIAN 1234 +#endif + +#ifndef __BYTE_ORDER +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif + +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#define BIG_ENDIAN __BIG_ENDIAN +#define PDP_ENDIAN __PDP_ENDIAN +#define BYTE_ORDER __BYTE_ORDER + +#elif defined(__APPLE__) +# include +# include + +# if BYTE_ORDER == LITTLE_ENDIAN +# define htobe16(x) OSSwapConstInt16(x) +# define htole16(x) (x) +# define be16toh(x) OSSwapConstInt16(x) +# define le16toh(x) (x) + +# define htobe32(x) OSSwapConstInt32(x) +# define htole32(x) (x) +# define be32toh(x) OSSwapConstInt32(x) +# define le32toh(x) (x) + +# define htobe64(x) OSSwapConstInt64(x) +# define htole64(x) (x) +# define be64toh(x) OSSwapConstInt64(x) +# define le64toh(x) (x) + +# else /* BYTE_ORDER == LITTLE_ENDIAN */ +# define htobe16(x) (x) +# define htole16(x) OSSwapConstInt16(x) +# define be16toh(x) (x) +# define le16toh(x) OSSwapConstInt16(x) + +# define htobe32(x) (x) +# define htole32(x) OSSwapConstInt32(x) +# define be32toh(x) (x) +# define le32toh(x) OSSwapConstInt32(x) + +# define htobe64(x) (x) +# define htole64(x) OSSwapConstInt64(x) +# define be64toh(x) (x) +# define le64toh(x) OSSwapConstInt64(x) +# endif + +#else +#include + +/* + * htobe/betoh are not defined for glibc < 2.9, so add them explicitly + * if they are missing. + */ +# ifdef __USE_BSD +/* Conversion interfaces. */ +# include + +# if __BYTE_ORDER == __LITTLE_ENDIAN +# ifndef htobe16 +# define htobe16(x) __bswap_16(x) +# endif +# ifndef htole16 +# define htole16(x) (x) +# endif +# ifndef be16toh +# define be16toh(x) __bswap_16(x) +# endif +# ifndef le16toh +# define le16toh(x) (x) +# endif + +# ifndef htobe32 +# define htobe32(x) __bswap_32(x) +# endif +# ifndef htole32 +# define htole32(x) (x) +# endif +# ifndef be32toh +# define be32toh(x) __bswap_32(x) +# endif +# ifndef le32toh +# define le32toh(x) (x) +# endif + +# ifndef htobe64 +# define htobe64(x) __bswap_64(x) +# endif +# ifndef htole64 +# define htole64(x) (x) +# endif +# ifndef be64toh +# define be64toh(x) __bswap_64(x) +# endif +# ifndef le64toh +# define le64toh(x) (x) +# endif + +# else /* __BYTE_ORDER == __LITTLE_ENDIAN */ +# ifndef htobe16 +# define htobe16(x) (x) +# endif +# ifndef htole16 +# define htole16(x) __bswap_16(x) +# endif +# ifndef be16toh +# define be16toh(x) (x) +# endif +# ifndef le16toh +# define le16toh(x) __bswap_16(x) +# endif + +# ifndef htobe32 +# define htobe32(x) (x) +# endif +# ifndef htole32 +# define htole32(x) __bswap_32(x) +# endif +# ifndef be32toh +# define be32toh(x) (x) +# endif +# ifndef le32toh +# define le32toh(x) __bswap_32(x) +# endif + +# ifndef htobe64 +# define htobe64(x) (x) +# endif +# ifndef htole64 +# define htole64(x) __bswap_64(x) +# endif +# ifndef be64toh +# define be64toh(x) (x) +# endif +# ifndef le64toh +# define le64toh(x) __bswap_64(x) +# endif + +# endif /* __BYTE_ORDER == __LITTLE_ENDIAN */ +# endif /* __USE_BSD */ +#endif /* else -- __FreeBSD__ */ + +#ifndef FLOAT_WORD_ORDER +#ifdef __FLOAT_WORD_ORDER +#define FLOAT_WORD_ORDER __FLOAT_WORD_ORDER +#else /* __FLOAT_WORD_ORDER */ +#define FLOAT_WORD_ORDER BYTE_ORDER +#endif /* __FLOAT_WORD_ORDER */ +#endif /* FLOAT_WORD_ORDER */ + +#if (BYTE_ORDER == BIG_ENDIAN) +# define BT_CTF_MY_BYTE_ORDER BT_CTF_BYTE_ORDER_BIG_ENDIAN +#else +# define BT_CTF_MY_BYTE_ORDER BT_CTF_BYTE_ORDER_LITTLE_ENDIAN +#endif + +#endif /* _BABELTRACE_ENDIAN_H */ diff --git a/include/babeltrace/endian.h b/include/babeltrace/endian.h deleted file mode 100644 index 55f8d1ec..00000000 --- a/include/babeltrace/endian.h +++ /dev/null @@ -1,231 +0,0 @@ -#ifndef _BABELTRACE_ENDIAN_H -#define _BABELTRACE_ENDIAN_H - -/* - * babeltrace/endian.h - * - * Copyright 2012 (c) - Mathieu Desnoyers - * - * endian.h compatibility layer. - * - * 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. - */ - -#ifdef __FreeBSD__ -#include - -#elif defined(__sun__) -#include - -#ifndef __BIG_ENDIAN -#define __BIG_ENDIAN 4321 -#endif -#ifndef __LITTLE_ENDIAN -#define __LITTLE_ENDIAN 1234 -#endif - -#ifdef _LITTLE_ENDIAN -#define __BYTE_ORDER __LITTLE_ENDIAN -#endif - -#ifdef _BIG_ENDIAN -#define __BYTE_ORDER __BIG_ENDIAN -#endif - -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define BIG_ENDIAN __BIG_ENDIAN -#define BYTE_ORDER __BYTE_ORDER - -#define betoh16(x) BE_16(x) -#define letoh16(x) LE_16(x) -#define betoh32(x) BE_32(x) -#define letoh32(x) LE_32(x) -#define betoh64(x) BE_64(x) -#define letoh64(x) LE_64(x) -#define htobe16(x) BE_16(x) -#define be16toh(x) BE_16(x) -#define htobe32(x) BE_32(x) -#define be32toh(x) BE_32(x) -#define htobe64(x) BE_64(x) -#define be64toh(x) BE_64(x) - -#elif defined(__MINGW32__) -#ifndef __BIG_ENDIAN -#define __BIG_ENDIAN 4321 -#endif -#ifndef __LITTLE_ENDIAN -#define __LITTLE_ENDIAN 1234 -#endif - -#ifndef __BYTE_ORDER -#define __BYTE_ORDER __LITTLE_ENDIAN -#endif - -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define BIG_ENDIAN __BIG_ENDIAN -#define PDP_ENDIAN __PDP_ENDIAN -#define BYTE_ORDER __BYTE_ORDER - -#elif defined(__APPLE__) -# include -# include - -# if BYTE_ORDER == LITTLE_ENDIAN -# define htobe16(x) OSSwapConstInt16(x) -# define htole16(x) (x) -# define be16toh(x) OSSwapConstInt16(x) -# define le16toh(x) (x) - -# define htobe32(x) OSSwapConstInt32(x) -# define htole32(x) (x) -# define be32toh(x) OSSwapConstInt32(x) -# define le32toh(x) (x) - -# define htobe64(x) OSSwapConstInt64(x) -# define htole64(x) (x) -# define be64toh(x) OSSwapConstInt64(x) -# define le64toh(x) (x) - -# else /* BYTE_ORDER == LITTLE_ENDIAN */ -# define htobe16(x) (x) -# define htole16(x) OSSwapConstInt16(x) -# define be16toh(x) (x) -# define le16toh(x) OSSwapConstInt16(x) - -# define htobe32(x) (x) -# define htole32(x) OSSwapConstInt32(x) -# define be32toh(x) (x) -# define le32toh(x) OSSwapConstInt32(x) - -# define htobe64(x) (x) -# define htole64(x) OSSwapConstInt64(x) -# define be64toh(x) (x) -# define le64toh(x) OSSwapConstInt64(x) -# endif - -#else -#include - -/* - * htobe/betoh are not defined for glibc < 2.9, so add them explicitly - * if they are missing. - */ -# ifdef __USE_BSD -/* Conversion interfaces. */ -# include - -# if __BYTE_ORDER == __LITTLE_ENDIAN -# ifndef htobe16 -# define htobe16(x) __bswap_16(x) -# endif -# ifndef htole16 -# define htole16(x) (x) -# endif -# ifndef be16toh -# define be16toh(x) __bswap_16(x) -# endif -# ifndef le16toh -# define le16toh(x) (x) -# endif - -# ifndef htobe32 -# define htobe32(x) __bswap_32(x) -# endif -# ifndef htole32 -# define htole32(x) (x) -# endif -# ifndef be32toh -# define be32toh(x) __bswap_32(x) -# endif -# ifndef le32toh -# define le32toh(x) (x) -# endif - -# ifndef htobe64 -# define htobe64(x) __bswap_64(x) -# endif -# ifndef htole64 -# define htole64(x) (x) -# endif -# ifndef be64toh -# define be64toh(x) __bswap_64(x) -# endif -# ifndef le64toh -# define le64toh(x) (x) -# endif - -# else /* __BYTE_ORDER == __LITTLE_ENDIAN */ -# ifndef htobe16 -# define htobe16(x) (x) -# endif -# ifndef htole16 -# define htole16(x) __bswap_16(x) -# endif -# ifndef be16toh -# define be16toh(x) (x) -# endif -# ifndef le16toh -# define le16toh(x) __bswap_16(x) -# endif - -# ifndef htobe32 -# define htobe32(x) (x) -# endif -# ifndef htole32 -# define htole32(x) __bswap_32(x) -# endif -# ifndef be32toh -# define be32toh(x) (x) -# endif -# ifndef le32toh -# define le32toh(x) __bswap_32(x) -# endif - -# ifndef htobe64 -# define htobe64(x) (x) -# endif -# ifndef htole64 -# define htole64(x) __bswap_64(x) -# endif -# ifndef be64toh -# define be64toh(x) (x) -# endif -# ifndef le64toh -# define le64toh(x) __bswap_64(x) -# endif - -# endif /* __BYTE_ORDER == __LITTLE_ENDIAN */ -# endif /* __USE_BSD */ -#endif /* else -- __FreeBSD__ */ - -#ifndef FLOAT_WORD_ORDER -#ifdef __FLOAT_WORD_ORDER -#define FLOAT_WORD_ORDER __FLOAT_WORD_ORDER -#else /* __FLOAT_WORD_ORDER */ -#define FLOAT_WORD_ORDER BYTE_ORDER -#endif /* __FLOAT_WORD_ORDER */ -#endif /* FLOAT_WORD_ORDER */ - -#if (BYTE_ORDER == BIG_ENDIAN) -# define BT_CTF_MY_BYTE_ORDER BT_CTF_BYTE_ORDER_BIG_ENDIAN -#else -# define BT_CTF_MY_BYTE_ORDER BT_CTF_BYTE_ORDER_LITTLE_ENDIAN -#endif - -#endif /* _BABELTRACE_ENDIAN_H */ diff --git a/include/babeltrace/list-internal.h b/include/babeltrace/list-internal.h new file mode 100644 index 00000000..ee5d84bd --- /dev/null +++ b/include/babeltrace/list-internal.h @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2002 Free Software Foundation, Inc. + * This file is part of the GNU C Library. + * Contributed by Ulrich Drepper , 2002. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; only + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _BT_LIST_H +#define _BT_LIST_H 1 + +/* The definitions of this file are adopted from those which can be + found in the Linux kernel headers to enable people familiar with + the latter find their way in these sources as well. */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Basic type for the double-link list. */ +struct bt_list_head +{ + struct bt_list_head *next; + struct bt_list_head *prev; +}; + + +/* Define a variable with the head and tail of the list. */ +#define BT_LIST_HEAD(name) \ + struct bt_list_head name = { &(name), &(name) } + +/* Initialize a new list head. */ +#define BT_INIT_LIST_HEAD(ptr) \ + (ptr)->next = (ptr)->prev = (ptr) + +#define BT_LIST_HEAD_INIT(name) { .prev = &(name), .next = &(name) } + +/* Add new element at the head of the list. */ +static inline void +bt_list_add (struct bt_list_head *newp, struct bt_list_head *head) +{ + head->next->prev = newp; + newp->next = head->next; + newp->prev = head; + head->next = newp; +} + + +/* Add new element at the tail of the list. */ +static inline void +bt_list_add_tail (struct bt_list_head *newp, struct bt_list_head *head) +{ + head->prev->next = newp; + newp->next = head; + newp->prev = head->prev; + head->prev = newp; +} + + +/* Remove element from list. */ +static inline void +__bt_list_del (struct bt_list_head *prev, struct bt_list_head *next) +{ + next->prev = prev; + prev->next = next; +} + +/* Remove element from list. */ +static inline void +bt_list_del (struct bt_list_head *elem) +{ + __bt_list_del (elem->prev, elem->next); +} + +/* delete from list, add to another list as head */ +static inline void +bt_list_move (struct bt_list_head *elem, struct bt_list_head *head) +{ + __bt_list_del (elem->prev, elem->next); + bt_list_add (elem, head); +} + +/* replace an old entry. + */ +static inline void +bt_list_replace(struct bt_list_head *old, struct bt_list_head *_new) +{ + _new->next = old->next; + _new->prev = old->prev; + _new->prev->next = _new; + _new->next->prev = _new; +} + +/* Join two lists. */ +static inline void +bt_list_splice (struct bt_list_head *add, struct bt_list_head *head) +{ + /* Do nothing if the list which gets added is empty. */ + if (add != add->next) + { + add->next->prev = head; + add->prev->next = head->next; + head->next->prev = add->prev; + head->next = add->next; + } +} + + +/* Get typed element from list at a given position. */ +#define bt_list_entry(ptr, type, member) \ + ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member))) + + + +/* Iterate forward over the elements of the list. */ +#define bt_list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + + +/* Iterate forward over the elements of the list. */ +#define bt_list_for_each_prev(pos, head) \ + for (pos = (head)->prev; pos != (head); pos = pos->prev) + + +/* Iterate backwards over the elements list. The list elements can be + removed from the list while doing this. */ +#define bt_list_for_each_prev_safe(pos, p, head) \ + for (pos = (head)->prev, p = pos->prev; \ + pos != (head); \ + pos = p, p = pos->prev) + +#define bt_list_for_each_entry(pos, head, member) \ + for (pos = bt_list_entry((head)->next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = bt_list_entry(pos->member.next, typeof(*pos), member)) + +#define bt_list_for_each_entry_reverse(pos, head, member) \ + for (pos = bt_list_entry((head)->prev, typeof(*pos), member); \ + &pos->member != (head); \ + pos = bt_list_entry(pos->member.prev, typeof(*pos), member)) + +#define bt_list_for_each_entry_safe(pos, p, head, member) \ + for (pos = bt_list_entry((head)->next, typeof(*pos), member), \ + p = bt_list_entry(pos->member.next,typeof(*pos), member); \ + &pos->member != (head); \ + pos = p, p = bt_list_entry(pos->member.next, typeof(*pos), member)) + +static inline int bt_list_empty(struct bt_list_head *head) +{ + return head == head->next; +} + +static inline void bt_list_replace_init(struct bt_list_head *old, + struct bt_list_head *_new) +{ + struct bt_list_head *head = old->next; + bt_list_del(old); + bt_list_add_tail(_new, head); + BT_INIT_LIST_HEAD(old); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _BT_LIST_H */ diff --git a/include/babeltrace/list.h b/include/babeltrace/list.h deleted file mode 100644 index ee5d84bd..00000000 --- a/include/babeltrace/list.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 2002 Free Software Foundation, Inc. - * This file is part of the GNU C Library. - * Contributed by Ulrich Drepper , 2002. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; only - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _BT_LIST_H -#define _BT_LIST_H 1 - -/* The definitions of this file are adopted from those which can be - found in the Linux kernel headers to enable people familiar with - the latter find their way in these sources as well. */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Basic type for the double-link list. */ -struct bt_list_head -{ - struct bt_list_head *next; - struct bt_list_head *prev; -}; - - -/* Define a variable with the head and tail of the list. */ -#define BT_LIST_HEAD(name) \ - struct bt_list_head name = { &(name), &(name) } - -/* Initialize a new list head. */ -#define BT_INIT_LIST_HEAD(ptr) \ - (ptr)->next = (ptr)->prev = (ptr) - -#define BT_LIST_HEAD_INIT(name) { .prev = &(name), .next = &(name) } - -/* Add new element at the head of the list. */ -static inline void -bt_list_add (struct bt_list_head *newp, struct bt_list_head *head) -{ - head->next->prev = newp; - newp->next = head->next; - newp->prev = head; - head->next = newp; -} - - -/* Add new element at the tail of the list. */ -static inline void -bt_list_add_tail (struct bt_list_head *newp, struct bt_list_head *head) -{ - head->prev->next = newp; - newp->next = head; - newp->prev = head->prev; - head->prev = newp; -} - - -/* Remove element from list. */ -static inline void -__bt_list_del (struct bt_list_head *prev, struct bt_list_head *next) -{ - next->prev = prev; - prev->next = next; -} - -/* Remove element from list. */ -static inline void -bt_list_del (struct bt_list_head *elem) -{ - __bt_list_del (elem->prev, elem->next); -} - -/* delete from list, add to another list as head */ -static inline void -bt_list_move (struct bt_list_head *elem, struct bt_list_head *head) -{ - __bt_list_del (elem->prev, elem->next); - bt_list_add (elem, head); -} - -/* replace an old entry. - */ -static inline void -bt_list_replace(struct bt_list_head *old, struct bt_list_head *_new) -{ - _new->next = old->next; - _new->prev = old->prev; - _new->prev->next = _new; - _new->next->prev = _new; -} - -/* Join two lists. */ -static inline void -bt_list_splice (struct bt_list_head *add, struct bt_list_head *head) -{ - /* Do nothing if the list which gets added is empty. */ - if (add != add->next) - { - add->next->prev = head; - add->prev->next = head->next; - head->next->prev = add->prev; - head->next = add->next; - } -} - - -/* Get typed element from list at a given position. */ -#define bt_list_entry(ptr, type, member) \ - ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member))) - - - -/* Iterate forward over the elements of the list. */ -#define bt_list_for_each(pos, head) \ - for (pos = (head)->next; pos != (head); pos = pos->next) - - -/* Iterate forward over the elements of the list. */ -#define bt_list_for_each_prev(pos, head) \ - for (pos = (head)->prev; pos != (head); pos = pos->prev) - - -/* Iterate backwards over the elements list. The list elements can be - removed from the list while doing this. */ -#define bt_list_for_each_prev_safe(pos, p, head) \ - for (pos = (head)->prev, p = pos->prev; \ - pos != (head); \ - pos = p, p = pos->prev) - -#define bt_list_for_each_entry(pos, head, member) \ - for (pos = bt_list_entry((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = bt_list_entry(pos->member.next, typeof(*pos), member)) - -#define bt_list_for_each_entry_reverse(pos, head, member) \ - for (pos = bt_list_entry((head)->prev, typeof(*pos), member); \ - &pos->member != (head); \ - pos = bt_list_entry(pos->member.prev, typeof(*pos), member)) - -#define bt_list_for_each_entry_safe(pos, p, head, member) \ - for (pos = bt_list_entry((head)->next, typeof(*pos), member), \ - p = bt_list_entry(pos->member.next,typeof(*pos), member); \ - &pos->member != (head); \ - pos = p, p = bt_list_entry(pos->member.next, typeof(*pos), member)) - -static inline int bt_list_empty(struct bt_list_head *head) -{ - return head == head->next; -} - -static inline void bt_list_replace_init(struct bt_list_head *old, - struct bt_list_head *_new) -{ - struct bt_list_head *head = old->next; - bt_list_del(old); - bt_list_add_tail(_new, head); - BT_INIT_LIST_HEAD(old); -} - -#ifdef __cplusplus -} -#endif - -#endif /* _BT_LIST_H */ diff --git a/include/babeltrace/mmap-align-internal.h b/include/babeltrace/mmap-align-internal.h new file mode 100644 index 00000000..ccb0e1f4 --- /dev/null +++ b/include/babeltrace/mmap-align-internal.h @@ -0,0 +1,105 @@ +#ifndef _BABELTRACE_MMAP_ALIGN_H +#define _BABELTRACE_MMAP_ALIGN_H + +/* + * BabelTrace mmap-align.h - mmap alignment header + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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. + */ + +#include +#include +#include + +/* + * This header implements a wrapper over mmap (mmap_align) that memory + * maps a file region that is not necessarily multiple of the page size. + * It returns a structure (instead of a pointer) that contains the mmap + * pointer (page-aligned) and a pointer to the offset requested within + * that page. Note: in the current implementation, the "addr" parameter + * cannot be forced, so we allocate at an address chosen by the OS. + */ + +struct mmap_align { + void *page_aligned_addr; /* mmap address, aligned to floor */ + size_t page_aligned_length; /* mmap length, containing range */ + + void *addr; /* virtual mmap address */ + size_t length; /* virtual mmap length */ +}; + +static inline +struct mmap_align *mmap_align(size_t length, int prot, + int flags, int fd, off_t offset) +{ + struct mmap_align *mma; + off_t page_aligned_offset; /* mmap offset, aligned to floor */ + + mma = malloc(sizeof(*mma)); + if (!mma) + return MAP_FAILED; + mma->length = length; + page_aligned_offset = ALIGN_FLOOR(offset, PAGE_SIZE); + /* + * Page aligned length needs to contain the requested range. + * E.g., for a small range that fits within a single page, we might + * require a 2 pages page_aligned_length if the range crosses a page + * boundary. + */ + mma->page_aligned_length = ALIGN(length + offset - page_aligned_offset, PAGE_SIZE); + mma->page_aligned_addr = mmap(NULL, mma->page_aligned_length, + prot, flags, fd, page_aligned_offset); + if (mma->page_aligned_addr == (void *) -1UL) { + free(mma); + return MAP_FAILED; + } + mma->addr = mma->page_aligned_addr + (offset - page_aligned_offset); + return mma; +} + +static inline +int munmap_align(struct mmap_align *mma) +{ + void *page_aligned_addr; + size_t page_aligned_length; + + page_aligned_addr = mma->page_aligned_addr; + page_aligned_length = mma->page_aligned_length; + free(mma); + return munmap(page_aligned_addr, page_aligned_length); +} + +static inline +void *mmap_align_addr(struct mmap_align *mma) +{ + return mma->addr; +} + +/* + * Helper for special-cases, normally unused. + */ +static inline +void mmap_align_set_addr(struct mmap_align *mma, void *addr) +{ + mma->addr = addr; +} + +#endif /* _BABELTRACE_MMAP_ALIGN_H */ diff --git a/include/babeltrace/mmap-align.h b/include/babeltrace/mmap-align.h deleted file mode 100644 index f7c18fa6..00000000 --- a/include/babeltrace/mmap-align.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef _BABELTRACE_MMAP_ALIGN_H -#define _BABELTRACE_MMAP_ALIGN_H - -/* - * BabelTrace mmap-align.h - mmap alignment header - * - * Copyright 2010 - Mathieu Desnoyers - * - * 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. - */ - -#include -#include -#include - -/* - * This header implements a wrapper over mmap (mmap_align) that memory - * maps a file region that is not necessarily multiple of the page size. - * It returns a structure (instead of a pointer) that contains the mmap - * pointer (page-aligned) and a pointer to the offset requested within - * that page. Note: in the current implementation, the "addr" parameter - * cannot be forced, so we allocate at an address chosen by the OS. - */ - -struct mmap_align { - void *page_aligned_addr; /* mmap address, aligned to floor */ - size_t page_aligned_length; /* mmap length, containing range */ - - void *addr; /* virtual mmap address */ - size_t length; /* virtual mmap length */ -}; - -static inline -struct mmap_align *mmap_align(size_t length, int prot, - int flags, int fd, off_t offset) -{ - struct mmap_align *mma; - off_t page_aligned_offset; /* mmap offset, aligned to floor */ - - mma = malloc(sizeof(*mma)); - if (!mma) - return MAP_FAILED; - mma->length = length; - page_aligned_offset = ALIGN_FLOOR(offset, PAGE_SIZE); - /* - * Page aligned length needs to contain the requested range. - * E.g., for a small range that fits within a single page, we might - * require a 2 pages page_aligned_length if the range crosses a page - * boundary. - */ - mma->page_aligned_length = ALIGN(length + offset - page_aligned_offset, PAGE_SIZE); - mma->page_aligned_addr = mmap(NULL, mma->page_aligned_length, - prot, flags, fd, page_aligned_offset); - if (mma->page_aligned_addr == (void *) -1UL) { - free(mma); - return MAP_FAILED; - } - mma->addr = mma->page_aligned_addr + (offset - page_aligned_offset); - return mma; -} - -static inline -int munmap_align(struct mmap_align *mma) -{ - void *page_aligned_addr; - size_t page_aligned_length; - - page_aligned_addr = mma->page_aligned_addr; - page_aligned_length = mma->page_aligned_length; - free(mma); - return munmap(page_aligned_addr, page_aligned_length); -} - -static inline -void *mmap_align_addr(struct mmap_align *mma) -{ - return mma->addr; -} - -/* - * Helper for special-cases, normally unused. - */ -static inline -void mmap_align_set_addr(struct mmap_align *mma, void *addr) -{ - mma->addr = addr; -} - -#endif /* _BABELTRACE_MMAP_ALIGN_H */ diff --git a/include/babeltrace/prio-heap-internal.h b/include/babeltrace/prio-heap-internal.h new file mode 100644 index 00000000..52de47c8 --- /dev/null +++ b/include/babeltrace/prio-heap-internal.h @@ -0,0 +1,134 @@ +#ifndef _BABELTRACE_PRIO_HEAP_H +#define _BABELTRACE_PRIO_HEAP_H + +/* + * prio_heap.h + * + * Static-sized priority heap containing pointers. Based on CLRS, + * chapter 6. + * + * Copyright 2011 - Mathieu Desnoyers + * + * 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. + */ + +#include +#include + +struct ptr_heap { + size_t len, alloc_len; + void **ptrs; + int (*gt)(void *a, void *b); +}; + +#ifdef DEBUG_HEAP +void check_heap(const struct ptr_heap *heap); +#else +static inline +void check_heap(const struct ptr_heap *heap) +{ +} +#endif + +/** + * bt_heap_maximum - return the largest element in the heap + * @heap: the heap to be operated on + * + * Returns the largest element in the heap, without performing any modification + * to the heap structure. Returns NULL if the heap is empty. + */ +static inline void *bt_heap_maximum(const struct ptr_heap *heap) +{ + check_heap(heap); + return likely(heap->len) ? heap->ptrs[0] : NULL; +} + +/** + * bt_heap_init - initialize the heap + * @heap: the heap to initialize + * @alloc_len: number of elements initially allocated + * @gt: function to compare the elements + * + * Returns -ENOMEM if out of memory. + */ +extern int bt_heap_init(struct ptr_heap *heap, + size_t alloc_len, + int gt(void *a, void *b)); + +/** + * bt_heap_free - free the heap + * @heap: the heap to free + */ +extern void bt_heap_free(struct ptr_heap *heap); + +/** + * bt_heap_insert - insert an element into the heap + * @heap: the heap to be operated on + * @p: the element to add + * + * Insert an element into the heap. + * + * Returns -ENOMEM if out of memory. + */ +extern int bt_heap_insert(struct ptr_heap *heap, void *p); + +/** + * bt_heap_remove - remove the largest element from the heap + * @heap: the heap to be operated on + * + * Returns the largest element in the heap. It removes this element from the + * heap. Returns NULL if the heap is empty. + */ +extern void *bt_heap_remove(struct ptr_heap *heap); + +/** + * bt_heap_cherrypick - remove a given element from the heap + * @heap: the heap to be operated on + * @p: the element + * + * Remove the given element from the heap. Return the element if present, else + * return NULL. This algorithm has a complexity of O(n), which is higher than + * O(log(n)) provided by the rest of this API. + */ +extern void *bt_heap_cherrypick(struct ptr_heap *heap, void *p); + +/** + * bt_heap_replace_max - replace the the largest element from the heap + * @heap: the heap to be operated on + * @p: the pointer to be inserted as topmost element replacement + * + * Returns the largest element in the heap. It removes this element from the + * heap. The heap is rebalanced only once after the insertion. Returns NULL if + * the heap is empty. + * + * This is the equivalent of calling bt_heap_remove() and then bt_heap_insert(), but + * it only rebalances the heap once. It never allocates memory. + */ +extern void *bt_heap_replace_max(struct ptr_heap *heap, void *p); + +/** + * bt_heap_copy - copy a heap + * @dst: the destination heap (must be allocated) + * @src: the source heap + * + * Returns -ENOMEM if out of memory. + */ +extern int bt_heap_copy(struct ptr_heap *dst, struct ptr_heap *src); + +#endif /* _BABELTRACE_PRIO_HEAP_H */ diff --git a/include/babeltrace/prio_heap.h b/include/babeltrace/prio_heap.h deleted file mode 100644 index 52de47c8..00000000 --- a/include/babeltrace/prio_heap.h +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef _BABELTRACE_PRIO_HEAP_H -#define _BABELTRACE_PRIO_HEAP_H - -/* - * prio_heap.h - * - * Static-sized priority heap containing pointers. Based on CLRS, - * chapter 6. - * - * Copyright 2011 - Mathieu Desnoyers - * - * 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. - */ - -#include -#include - -struct ptr_heap { - size_t len, alloc_len; - void **ptrs; - int (*gt)(void *a, void *b); -}; - -#ifdef DEBUG_HEAP -void check_heap(const struct ptr_heap *heap); -#else -static inline -void check_heap(const struct ptr_heap *heap) -{ -} -#endif - -/** - * bt_heap_maximum - return the largest element in the heap - * @heap: the heap to be operated on - * - * Returns the largest element in the heap, without performing any modification - * to the heap structure. Returns NULL if the heap is empty. - */ -static inline void *bt_heap_maximum(const struct ptr_heap *heap) -{ - check_heap(heap); - return likely(heap->len) ? heap->ptrs[0] : NULL; -} - -/** - * bt_heap_init - initialize the heap - * @heap: the heap to initialize - * @alloc_len: number of elements initially allocated - * @gt: function to compare the elements - * - * Returns -ENOMEM if out of memory. - */ -extern int bt_heap_init(struct ptr_heap *heap, - size_t alloc_len, - int gt(void *a, void *b)); - -/** - * bt_heap_free - free the heap - * @heap: the heap to free - */ -extern void bt_heap_free(struct ptr_heap *heap); - -/** - * bt_heap_insert - insert an element into the heap - * @heap: the heap to be operated on - * @p: the element to add - * - * Insert an element into the heap. - * - * Returns -ENOMEM if out of memory. - */ -extern int bt_heap_insert(struct ptr_heap *heap, void *p); - -/** - * bt_heap_remove - remove the largest element from the heap - * @heap: the heap to be operated on - * - * Returns the largest element in the heap. It removes this element from the - * heap. Returns NULL if the heap is empty. - */ -extern void *bt_heap_remove(struct ptr_heap *heap); - -/** - * bt_heap_cherrypick - remove a given element from the heap - * @heap: the heap to be operated on - * @p: the element - * - * Remove the given element from the heap. Return the element if present, else - * return NULL. This algorithm has a complexity of O(n), which is higher than - * O(log(n)) provided by the rest of this API. - */ -extern void *bt_heap_cherrypick(struct ptr_heap *heap, void *p); - -/** - * bt_heap_replace_max - replace the the largest element from the heap - * @heap: the heap to be operated on - * @p: the pointer to be inserted as topmost element replacement - * - * Returns the largest element in the heap. It removes this element from the - * heap. The heap is rebalanced only once after the insertion. Returns NULL if - * the heap is empty. - * - * This is the equivalent of calling bt_heap_remove() and then bt_heap_insert(), but - * it only rebalances the heap once. It never allocates memory. - */ -extern void *bt_heap_replace_max(struct ptr_heap *heap, void *p); - -/** - * bt_heap_copy - copy a heap - * @dst: the destination heap (must be allocated) - * @src: the source heap - * - * Returns -ENOMEM if out of memory. - */ -extern int bt_heap_copy(struct ptr_heap *dst, struct ptr_heap *src); - -#endif /* _BABELTRACE_PRIO_HEAP_H */ diff --git a/lib/component/clock-class-priority-map.c b/lib/component/clock-class-priority-map.c index e917ea50..f9055198 100644 --- a/lib/component/clock-class-priority-map.c +++ b/lib/component/clock-class-priority-map.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include diff --git a/lib/component/component-class.c b/lib/component/component-class.c index bdaa2d37..4585b1f3 100644 --- a/lib/component/component-class.c +++ b/lib/component/component-class.c @@ -26,7 +26,7 @@ * SOFTWARE. */ -#include +#include #include #include #include diff --git a/lib/component/component.c b/lib/component/component.c index 47f83c86..9b996f62 100644 --- a/lib/component/component.c +++ b/lib/component/component.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include static diff --git a/lib/component/connection.c b/lib/component/connection.c index 1b58c026..986303ed 100644 --- a/lib/component/connection.c +++ b/lib/component/connection.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include static diff --git a/lib/component/filter.c b/lib/component/filter.c index dd440120..5931b3b3 100644 --- a/lib/component/filter.c +++ b/lib/component/filter.c @@ -26,7 +26,7 @@ * SOFTWARE. */ -#include +#include #include #include #include diff --git a/lib/component/graph.c b/lib/component/graph.c index a770be30..c861fa3c 100644 --- a/lib/component/graph.c +++ b/lib/component/graph.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include diff --git a/lib/component/iterator.c b/lib/component/iterator.c index ab2783d5..29562955 100644 --- a/lib/component/iterator.c +++ b/lib/component/iterator.c @@ -26,7 +26,7 @@ * SOFTWARE. */ -#include +#include #include #include #include diff --git a/lib/component/notification/event.c b/lib/component/notification/event.c index bae1912f..a9fbf48b 100644 --- a/lib/component/notification/event.c +++ b/lib/component/notification/event.c @@ -24,7 +24,7 @@ * SOFTWARE. */ -#include +#include #include #include #include diff --git a/lib/component/notification/heap.c b/lib/component/notification/heap.c index 897b680b..fc0bce81 100644 --- a/lib/component/notification/heap.c +++ b/lib/component/notification/heap.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include #ifdef DEBUG_HEAP diff --git a/lib/component/notification/inactivity.c b/lib/component/notification/inactivity.c index 9f4cae3f..48073955 100644 --- a/lib/component/notification/inactivity.c +++ b/lib/component/notification/inactivity.c @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include #include diff --git a/lib/component/notification/packet.c b/lib/component/notification/packet.c index 393181da..fa6a0ee3 100644 --- a/lib/component/notification/packet.c +++ b/lib/component/notification/packet.c @@ -24,7 +24,7 @@ * SOFTWARE. */ -#include +#include #include static diff --git a/lib/component/notification/stream.c b/lib/component/notification/stream.c index 56062f61..68b9bcdb 100644 --- a/lib/component/notification/stream.c +++ b/lib/component/notification/stream.c @@ -24,7 +24,7 @@ * SOFTWARE. */ -#include +#include #include static diff --git a/lib/component/port.c b/lib/component/port.c index bb72b163..c0d5e061 100644 --- a/lib/component/port.c +++ b/lib/component/port.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include static void bt_port_destroy(struct bt_object *obj) diff --git a/lib/component/sink.c b/lib/component/sink.c index fbdb3a3e..49bd8402 100644 --- a/lib/component/sink.c +++ b/lib/component/sink.c @@ -26,7 +26,7 @@ * SOFTWARE. */ -#include +#include #include #include #include diff --git a/lib/component/source.c b/lib/component/source.c index 7d43e34c..0c4f1817 100644 --- a/lib/component/source.c +++ b/lib/component/source.c @@ -27,7 +27,7 @@ */ #include -#include +#include #include #include #include diff --git a/lib/ctf-ir/clock-class.c b/lib/ctf-ir/clock-class.c index 66f7f440..37635ca9 100644 --- a/lib/ctf-ir/clock-class.c +++ b/lib/ctf-ir/clock-class.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include static diff --git a/lib/ctf-ir/event-class.c b/lib/ctf-ir/event-class.c index 6764d438..0cef1935 100644 --- a/lib/ctf-ir/event-class.c +++ b/lib/ctf-ir/event-class.c @@ -37,8 +37,8 @@ #include #include #include -#include -#include +#include +#include #include static diff --git a/lib/ctf-ir/event.c b/lib/ctf-ir/event.c index 5fd732de..ff153559 100644 --- a/lib/ctf-ir/event.c +++ b/lib/ctf-ir/event.c @@ -44,7 +44,7 @@ #include #include #include -#include +#include static void bt_ctf_event_destroy(struct bt_object *obj); diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index 6b02d4e3..b29d9947 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -35,8 +35,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/lib/ctf-ir/fields.c b/lib/ctf-ir/fields.c index ace87de3..c43b4afa 100644 --- a/lib/ctf-ir/fields.c +++ b/lib/ctf-ir/fields.c @@ -31,9 +31,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #define PACKET_LEN_INCREMENT (getpagesize() * 8 * CHAR_BIT) diff --git a/lib/ctf-ir/stream-class.c b/lib/ctf-ir/stream-class.c index 776ced90..4fac7468 100644 --- a/lib/ctf-ir/stream-class.c +++ b/lib/ctf-ir/stream-class.c @@ -41,9 +41,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include static diff --git a/lib/ctf-ir/stream.c b/lib/ctf-ir/stream.c index a06cbbbf..7a4d53ce 100644 --- a/lib/ctf-ir/stream.c +++ b/lib/ctf-ir/stream.c @@ -40,8 +40,8 @@ #include #include #include -#include -#include +#include +#include #include static diff --git a/lib/ctf-ir/trace.c b/lib/ctf-ir/trace.c index 99927088..e0ef7b61 100644 --- a/lib/ctf-ir/trace.c +++ b/lib/ctf-ir/trace.c @@ -41,10 +41,10 @@ #include #include #include -#include +#include #include #include -#include +#include #include #define DEFAULT_IDENTIFIER_SIZE 128 diff --git a/lib/ctf-writer/clock.c b/lib/ctf-writer/clock.c index 84125f22..dd070ec9 100644 --- a/lib/ctf-writer/clock.c +++ b/lib/ctf-writer/clock.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include static diff --git a/lib/ctf-writer/serialize.c b/lib/ctf-writer/serialize.c index 0e04229f..e0239f65 100644 --- a/lib/ctf-writer/serialize.c +++ b/lib/ctf-writer/serialize.c @@ -36,11 +36,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #if (FLT_RADIX != 2) diff --git a/lib/ctf-writer/writer.c b/lib/ctf-writer/writer.c index c0dbdbb0..c7b658fc 100644 --- a/lib/ctf-writer/writer.c +++ b/lib/ctf-writer/writer.c @@ -35,8 +35,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index bf6f9425..2e528ea0 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -27,7 +27,7 @@ * SOFTWARE. */ -#include +#include #include #include #include diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index 83f628cd..90f77cb5 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -28,7 +28,7 @@ */ #include -#include +#include #include #include #include diff --git a/lib/prio_heap/prio_heap.c b/lib/prio_heap/prio_heap.c index 58e3de68..cd7098ff 100644 --- a/lib/prio_heap/prio_heap.c +++ b/lib/prio_heap/prio_heap.c @@ -25,7 +25,7 @@ * SOFTWARE. */ -#include +#include #include #include #include diff --git a/lib/values.c b/lib/values.c index 1c7902bd..6d08aaeb 100644 --- a/lib/values.c +++ b/lib/values.c @@ -29,11 +29,11 @@ #include #include #include -#include +#include #include #include #include -#include +#include #define BT_VALUE_FROM_CONCRETE(_concrete) ((struct bt_value *) (_concrete)) #define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base)) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index d3fac02d..d50aac9d 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = ctf text muxer utils libctfcopytrace writer +SUBDIRS = ctf text utils libctfcopytrace writer if ENABLE_DEBUG_INFO SUBDIRS += debug-info diff --git a/plugins/ctf/common/btr/btr.c b/plugins/ctf/common/btr/btr.c index 7c48bd08..7e7cf37b 100644 --- a/plugins/ctf/common/btr/btr.c +++ b/plugins/ctf/common/btr/btr.c @@ -29,10 +29,10 @@ #include #include #include -#include +#include #include #include -#include +#include #include #include "btr.h" diff --git a/plugins/ctf/common/metadata/ast.h b/plugins/ctf/common/metadata/ast.h index 684ea6b8..3ab552aa 100644 --- a/plugins/ctf/common/metadata/ast.h +++ b/plugins/ctf/common/metadata/ast.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include diff --git a/plugins/ctf/common/metadata/decoder.c b/plugins/ctf/common/metadata/decoder.c index 6dbd8160..81d6ddef 100644 --- a/plugins/ctf/common/metadata/decoder.c +++ b/plugins/ctf/common/metadata/decoder.c @@ -17,8 +17,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/plugins/ctf/common/metadata/objstack.c b/plugins/ctf/common/metadata/objstack.c index 80877220..de676016 100644 --- a/plugins/ctf/common/metadata/objstack.c +++ b/plugins/ctf/common/metadata/objstack.c @@ -25,9 +25,9 @@ */ #include -#include +#include #include -#include +#include #define OBJSTACK_ALIGN 8 /* Object stack alignment */ #define OBJSTACK_INIT_LEN 128 diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index e3ca366f..71f4f12a 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -36,8 +36,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/plugins/ctf/common/metadata/visitor-parent-links.c b/plugins/ctf/common/metadata/visitor-parent-links.c index 4a017fc8..d134d71c 100644 --- a/plugins/ctf/common/metadata/visitor-parent-links.c +++ b/plugins/ctf/common/metadata/visitor-parent-links.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include "scanner.h" #include "parser.h" #include "ast.h" diff --git a/plugins/ctf/common/metadata/visitor-semantic-validator.c b/plugins/ctf/common/metadata/visitor-semantic-validator.c index bf00008d..d94a3bdf 100644 --- a/plugins/ctf/common/metadata/visitor-semantic-validator.c +++ b/plugins/ctf/common/metadata/visitor-semantic-validator.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include "scanner.h" #include "parser.h" #include "ast.h" diff --git a/plugins/ctf/fs/lttng-index.h b/plugins/ctf/fs/lttng-index.h index b26f3132..05629f86 100644 --- a/plugins/ctf/fs/lttng-index.h +++ b/plugins/ctf/fs/lttng-index.h @@ -25,7 +25,7 @@ #ifndef LTTNG_INDEX_H #define LTTNG_INDEX_H -#include +#include #define CTF_INDEX_MAGIC 0xC1F1DCC1 #define CTF_INDEX_MAJOR 1 diff --git a/plugins/ctf/fs/metadata.c b/plugins/ctf/fs/metadata.c index a728abbf..c8e008aa 100644 --- a/plugins/ctf/fs/metadata.c +++ b/plugins/ctf/fs/metadata.c @@ -29,8 +29,8 @@ #include #include #include -#include -#include +#include +#include #define PRINT_ERR_STREAM ctf_fs->error_fp #define PRINT_PREFIX "ctf-fs-metadata" diff --git a/plugins/text/print.c b/plugins/text/print.c index c155e6ff..3634d068 100644 --- a/plugins/text/print.c +++ b/plugins/text/print.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/plugins/text/text.c b/plugins/text/text.c index 78cdaab6..bf7201d2 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/python-plugin-provider/python-plugin-provider.c b/python-plugin-provider/python-plugin-provider.c index 20892fca..c7727f21 100644 --- a/python-plugin-provider/python-plugin-provider.c +++ b/python-plugin-provider/python-plugin-provider.c @@ -25,7 +25,7 @@ */ #include -#include +#include #include #include #include diff --git a/tests/lib/common.c b/tests/lib/common.c index 3f418e6d..a6812b9f 100644 --- a/tests/lib/common.c +++ b/tests/lib/common.c @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #include void recursive_rmdir(const char *path) diff --git a/tests/lib/test_bitfield.c b/tests/lib/test_bitfield.c index b14883df..efbbc30e 100644 --- a/tests/lib/test_bitfield.c +++ b/tests/lib/test_bitfield.c @@ -19,7 +19,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include +#include #include #include #include diff --git a/tests/lib/test_bt_notification_heap.c b/tests/lib/test_bt_notification_heap.c index a8c1a42b..3bffb711 100644 --- a/tests/lib/test_bt_notification_heap.c +++ b/tests/lib/test_bt_notification_heap.c @@ -22,7 +22,7 @@ #include "tap/tap.h" #include #include -#include +#include #include #include #include diff --git a/tests/lib/test_ctf_ir_ref.c b/tests/lib/test_ctf_ir_ref.c index f6a8253f..f82c3145 100644 --- a/tests/lib/test_ctf_ir_ref.c +++ b/tests/lib/test_ctf_ir_ref.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include "common.h" diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 5b256cad..9f76f7b3 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -32,16 +32,16 @@ #include #include #include -#include +#include #include #include -#include -#include +#include +#include #include #include #include #include -#include +#include #include "tap/tap.h" #include #include