BT_ASSERT(ds_file->mmap_len > 0);
ds_file->mmap_addr =
- bt_mmap(ds_file->mmap_len, PROT_READ, MAP_PRIVATE, fileno(ds_file->file->fp),
+ bt_mmap(ds_file->mmap_len, PROT_READ, MAP_PRIVATE, fileno(ds_file->file->fp.get()),
ds_file->mmap_offset_in_file, static_cast<int>(ds_file->logger.level()));
if (ds_file->mmap_addr == MAP_FAILED) {
BT_CPPLOGE_SPEC(ds_file->logger,
return;
}
- if (file->fp) {
- BT_CPPLOGD_SPEC(file->logger, "Closing file \"{}\" ({})",
- file->path ? file->path->str : NULL, fmt::ptr(file->fp));
-
- if (fclose(file->fp)) {
- BT_CPPLOGE_SPEC(file->logger, "Cannot close file \"{}\": {}",
- file->path ? file->path->str : "NULL", strerror(errno));
- }
- }
-
if (file->path) {
g_string_free(file->path, TRUE);
}
struct stat stat;
BT_CPPLOGI_SPEC(file->logger, "Opening file \"{}\" with mode \"{}\"", file->path->str, mode);
- file->fp = fopen(file->path->str, mode);
+ file->fp.reset(fopen(file->path->str, mode));
if (!file->fp) {
BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot open file", ": path={}, mode={}",
file->path->str, mode);
BT_CPPLOGI_SPEC(file->logger, "Opened file: {}", fmt::ptr(file->fp));
- if (fstat(fileno(file->fp), &stat)) {
+ if (fstat(fileno(file->fp.get()), &stat)) {
BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot get file information", ": path={}",
file->path->str);
goto error;
error:
ret = -1;
- if (file->fp) {
- if (fclose(file->fp)) {
- BT_CPPLOGE_SPEC(file->logger, "Cannot close file \"{}\": {}", file->path->str,
- strerror(errno));
- }
- }
-
end:
return ret;
}
goto end;
}
- ret = ctf_metadata_decoder_append_content(ctf_fs_trace->metadata->decoder.get(), file->fp);
+ ret =
+ ctf_metadata_decoder_append_content(ctf_fs_trace->metadata->decoder.get(), file->fp.get());
if (ret) {
BT_CPPLOGE_SPEC(ctf_fs_trace->logger, "Cannot update metadata decoder's content.");
goto end;