00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FILEMGR_H
00023 #define FILEMGR_H
00024
00025 #include <sys/stat.h>
00026 #include <fcntl.h>
00027
00028 #include <defs.h>
00029
00030 SWORD_NAMESPACE_START
00031
00032 class SWDLLEXPORT FileMgr;
00033
00034 class SWDLLEXPORT FileDesc
00035 {
00036
00037 friend class FileMgr;
00038
00039 long offset;
00040 int fd;
00041 FileMgr *parent;
00042 FileDesc *next;
00043
00044 public:
00045 FileDesc (FileMgr * parent, const char *path, int mode, int perms, bool tryDowngrade);
00046 virtual ~FileDesc ();
00047 int getFd ();
00048 char *path;
00049 int mode;
00050 int perms;
00051 bool tryDowngrade;
00052 };
00053
00054
00055 class FileMgr
00056 {
00057
00058 friend class FileDesc;
00059
00060 FileDesc *files;
00061 int sysOpen (FileDesc * file);
00062 public:
00063
00064 FileMgr (int maxFiles = 35);
00065 ~FileMgr ();
00066 FileDesc *open (const char *path, int mode, bool tryDowngrade);
00067 FileDesc *open (const char *path, int mode, int perms = S_IREAD | S_IWRITE, bool tryDowngrade = false);
00068 void close (FileDesc *);
00069
00070 static signed char existsFile (const char *ipath, const char *ifileName = 0);
00071 static signed char existsDir (const char *ipath, const char *idirName = 0);
00072
00073
00074
00075 signed char trunc (FileDesc *);
00076
00077 int maxFiles;
00078 static FileMgr systemFileMgr;
00079 };
00080
00081
00082 SWORD_NAMESPACE_END
00083 #endif