00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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