938c048dee513ce7c56546a8bdfee9465e547b18
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 struct ctf_fs_file
*ctf_fs_file_create(const bt2c::Logger
& parentLogger
)
40 ctf_fs_file
*file
= new ctf_fs_file
{parentLogger
};
41 file
->path
= g_string_new(NULL
);
49 ctf_fs_file_destroy(file
);
56 int ctf_fs_file_open(struct ctf_fs_file
*file
, const char *mode
)
61 BT_CPPLOGI_SPEC(file
->logger
, "Opening file \"{}\" with mode \"{}\"", file
->path
->str
, mode
);
62 file
->fp
= fopen(file
->path
->str
, mode
);
64 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file
->logger
, "Cannot open file", ": path={}, mode={}",
65 file
->path
->str
, mode
);
69 BT_CPPLOGI_SPEC(file
->logger
, "Opened file: {}", fmt::ptr(file
->fp
));
71 if (fstat(fileno(file
->fp
), &stat
)) {
72 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file
->logger
, "Cannot get file information", ": path={}",
77 file
->size
= stat
.st_size
;
78 BT_CPPLOGI_SPEC(file
->logger
, "File is {} bytes", (intmax_t) file
->size
);
85 if (fclose(file
->fp
)) {
86 BT_CPPLOGE_SPEC(file
->logger
, "Cannot close file \"{}\": {}", file
->path
->str
,
This page took 0.031601 seconds and 3 git commands to generate.