This helper function is used to read strings from a binary file locally in trace-dump.c context. The same functionality could be useful for other trace-cmd logics. Made the function non static and prefix it with "trace_", so it could be used in trace-cmd application context. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx> --- tracecmd/include/trace-local.h | 1 + tracecmd/trace-dump.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 8b2d4c21..109c3328 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -318,4 +318,5 @@ struct pid_addr_maps { int trace_debug_get_filemap(struct pid_addr_maps **file_maps, int pid); void trace_debug_free_filemap(struct pid_addr_maps *maps); +int trace_read_file_string(int fd, char *dst, int len); #endif /* __TRACE_LOCAL_H */ diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 5642f12a..c55e2389 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -49,7 +49,7 @@ enum dump_items verbosity; tracecmd_plog(fmt, ##__VA_ARGS__); \ } while (0) -static int read_file_string(int fd, char *dst, int len) +int trace_read_file_string(int fd, char *dst, int len) { size_t size = 0; int r; @@ -160,7 +160,7 @@ static void dump_initial_format(int fd) die("wrong tracing string: %s", buf); /* get file version */ - if (read_file_string(fd, buf, DUMP_SIZE)) + if (trace_read_file_string(fd, buf, DUMP_SIZE)) die("no version string"); do_print(SUMMARY, "\t\t%s\t[Version]\n", buf); @@ -260,7 +260,7 @@ static void dump_events_format(int fd) while (systems) { - if (read_file_string(fd, buf, DUMP_SIZE)) + if (trace_read_file_string(fd, buf, DUMP_SIZE)) die("cannot read the name of the $dth system", systems); if (read_file_number(fd, &events, 4)) die("cannot read the count of the events in system %s", -- 2.28.0