d125789e6e6c9ae68424e50a76bb06e034e444eb
2 * SPDX-License-Identifier: MIT
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
11 #include "cpp-common/vendor/fmt/format.h"
15 void ctf_fs_file_destroy(struct ctf_fs_file
*file
)
22 BT_CPPLOGD_SPEC(file
->logger
, "Closing file \"{}\" ({})",
23 file
->path
? file
->path
->str
: NULL
, fmt::ptr(file
->fp
));
25 if (fclose(file
->fp
)) {
26 BT_CPPLOGE_SPEC(file
->logger
, "Cannot close file \"{}\": {}",
27 file
->path
? file
->path
->str
: "NULL", strerror(errno
));
32 g_string_free(file
->path
, TRUE
);
38 void ctf_fs_file_deleter::operator()(ctf_fs_file
* const file
) noexcept
40 ctf_fs_file_destroy(file
);
43 ctf_fs_file::UP
ctf_fs_file_create(const bt2c::Logger
& parentLogger
)
45 ctf_fs_file::UP file
{new ctf_fs_file
{parentLogger
}};
47 file
->path
= g_string_new(NULL
);
61 int ctf_fs_file_open(struct ctf_fs_file
*file
, const char *mode
)
66 BT_CPPLOGI_SPEC(file
->logger
, "Opening file \"{}\" with mode \"{}\"", file
->path
->str
, mode
);
67 file
->fp
= fopen(file
->path
->str
, mode
);
69 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file
->logger
, "Cannot open file", ": path={}, mode={}",
70 file
->path
->str
, mode
);
74 BT_CPPLOGI_SPEC(file
->logger
, "Opened file: {}", fmt::ptr(file
->fp
));
76 if (fstat(fileno(file
->fp
), &stat
)) {
77 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file
->logger
, "Cannot get file information", ": path={}",
82 file
->size
= stat
.st_size
;
83 BT_CPPLOGI_SPEC(file
->logger
, "File is {} bytes", (intmax_t) file
->size
);
90 if (fclose(file
->fp
)) {
91 BT_CPPLOGE_SPEC(file
->logger
, "Cannot close file \"{}\": {}", file
->path
->str
,
This page took 0.033015 seconds and 3 git commands to generate.