diff mbox series

[6/6] v4l2-tracer: use stat to verify that retrace file exists

Message ID b17f1feba82de0c7529525e3e35bc5e8a388a9d9.1701390439.git.deborah.brouwer@collabora.com (mailing list archive)
State New
Headers show
Series v4l2-tracer: misc fixes and improvements | expand

Commit Message

Deborah Brouwer Dec. 1, 2023, 12:46 a.m. UTC
Instead of opening and closing the file to see if it exists, just use
stat. This avoids cluttering a trace with extra opens/closes. Also change
the return value to give a better description of the failure to the
calling function.

Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
 utils/v4l2-tracer/retrace.cpp          | 7 +++----
 utils/v4l2-tracer/v4l2-tracer-common.h | 1 +
 2 files changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/utils/v4l2-tracer/retrace.cpp b/utils/v4l2-tracer/retrace.cpp
index b8a1c8fb..60d64d8b 100644
--- a/utils/v4l2-tracer/retrace.cpp
+++ b/utils/v4l2-tracer/retrace.cpp
@@ -1537,12 +1537,11 @@  void retrace_array(json_object *root_array_obj)
 
 int retrace(std::string trace_filename)
 {
-	FILE *trace_file = fopen(trace_filename.c_str(), "r");
-	if (trace_file == nullptr) {
+	struct stat sb;
+	if (stat(trace_filename.c_str(), &sb) == -1) {
 		line_info("\n\tTrace file error: \'%s\'", trace_filename.c_str());
-		return 1;
+		return -EINVAL;
 	}
-	fclose(trace_file);
 
 	fprintf(stderr, "Retracing: %s\n", trace_filename.c_str());
 
diff --git a/utils/v4l2-tracer/v4l2-tracer-common.h b/utils/v4l2-tracer/v4l2-tracer-common.h
index c8b5dbd4..adb41218 100644
--- a/utils/v4l2-tracer/v4l2-tracer-common.h
+++ b/utils/v4l2-tracer/v4l2-tracer-common.h
@@ -26,6 +26,7 @@ 
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <unordered_map>
 #include <vector>