00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00027 #ifndef _UCOMMON_FILE_H_
00028 #define _UCOMMON_FILE_H_
00029
00030 #ifndef _UCOMMON_THREAD_H_
00031 #include <ucommon/thread.h>
00032 #endif
00033
00034 #ifndef _MSWINDOWS_
00035 #include <sys/stat.h>
00036 #endif
00037
00038 #include <errno.h>
00039
00040 NAMESPACE_UCOMMON
00041
00045 typedef void *dir_t;
00046
00050 typedef void *mem_t;
00051
00060 class __EXPORT fsys
00061 {
00062 protected:
00063 fd_t fd;
00064 #ifdef _MSWINDOWS_
00065 WIN32_FIND_DATA *ptr;
00066 HINSTANCE mem;
00067 #else
00068 void *ptr;
00069 #endif
00070 int error;
00071
00072 #ifdef _MSWINDOWS_
00073 static int remapError(void);
00074 #else
00075 inline static int remapError(void)
00076 {return errno;};
00077 #endif
00078
00079 public:
00083 typedef enum {
00084 ACCESS_RDONLY,
00085 ACCESS_WRONLY,
00086 ACCESS_REWRITE,
00087 ACCESS_RDWR = ACCESS_REWRITE,
00088 ACCESS_APPEND,
00089 ACCESS_SHARED,
00090 ACCESS_DIRECTORY,
00091 ACCESS_STREAM,
00092 ACCESS_RANDOM
00093 } access_t;
00094
00098 typedef long offset_t;
00099
00103 static const offset_t end;
00104
00108 fsys();
00109
00114 fsys(const fsys& descriptor);
00115
00121 fsys(const char *path, access_t access);
00122
00129 fsys(const char *path, access_t access, unsigned permission);
00130
00134 ~fsys();
00135
00140 inline fd_t operator*() const
00141 {return fd;};
00142
00147 inline operator fd_t() const
00148 {return fd;};
00149
00154 inline operator bool()
00155 {return fd != INVALID_HANDLE_VALUE || ptr != NULL;};
00156
00161 inline bool operator!()
00162 {return fd == INVALID_HANDLE_VALUE && ptr == NULL;};
00163
00168 void operator=(const fsys& descriptor);
00169
00174 void operator=(fd_t descriptor);
00175
00181 inline int getError(void)
00182 {return error;};
00183
00188 inline fd_t getHandle(void)
00189 {return fd;};
00190
00195 void seek(offset_t offset);
00196
00201 void drop(offset_t size = 0);
00202
00209 ssize_t read(void *buffer, size_t count);
00210
00217 ssize_t write(const void *buffer, size_t count);
00218
00224 int stat(struct stat *buffer);
00225
00230 int sync(void);
00231
00237 static int changeDir(const char *path);
00238
00245 static char *getPrefix(char *path, size_t size);
00246
00253 static int stat(const char *path, struct stat *buffer);
00254
00260 static int remove(const char *path);
00261
00268 static int rename(const char *oldpath, const char *newpath);
00269
00276 static int change(const char *path, unsigned mode);
00277
00284 static int access(const char *path, unsigned mode);
00285
00291 static bool isfile(const char *path);
00292
00298 static bool isdir(const char *path);
00299
00300
00308 inline static ssize_t read(fsys& descriptor, void *buffer, size_t count)
00309 {return descriptor.read(buffer, count);};
00310
00318 inline static ssize_t write(fsys& descriptor, const void *buffer, size_t count)
00319 {return descriptor.write(buffer, count);};
00320
00326 inline static void seek(fsys& descriptor, offset_t offset)
00327 {descriptor.seek(offset);};
00328
00334 inline static void drop(fsys& descriptor, offset_t size)
00335 {descriptor.drop(size);};
00336
00342 void open(const char *path, access_t access);
00343
00348 inline void assign(fd_t descriptor)
00349 {close(); fd = descriptor;};
00350
00356 inline static void assign(fsys& object, fd_t descriptor)
00357 {object.close(); object.fd = descriptor;};
00358
00365 void create(const char *path, access_t access, unsigned mode);
00366
00373 static int createDir(const char *path, unsigned mode);
00374
00380 static int removeDir(const char *path);
00381
00386 inline static void close(fsys& descriptor)
00387 {descriptor.close();};
00388
00392 void close(void);
00393
00400 inline static void open(fsys& object, const char *path, access_t access)
00401 {object.open(path, access);};
00402
00410 inline static void create(fsys& object, const char *path, access_t access, unsigned mode)
00411 {object.create(path, access, mode);};
00412
00418 static int load(const char *path);
00419
00425 static void load(fsys& module, const char *path);
00426
00431 static void unload(fsys& module);
00432
00439 static void *find(fsys& module, const char *symbol);
00440 };
00441
00445 typedef fsys fsys_t;
00446
00447 END_NAMESPACE
00448
00449 #endif
00450