From: Tzvetomir Stoyanov <tstoyanov@xxxxxxxxxx> Reorganized libtracecmd internal headers: - Renamed trace-cmd-local.h to trace-write-local.h This internal header implements static __do_write_check() function, used in trace-input.c, trace-output.c and trace-msg.c files. The header cannot be included in other files, which do not call __do_write_check(). The new name trace-write-local.h reflects more closely the purpose of the file. - Added trace-cmd-local.h file, to share code inside libtracecmd. - Added definitions of htonll() and ntohll(), if not already defined, in trace-cmd-local.h Signed-off-by: Tzvetomir Stoyanov <tstoyanov@xxxxxxxxxx> --- lib/trace-cmd/include/trace-cmd-local.h | 45 ++++++----------------- lib/trace-cmd/include/trace-write-local.h | 43 ++++++++++++++++++++++ lib/trace-cmd/trace-input.c | 2 +- lib/trace-cmd/trace-msg.c | 2 +- lib/trace-cmd/trace-output.c | 2 + 5 files changed, 58 insertions(+), 36 deletions(-) create mode 100644 lib/trace-cmd/include/trace-write-local.h diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h index 09574dbd..95dce66c 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -6,10 +6,8 @@ #ifndef _TRACE_CMD_LOCAL_H #define _TRACE_CMD_LOCAL_H -/* Local for trace-input.c and trace-output.c */ - -#include "trace-cmd.h" -#include "event-utils.h" +/* Can be overridden */ +void warning(const char *fmt, ...); /* trace.dat file format version */ #define FILE_VERSION 6 @@ -18,36 +16,15 @@ #define STR(x) _STR(x) #define FILE_VERSION_STRING STR(FILE_VERSION) -static ssize_t __do_write(int fd, const void *data, size_t size) -{ - ssize_t tot = 0; - ssize_t w; - - do { - w = write(fd, data + tot, size - tot); - tot += w; - - if (!w) - break; - if (w < 0) - return w; - } while (tot != size); - - return tot; -} - -static ssize_t -__do_write_check(int fd, const void *data, size_t size) -{ - ssize_t ret; - - ret = __do_write(fd, data, size); - if (ret < 0) - return ret; - if (ret != size) - return -1; +#ifndef htonll +# if __BYTE_ORDER == __LITTLE_ENDIAN +#define htonll(x) __bswap_64(x) +#define ntohll(x) __bswap_64(x) +#else +#define htonll(x) (x) +#define ntohll(x) (x) +#endif +#endif - return 0; -} #endif /* _TRACE_CMD_LOCAL_H */ diff --git a/lib/trace-cmd/include/trace-write-local.h b/lib/trace-cmd/include/trace-write-local.h new file mode 100644 index 00000000..94ad910b --- /dev/null +++ b/lib/trace-cmd/include/trace-write-local.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: LGPL-2.1 */ +/* + * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@xxxxxxxxxx> + * + */ +#ifndef _TRACE_WRITE_LOCAL_H +#define _TRACE_WRITE_LOCAL_H + +/* Local for trace-input.c, trace-output.c and trace-msg.c */ + +static ssize_t __do_write(int fd, const void *data, size_t size) +{ + ssize_t tot = 0; + ssize_t w; + + do { + w = write(fd, data + tot, size - tot); + tot += w; + + if (!w) + break; + if (w < 0) + return w; + } while (tot != size); + + return tot; +} + +static ssize_t +__do_write_check(int fd, const void *data, size_t size) +{ + ssize_t ret; + + ret = __do_write(fd, data, size); + if (ret < 0) + return ret; + if (ret != size) + return -1; + + return 0; +} + +#endif /* _TRACE_WRITE_LOCAL_H */ diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 8b5405fb..d1d010de 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -15,7 +15,7 @@ #include <linux/time64.h> -#include "trace-cmd-local.h" +#include "trace-write-local.h" #include "trace-local.h" #include "kbuffer.h" #include "list.h" diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c index 9c8a6908..85a2bae6 100644 --- a/lib/trace-cmd/trace-msg.c +++ b/lib/trace-cmd/trace-msg.c @@ -22,7 +22,7 @@ #include <sys/types.h> #include <linux/types.h> -#include "trace-cmd-local.h" +#include "trace-write-local.h" #include "trace-local.h" #include "trace-msg.h" diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index acdd2d57..4a9a857d 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -21,7 +21,9 @@ #include <glob.h> #include "tracefs.h" +#include "trace-cmd.h" #include "trace-cmd-local.h" +#include "trace-write-local.h" #include "list.h" #include "trace-msg.h" -- 2.24.1