2 * Copyright 2016 - Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include <sys/types.h>
29 #define PRINT_ERR_STREAM ctf_fs->error_fp
30 #define PRINT_PREFIX "ctf-fs-file"
36 void ctf_fs_file_destroy(struct ctf_fs_file
*file
)
38 struct ctf_fs_component
*ctf_fs
;;
44 ctf_fs
= file
->ctf_fs
;
47 PDBG("Closing file \"%s\" (%p)\n", file
->path
->str
, file
->fp
);
49 if (fclose(file
->fp
)) {
50 PERR("Cannot close file \"%s\": %s\n", file
->path
->str
,
56 g_string_free(file
->path
, TRUE
);
63 struct ctf_fs_file
*ctf_fs_file_create(struct ctf_fs_component
*ctf_fs
)
65 struct ctf_fs_file
*file
= g_new0(struct ctf_fs_file
, 1);
71 file
->ctf_fs
= ctf_fs
;
72 file
->path
= g_string_new(NULL
);
80 ctf_fs_file_destroy(file
);
88 int ctf_fs_file_open(struct ctf_fs_component
*ctf_fs
, struct ctf_fs_file
*file
,
94 PDBG("Opening file \"%s\" with mode \"%s\"\n", file
->path
->str
, mode
);
95 file
->fp
= fopen(file
->path
->str
, mode
);
97 PERR("Cannot open file \"%s\" with mode \"%s\": %s\n",
98 file
->path
->str
, mode
, strerror(errno
));
102 PDBG("Opened file: %p\n", file
->fp
);
104 if (fstat(fileno(file
->fp
), &stat
)) {
105 PERR("Cannot get file informations: %s\n", strerror(errno
));
109 file
->size
= stat
.st_size
;
110 PDBG(" File is %zu bytes\n", file
->size
);
117 if (fclose(file
->fp
)) {
118 PERR("Cannot close file \"%s\": %s\n", file
->path
->str
,
This page took 0.032025 seconds and 4 git commands to generate.