src.ctf.fs: remove ctf_fs_file_create
[deliverable/babeltrace.git] / src / plugins / ctf / fs-src / file.cpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #define BT_CLOG_CFG (logCfg)
8 #define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/FILE"
9
10 #include <stdio.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <unistd.h>
14 #include <glib.h>
15 #include "file.hpp"
16 #include "cpp-common/cfg-logging.hpp"
17 #include "cpp-common/cfg-logging-error-reporting.hpp"
18
19 BT_HIDDEN
20 int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode)
21 {
22 int ret = 0;
23 struct stat stat;
24 const bt2_common::LogCfg& logCfg = file->logCfg;
25
26 BT_CLOGI("Opening file \"%s\" with mode \"%s\"", file->path.c_str(), mode);
27 file->fp.reset(fopen(file->path.c_str(), mode));
28 if (!file->fp) {
29 BT_CLOGE_ERRNO_APPEND_CAUSE("Cannot open file", ": path=%s, mode=%s", file->path.c_str(),
30 mode);
31 goto error;
32 }
33
34 BT_CLOGI("Opened file: %p", file->fp.get());
35
36 if (fstat(fileno(file->fp.get()), &stat)) {
37 BT_CLOGE_ERRNO_APPEND_CAUSE("Cannot get file information", ": path=%s", file->path.c_str());
38 goto error;
39 }
40
41 file->size = stat.st_size;
42 BT_CLOGI("File is %jd bytes", (intmax_t) file->size);
43 goto end;
44
45 error:
46 ret = -1;
47
48 end:
49 return ret;
50 }
This page took 0.030794 seconds and 5 git commands to generate.