edelib
2.0.0
|
00001 /* 00002 * $Id: TempFile.h 2839 2009-09-28 11:36:20Z karijes $ 00003 * 00004 * Temporary file handler 00005 * Copyright (c) 2005-2007 edelib authors 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this library. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef __EDELIB_TEMPFILE_H__ 00022 #define __EDELIB_TEMPFILE_H__ 00023 00024 #include <stdio.h> 00025 #include "String.h" 00026 00027 EDELIB_NS_BEGIN 00028 00041 class TempFile { 00042 private: 00043 int fd; 00044 int errno_err; 00045 FILE *stream; 00046 bool auto_del; 00047 bool no_close; 00048 String filename; 00049 00050 E_DISABLE_CLASS_COPY(TempFile) 00051 public: 00055 TempFile(); 00056 00060 ~TempFile(); 00061 00067 bool create(const char* prefix, int mode = 0600); 00068 00072 operator bool(void) const { return (errno_err == 0); } 00073 00077 void unlink(void); 00078 00082 bool close(void); 00083 00087 void set_auto_delete(bool v) { auto_del = v; } 00088 00092 void set_no_close(bool n) { no_close = n; } 00093 00097 FILE* fstream(void); 00098 00102 const char* name(void) const { return (filename.empty() ? NULL : filename.c_str()); } 00103 00107 int handle(void) const { return fd; } 00108 00112 int status(void) const { return errno_err; } 00113 }; 00114 00115 EDELIB_NS_END 00116 #endif