2 * SPDX-License-Identifier: MIT
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
11 #include "cpp-common/vendor/fmt/format.h"
16 void ctf_fs_file_destroy(struct ctf_fs_file
*file
)
23 BT_CPPLOGD_SPEC(file
->logger
, "Closing file \"{}\" ({})",
24 file
->path
? file
->path
->str
: NULL
, fmt::ptr(file
->fp
));
26 if (fclose(file
->fp
)) {
27 BT_CPPLOGE_SPEC(file
->logger
, "Cannot close file \"{}\": {}",
28 file
->path
? file
->path
->str
: "NULL", strerror(errno
));
33 g_string_free(file
->path
, TRUE
);
39 struct ctf_fs_file
*ctf_fs_file_create(const bt2c::Logger
& parentLogger
)
41 ctf_fs_file
*file
= new ctf_fs_file
{parentLogger
};
42 file
->path
= g_string_new(NULL
);
50 ctf_fs_file_destroy(file
);
57 int ctf_fs_file_open(struct ctf_fs_file
*file
, const char *mode
)
62 BT_CPPLOGI_SPEC(file
->logger
, "Opening file \"{}\" with mode \"{}\"", file
->path
->str
, mode
);
63 file
->fp
= fopen(file
->path
->str
, mode
);
65 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file
->logger
, "Cannot open file", ": path={}, mode={}",
66 file
->path
->str
, mode
);
70 BT_CPPLOGI_SPEC(file
->logger
, "Opened file: {}", fmt::ptr(file
->fp
));
72 if (fstat(fileno(file
->fp
), &stat
)) {
73 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file
->logger
, "Cannot get file information", ": path={}",
78 file
->size
= stat
.st_size
;
79 BT_CPPLOGI_SPEC(file
->logger
, "File is {} bytes", (intmax_t) file
->size
);
86 if (fclose(file
->fp
)) {
87 BT_CPPLOGE_SPEC(file
->logger
, "Cannot close file \"{}\": {}", file
->path
->str
,
This page took 0.035075 seconds and 5 git commands to generate.