Skip to contentSkip to conversation

libtracefs: Remove include sys/stat.h from global tracefs.h

PATCH New Steven Rostedt 1 participant 1 message Aug 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtracefs: Remove include sys/stat.h from global tracefs.h

From: "Steven Rostedt (VMware)" <[email protected]>

When using libtracefs in a program, Adding the following:

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tracefs.h>

Caused the following error:

In file included from /usr/include/bits/statx.h:31,

                 from /usr/include/sys/stat.h:446,
                 from /usr/local/include/tracefs/tracefs.h:9,
/usr/include/linux/stat.h:57:2: error: unknown type name â__s64â
   57 |  __s64 tv_sec;
      |  ^~~~~

The #define _GNU_SOURCE appears to cause this, but I needed it for my program. I tried several combinations to fix it, but the only solution I found that worked was to remove <sys/stat.h> from tracefs.h.

There's no reason to have it in the global header. The only includes that a header should have are those that the header itself needed. As tracefs.h does not need sys/stat.h itself, it should be removed.

Fixes 4b05ae03 ("libtracefs: Add missing system includes")
---
 include/tracefs.h   | 1 -
 src/tracefs-tools.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
include/tracefs.h +0 -1
index 55f8239..0e31a4f 100644
@@ -6,7 +6,6 @@
 #ifndef _TRACE_FS_H
 #define _TRACE_FS_H
 
-#include <sys/stat.h>
 #include <fcntl.h>
 #include <sched.h>
 #include <event-parse.h>
src/tracefs-tools.c +1 -0
index ca0ed58..ae85444 100644
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <regex.h>
 #include <dirent.h>
 #include <limits.h>
Signature · 1 line
2.31.1