00001 00002 /*************************************************************************** 00003 * file.h - file utils 00004 * 00005 * Generated: Wed Aug 30 22:46:20 2006 00006 * Copyright 2006 Tim Niemueller [www.niemueller.de] 00007 * 2007 Daniel Beck 00008 * 00009 ****************************************************************************/ 00010 00011 /* This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. A runtime exception applies to 00015 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU Library General Public License for more details. 00021 * 00022 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00023 */ 00024 00025 #ifndef __UTILS_SYSTEM_FILE_H_ 00026 #define __UTILS_SYSTEM_FILE_H_ 00027 00028 #include <core/exception.h> 00029 #include <cstdio> 00030 00031 namespace fawkes { 00032 00033 class UnableToOpenFileException : public Exception { 00034 public: 00035 UnableToOpenFileException(const char *filename, int error); 00036 }; 00037 00038 class File { 00039 public: 00040 00041 /** What to do when a file with the same name 00042 * already exists 00043 */ 00044 typedef enum { 00045 OVERWRITE, /**< overwrite the existing file */ 00046 APPEND, /**< append data at the end of the existing file */ 00047 ADD_SUFFIX /**< add a suffix (starting with ".1") to the given filename */ 00048 } FileOpenMethod; 00049 00050 File(const char *filename, FileOpenMethod method = APPEND); 00051 ~File(); 00052 00053 FILE * stream() const; 00054 const char * filename() const; 00055 00056 static bool exists(const char *filename); 00057 static bool is_regular(const char *filename); 00058 00059 private: 00060 int fd; 00061 FILE *fp; 00062 char *fn; 00063 }; 00064 00065 00066 } // end namespace fawkes 00067 00068 #endif