src.ctf.fs: remove ctf_fs_file_destroy
[babeltrace.git] / src / plugins / ctf / fs-src / file.cpp
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
5 */
6
7#include <glib.h>
8#include <stdio.h>
9#include <sys/stat.h>
10
11#include "cpp-common/bt2s/make-unique.hpp"
12#include "cpp-common/vendor/fmt/format.h"
13
14#include "file.hpp"
15
16ctf_fs_file::UP ctf_fs_file_create(const bt2c::Logger& parentLogger)
17{
18 return bt2s::make_unique<ctf_fs_file>(parentLogger);
19}
20
21int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode)
22{
23 int ret = 0;
24 struct stat stat;
25
26 BT_CPPLOGI_SPEC(file->logger, "Opening file \"{}\" with mode \"{}\"", file->path, mode);
27 file->fp.reset(fopen(file->path.c_str(), mode));
28 if (!file->fp) {
29 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot open file", ": path={}, mode={}",
30 file->path, mode);
31 goto error;
32 }
33
34 BT_CPPLOGI_SPEC(file->logger, "Opened file: {}", fmt::ptr(file->fp));
35
36 if (fstat(fileno(file->fp.get()), &stat)) {
37 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot get file information", ": path={}",
38 file->path);
39 goto error;
40 }
41
42 file->size = stat.st_size;
43 BT_CPPLOGI_SPEC(file->logger, "File is {} bytes", (intmax_t) file->size);
44 goto end;
45
46error:
47 ret = -1;
48
49end:
50 return ret;
51}
This page took 0.024101 seconds and 4 git commands to generate.