25#include <core/exceptions/system.h>
28#include <utils/system/file.h>
50 append(
"File that could not be opened: %s", filename);
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__);
103 fp = fdopen(fd,
"r+");
139 return (access(
filename, F_OK) == 0);
152 return S_ISREG(s.st_mode);
Base class for exceptions in Fawkes.
void append(const char *format,...) noexcept
Append messages to the message list.
File(const char *filename, FileOpenMethod method=APPEND)
Constructor.
static bool is_regular(const char *filename)
Check if a file is a regular file.
static bool exists(const char *filename)
Check if a file exists.
FileOpenMethod
What to do when a file with the same name already exists.
@ APPEND
append data at the end of the existing file
@ ADD_SUFFIX
add a suffix (starting with ".1") to the given filename
@ OVERWRITE
overwrite the existing file
FILE * stream() const
Get access to the file stream.
const char * filename() const
Get the file's name.
System ran out of memory and desired operation could not be fulfilled.
Opening a file failed for some reason.
UnableToOpenFileException(const char *filename, int error)
Constructor.
Fawkes library namespace.