cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / plugins / ctf / fs-src / file.cpp
CommitLineData
e98a2d6e 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
e98a2d6e 3 *
0235b0db 4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
e98a2d6e
PP
5 */
6
c802cacb
SM
7#include <glib.h>
8#include <stdio.h>
9#include <sys/stat.h>
c802cacb 10
0f5c5d5c 11#include "cpp-common/vendor/fmt/format.h"
98903a3e 12
087cd0f5 13#include "file.hpp"
e98a2d6e 14
55314f2a 15int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode)
e98a2d6e 16{
4164020e
SM
17 int ret = 0;
18 struct stat stat;
19
a39d9817
SM
20 BT_CPPLOGI_SPEC(file->logger, "Opening file \"{}\" with mode \"{}\"", file->path, mode);
21 file->fp.reset(fopen(file->path.c_str(), mode));
4164020e 22 if (!file->fp) {
0f5c5d5c 23 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot open file", ": path={}, mode={}",
a39d9817 24 file->path, mode);
4164020e
SM
25 goto error;
26 }
27
0f5c5d5c 28 BT_CPPLOGI_SPEC(file->logger, "Opened file: {}", fmt::ptr(file->fp));
4164020e 29
85a25425 30 if (fstat(fileno(file->fp.get()), &stat)) {
0f5c5d5c 31 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot get file information", ": path={}",
a39d9817 32 file->path);
4164020e
SM
33 goto error;
34 }
35
36 file->size = stat.st_size;
0f5c5d5c 37 BT_CPPLOGI_SPEC(file->logger, "File is {} bytes", (intmax_t) file->size);
4164020e 38 goto end;
e98a2d6e
PP
39
40error:
4164020e 41 ret = -1;
e98a2d6e 42
e98a2d6e 43end:
4164020e 44 return ret;
e98a2d6e 45}
This page took 0.099372 seconds and 4 git commands to generate.