26 #include <utils/system/file.h> 27 #include <core/exceptions/system.h> 29 #include <sys/types.h> 51 append(
"File that could not be opened: %s", filename);
78 fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
79 fn = strdup(filename);
83 fd = open(filename, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
84 fn = strdup(filename);
89 char *filename_ext = strdup(filename);
93 if ( asprintf(&filename_ext,
"%s.%d", filename, ++index) == -1 ) {
98 fd = open(filename_ext, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
104 printf(
"%s [line %d]: Unkown method.\n", __FILE__, __LINE__);
112 fp = fdopen(fd,
"r+");
151 return (access(filename, F_OK) == 0);
164 if ( stat(filename, &s) == 0 ) {
165 return S_ISREG(s.st_mode);
File(const char *filename, FileOpenMethod method=APPEND)
Constructor.
const char * filename() const
Get the file's name.
Fawkes library namespace.
UnableToOpenFileException(const char *filename, int error)
Constructor.
FileOpenMethod
What to do when a file with the same name already exists.
Base class for exceptions in Fawkes.
FILE * stream() const
Get access to the file stream.
static bool exists(const char *filename)
Check if a file exists.
static bool is_regular(const char *filename)
Check if a file is a regular file.
System ran out of memory and desired operation could not be fulfilled.
void append(const char *format,...)
Append messages to the message list.