summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-03-26 10:39:30 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2021-03-30 08:33:49 +1000
commit9011f91868ad54cd300383c4ddcbb08e5d0d5bb8 (patch)
treefa8775d0b44a6db6b6f64feb878ddd98e808f1c8 /tools
parent7f4df04d59b1182fb8497f16dc5588bd6e1d4225 (diff)
tools/record: switch the output file from an fd to a FILE*
This is prep work to be more consistent with the use of tempfile later for individual devices. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools')
-rw-r--r--tools/libinput-record.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/tools/libinput-record.c b/tools/libinput-record.c
index 062a45ad..8021679c 100644
--- a/tools/libinput-record.c
+++ b/tools/libinput-record.c
@@ -110,7 +110,7 @@ struct record_context {
char *outfile; /* file name given on cmdline */
char *output_file; /* full file name with suffix */
- int out_fd;
+ FILE *out_file;
unsigned int indent;
struct libinput *libinput;
@@ -216,7 +216,7 @@ iprintf(const struct record_context *ctx, const char *format, ...)
snprintf(fmt, sizeof(fmt), "%s%s", &space[len - indent - 1], format);
va_start(args, format);
- rc = vdprintf(ctx->out_fd, fmt, args);
+ rc = vfprintf(ctx->out_file, fmt, args);
va_end(args);
assert(rc != -1 && (unsigned int)rc > indent);
@@ -232,7 +232,7 @@ noiprintf(const struct record_context *ctx, const char *format, ...)
int rc;
va_start(args, format);
- rc = vdprintf(ctx->out_fd, format, args);
+ rc = vfprintf(ctx->out_file, format, args);
va_end(args);
assert(rc != -1 && (unsigned int)rc > 0);
}
@@ -2102,20 +2102,20 @@ init_output_file(const char *file, bool is_prefix)
static bool
open_output_file(struct record_context *ctx, bool is_prefix)
{
- int out_fd;
+ FILE *out_file;
if (ctx->outfile) {
char *fname = init_output_file(ctx->outfile, is_prefix);
ctx->output_file = fname;
- out_fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
- if (out_fd < 0)
+ out_file = fopen(fname, "w");
+ if (!out_file)
return false;
} else {
ctx->output_file = safe_strdup("stdout");
- out_fd = STDOUT_FILENO;
+ out_file = stdout;
}
- ctx->out_fd = out_fd;
+ ctx->out_file = out_file;
return true;
}
@@ -2393,7 +2393,7 @@ mainloop(struct record_context *ctx)
}
- if (ctx->out_fd != STDOUT_FILENO)
+ if (ctx->out_file != stdout)
print_progress_bar();
}
@@ -2421,17 +2421,15 @@ mainloop(struct record_context *ctx)
indent_pop(ctx); /* devices: */
assert(ctx->indent == 0);
- fsync(ctx->out_fd);
-
/* If we didn't have events, delete the file. */
- if (!isatty(ctx->out_fd)) {
+ if (!isatty(fileno(ctx->out_file))) {
if (!ctx->had_events && ctx->output_file) {
fprintf(stderr, "No events recorded, deleting '%s'\n", ctx->output_file);
unlink(ctx->output_file);
}
- close(ctx->out_fd);
- ctx->out_fd = -1;
+ fclose(ctx->out_file);
+ ctx->out_file = NULL;
}
free(ctx->output_file);
ctx->output_file = NULL;