Fawkes API  Fawkes Development Version
file.h
1 
2 /***************************************************************************
3  * file.h - file utils
4  *
5  * Generated: Wed Aug 30 22:46:20 2006
6  * Copyright 2006 Tim Niemueller [www.niemueller.de]
7  * 2007 Daniel Beck
8  *
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version. A runtime exception applies to
15  * this software (see LICENSE.GPL_WRE file mentioned below for details).
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Library General Public License for more details.
21  *
22  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23  */
24 
25 #ifndef _UTILS_SYSTEM_FILE_H_
26 #define _UTILS_SYSTEM_FILE_H_
27 
28 #include <core/exception.h>
29 
30 #include <cstdio>
31 
32 namespace fawkes {
33 
34 class UnableToOpenFileException : public Exception
35 {
36 public:
37  UnableToOpenFileException(const char *filename, int error);
38 };
39 
40 class File
41 {
42 public:
43  /** What to do when a file with the same name
44  * already exists
45  */
46  typedef enum {
47  OVERWRITE, /**< overwrite the existing file */
48  APPEND, /**< append data at the end of the existing file */
49  ADD_SUFFIX /**< add a suffix (starting with ".1") to the given filename */
51 
52  File(const char *filename, FileOpenMethod method = APPEND);
53  ~File();
54 
55  FILE * stream() const;
56  const char *filename() const;
57 
58  static bool exists(const char *filename);
59  static bool is_regular(const char *filename);
60 
61 private:
62  int fd;
63  FILE *fp;
64  char *fn;
65 };
66 
67 } // end namespace fawkes
68 
69 #endif
fawkes::File::exists
static bool exists(const char *filename)
Check if a file exists.
Definition: file.cpp:142
fawkes::File::is_regular
static bool is_regular(const char *filename)
Check if a file is a regular file.
Definition: file.cpp:152
fawkes::UnableToOpenFileException::UnableToOpenFileException
UnableToOpenFileException(const char *filename, int error)
Constructor.
Definition: file.cpp:52
fawkes::File::ADD_SUFFIX
add a suffix (starting with ".1") to the given filename
Definition: file.h:54
fawkes::File::~File
~File()
Destructor.
Definition: file.cpp:112
fawkes::File::filename
const char * filename() const
Get the file's name.
Definition: file.cpp:132
fawkes::File::OVERWRITE
overwrite the existing file
Definition: file.h:52
fawkes::File
Definition: file.h:45
fawkes::File::File
File(const char *filename, FileOpenMethod method=APPEND)
Constructor.
Definition: file.cpp:73
fawkes
fawkes::File::APPEND
append data at the end of the existing file
Definition: file.h:53
fawkes::File::stream
FILE * stream() const
Get access to the file stream.
Definition: file.cpp:123
fawkes::File::FileOpenMethod
FileOpenMethod
What to do when a file with the same name already exists.
Definition: file.h:51