25 #include <core/exceptions/system.h>
27 #include <sys/types.h>
28 #include <utils/system/file.h>
48 : Exception(error,
"Unable to open file")
50 append(
"File that could not be opened: %s", filename);
68 File::File(
const char *filename, FileOpenMethod method)
74 fd = open(
filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
79 fd = open(
filename, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
84 char *filename_ext = strdup(
filename);
88 if (asprintf(&filename_ext,
"%s.%d",
filename, ++index) == -1) {
92 fd = open(filename_ext, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
96 default: printf(
"%s [line %d]: Unkown method.\n", __FILE__, __LINE__);
100 throw UnableToOpenFileException(
filename, errno);
103 fp = fdopen(fd,
"r+");
139 return (access(
filename, F_OK) == 0);
152 return S_ISREG(s.st_mode);