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 #include <cstdio>
30 
31 namespace fawkes {
32 
34  public:
35  UnableToOpenFileException(const char *filename, int error);
36 };
37 
38 class File {
39  public:
40 
41  /** What to do when a file with the same name
42  * already exists
43  */
44  typedef enum {
45  OVERWRITE, /**< overwrite the existing file */
46  APPEND, /**< append data at the end of the existing file */
47  ADD_SUFFIX /**< add a suffix (starting with ".1") to the given filename */
49 
50  File(const char *filename, FileOpenMethod method = APPEND);
51  ~File();
52 
53  FILE * stream() const;
54  const char * filename() const;
55 
56  static bool exists(const char *filename);
57  static bool is_regular(const char *filename);
58 
59  private:
60  int fd;
61  FILE *fp;
62  char *fn;
63 };
64 
65 
66 } // end namespace fawkes
67 
68 #endif
Fawkes library namespace.
Opening a file failed for some reason.
Definition: file.h:33
UnableToOpenFileException(const char *filename, int error)
Constructor.
Definition: file.cpp:48
FileOpenMethod
What to do when a file with the same name already exists.
Definition: file.h:44
overwrite the existing file
Definition: file.h:45
Base class for exceptions in Fawkes.
Definition: exception.h:36
append data at the end of the existing file
Definition: file.h:46
File utility methods.
Definition: file.h:38