Logo
~Sockets~
~Examples~
~Contact~


File.cpp

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2004-2007  Anders Hedstrom
00007 
00008 This library is made available under the terms of the GNU GPL.
00009 
00010 If you would like to use this library in a closed-source application,
00011 a separate license agreement is available. For information about 
00012 the closed-source license agreement for the C++ sockets library,
00013 please visit http://www.alhem.net/Sockets/license.html and/or
00014 email license@alhem.net.
00015 
00016 This program is free software; you can redistribute it and/or
00017 modify it under the terms of the GNU General Public License
00018 as published by the Free Software Foundation; either version 2
00019 of the License, or (at your option) any later version.
00020 
00021 This program is distributed in the hope that it will be useful,
00022 but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 GNU General Public License for more details.
00025 
00026 You should have received a copy of the GNU General Public License
00027 along with this program; if not, write to the Free Software
00028 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00029 */
00030 #include <stdarg.h>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #ifndef _WIN32
00034 #include <unistd.h>
00035 #endif
00036 
00037 #include "File.h"
00038 
00039 #ifdef SOCKETS_NAMESPACE
00040 namespace SOCKETS_NAMESPACE {
00041 #endif
00042 
00043 
00044 File::File()
00045 :m_fil(NULL)
00046 {
00047 }
00048 
00049 
00050 File::~File()
00051 {
00052 }
00053 
00054 
00055 bool File::fopen(const std::string& path, const std::string& mode)
00056 {
00057         m_path = path;
00058         m_mode = mode;
00059         m_fil = ::fopen(path.c_str(), mode.c_str());
00060         return m_fil ? true : false;
00061 }
00062 
00063 
00064 void File::fclose()
00065 {
00066         if (m_fil)
00067 		::fclose(m_fil);
00068 }
00069 
00070 
00071 
00072 size_t File::fread(char *ptr, size_t size, size_t nmemb)
00073 {
00074         return m_fil ? ::fread(ptr, size, nmemb, m_fil) : 0;
00075 }
00076 
00077 
00078 size_t File::fwrite(const char *ptr, size_t size, size_t nmemb)
00079 {
00080         return m_fil ? ::fwrite(ptr, size, nmemb, m_fil) : 0;
00081 }
00082 
00083 
00084 
00085 char *File::fgets(char *s, int size)
00086 {
00087         return m_fil ? ::fgets(s, size, m_fil) : NULL;
00088 }
00089 
00090 
00091 void File::fprintf(const char *format, ...)
00092 {
00093         va_list ap;
00094         va_start(ap, format);
00095         vfprintf(m_fil, format, ap);
00096         va_end(ap);
00097 }
00098 
00099 
00100 off_t File::size()
00101 {
00102         struct stat st;
00103         if (stat(m_path.c_str(), &st) == -1)
00104         {
00105                 return 0;
00106         }
00107         return st.st_size;
00108 }
00109 
00110 
00111 bool File::eof()
00112 {
00113         if (m_fil)
00114         {
00115                 if (feof(m_fil))
00116                         return true;
00117         }
00118         return false;
00119 }
00120 
00121 
00122 #ifdef SOCKETS_NAMESPACE
00123 }
00124 #endif
00125 
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4