@@ -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());
@@ -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>
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(-)