The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
filemgr.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * filemgr.cpp - implementation of class FileMgr used for pooling file
4  * handles
5  *
6  * $Id: filemgr.cpp 3819 2020-10-24 20:23:11Z scribe $
7  *
8  * Copyright 1998-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #include <filemgr.h>
25 #include <utilstr.h>
26 
27 #include <stdlib.h>
28 #include <dirent.h>
29 #include <fcntl.h>
30 #include <sys/stat.h>
31 #include <sys/types.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <swbuf.h>
35 #if !defined(__GNUC__) && !defined(_WIN32_WCE)
36 #include <io.h>
37 #include <direct.h>
38 #else
39 #include <unistd.h>
40 #endif
41 #ifdef WIN32
42 #include <wchar.h>
43 #include <windows.h>
44 #endif
45 
46 
47 #ifndef O_BINARY
48 #define O_BINARY 0
49 #endif
50 
51 #ifndef S_IRGRP
52 #define S_IRGRP 0
53 #endif
54 
55 #ifndef S_IROTH
56 #define S_IROTH 0
57 #endif
58 
59 // Fix for VC6
60 #ifndef S_IREAD
61 #ifdef _S_IREAD
62 #define S_IREAD _S_IREAD
63 #define S_IWRITE _S_IWRITE
64 #endif
65 #endif
66 // -----------
67 
68 // ------- if we still don't have something
69 #ifndef S_IREAD
70 #define S_IREAD 0400
71 #endif
72 #ifndef S_IWRITE
73 #define S_IWRITE 0200
74 #endif
75 // -------
76 
77 
79 
80 
81 unsigned int FileMgr::CREAT = O_CREAT;
82 unsigned int FileMgr::APPEND = O_APPEND;
83 unsigned int FileMgr::TRUNC = O_TRUNC;
84 unsigned int FileMgr::RDONLY = O_RDONLY;
85 unsigned int FileMgr::RDWR = O_RDWR;
86 unsigned int FileMgr::WRONLY = O_WRONLY;
87 unsigned int FileMgr::IREAD = S_IREAD;
88 unsigned int FileMgr::IWRITE = S_IWRITE;
89 
90 
91 // ---------------- statics -----------------
93 
95 public:
99 
100 
102  if (!systemFileMgr)
103  systemFileMgr = new FileMgr();
104 
105  return systemFileMgr;
106 }
107 
108 
110  if (systemFileMgr)
111  delete systemFileMgr;
112  systemFileMgr = newFileMgr;
113 }
114 
115 long FileMgr::write(int fd, const void *buf, long count) {
116  return ::write(fd, buf, count);
117 }
118 
119 // --------------- end statics --------------
120 
121 
122 FileDesc::FileDesc(FileMgr *parent, const char *path, int mode, int perms, bool tryDowngrade) {
123  this->parent = parent;
124  this->path = 0;
125  stdstr(&this->path, path);
126  this->mode = mode;
127  this->perms = perms;
128  this->tryDowngrade = tryDowngrade;
129  offset = 0;
130  fd = -77;
131 }
132 
133 
135  if (fd > 0)
137 
138  if (path)
139  delete [] path;
140 }
141 
142 
143 long FileDesc::seek(long offset, int whence) {
144  return lseek(getFd(), offset, whence);
145 }
146 
147 
148 long FileDesc::read(void *buf, long count) {
149  return ::read(getFd(), buf, count);
150 }
151 
152 
153 long FileDesc::write(const void *buf, long count) {
154  return FileMgr::write(getFd(), buf, count);
155 }
156 
157 
158 FileMgr::FileMgr(int maxFiles) {
159  this->maxFiles = maxFiles; // must be at least 2
160  files = 0;
161 }
162 
163 
165  FileDesc *tmp;
166 
167  while(files) {
168  tmp = files->next;
169  delete files;
170  files = tmp;
171  }
172 }
173 
174 
175 FileDesc *FileMgr::open(const char *path, int mode, bool tryDowngrade) {
176  return open(path, mode, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH, tryDowngrade);
177 }
178 
179 
180 FileDesc *FileMgr::open(const char *path, int mode, int perms, bool tryDowngrade) {
181  FileDesc **tmp, *tmp2;
182 
183  for (tmp = &files; *tmp; tmp = &((*tmp)->next)) {
184  if ((*tmp)->fd < 0) // insert as first non-system_open file
185  break;
186  }
187 
188  tmp2 = new FileDesc(this, path, mode, perms, tryDowngrade);
189  tmp2->next = *tmp;
190  *tmp = tmp2;
191 
192  return tmp2;
193 }
194 
195 
197  FileDesc **loop;
198 
199  for (loop = &files; *loop; loop = &((*loop)->next)) {
200  if (*loop == file) {
201  *loop = (*loop)->next;
202  delete file;
203  break;
204  }
205  }
206 }
207 
208 
210  FileDesc **loop;
211  int openCount = 1; // because we are presently opening 1 file, and we need to be sure to close files to accomodate, if necessary
212 
213  for (loop = &files; *loop; loop = &((*loop)->next)) {
214 
215  if ((*loop)->fd > 0) {
216  if (++openCount > maxFiles) {
217  (*loop)->offset = lseek((*loop)->fd, 0, SEEK_CUR);
218  ::close((*loop)->fd);
219  (*loop)->fd = -77;
220  }
221  }
222 
223  if (*loop == file) {
224  if (*loop != files) {
225  *loop = (*loop)->next;
226  file->next = files;
227  files = file;
228  }
229  if ((hasAccess(file->path, 04)) || ((file->mode & O_CREAT) == O_CREAT)) { // check for at least file exists / read access before we try to open
230  char tries = (((file->mode & O_RDWR) == O_RDWR) && (file->tryDowngrade)) ? 2 : 1; // try read/write if possible
231  for (int i = 0; i < tries; i++) {
232  if (i > 0) {
233  file->mode = (file->mode & ~O_RDWR); // remove write access
234  file->mode = (file->mode | O_RDONLY);// add read access
235  }
236  file->fd = openFile(file->path, file->mode|O_BINARY, file->perms);
237  if (file->fd >= 0)
238  break;
239  }
240 
241  if (file->fd >= 0)
242  lseek(file->fd, file->offset, SEEK_SET);
243  }
244  else file->fd = -1;
245  if (!*loop)
246  break;
247  }
248  }
249  return file->fd;
250 }
251 
252 
253 // to truncate a file at its current position
254 // leaving byte at current possition intact
255 // deleting everything afterward.
256 signed char FileMgr::trunc(FileDesc *file) {
257 
258  static const char *writeTest = "x";
259  long size = file->seek(1, SEEK_CUR);
260  if (size == 1) // was empty
261  size = 0;
262  char nibble [ 32767 ];
263  bool writable = file->write(writeTest, 1);
264  int bytes = 0;
265 
266  if (writable) {
267  // get tmpfilename
268  char *buf = new char [ strlen(file->path) + 10 ];
269  int i;
270  for (i = 0; i < 9999; i++) {
271  sprintf(buf, "%stmp%.4d", file->path, i);
272  if (!existsFile(buf))
273  break;
274  }
275  if (i == 9999)
276  return -2;
277 
278  FileDesc *fd = open(buf, CREAT|RDWR);
279  if (!fd || fd->getFd() < 0)
280  return -3;
281 
282  file->seek(0, SEEK_SET);
283  while (size > 0) {
284  bytes = (int)file->read(nibble, 32767);
285  bytes = (bytes < size)?bytes:(int)size;
286  if (fd->write(nibble, bytes) != bytes) { break; }
287  size -= bytes;
288  }
289  if (size < 1) {
290  // zero out the file
291  ::close(file->fd);
292  file->fd = openFile(file->path, O_TRUNC, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
293  ::close(file->fd);
294  file->fd = -77; // force file open by filemgr
295  // copy tmp file back (dumb, but must preserve file permissions)
296  fd->seek(0, SEEK_SET);
297  do {
298  bytes = fd->read(nibble, 32767);
299  file->write(nibble, bytes);
300  } while (bytes == 32767);
301  }
302 
303  close(fd);
304  ::close(file->fd);
305  removeFile(buf); // remove our tmp file
306  file->fd = -77; // causes file to be swapped out forcing open on next call to getFd()
307  }
308  else { // put offset back and return failure
309  file->seek(-1, SEEK_CUR);
310  return -1;
311  }
312  return 0;
313 }
314 
315 
316 SWBuf FileMgr::getEnvValue(const char *variableName) {
317  return
318 #ifdef WIN32
319  wcharToUTF8(_wgetenv((const wchar_t *)utf8ToWChar(variableName).getRawData()));
320 #else
321  getenv(variableName);
322 #endif
323 
324 }
325 
326 
327 bool FileMgr::hasAccess(const char *path, int mode) {
328  return
329 #ifdef WIN32
330  !_waccess((const wchar_t *)utf8ToWChar(path).getRawData(), mode);
331 #else
332  !access(path, mode);
333 #endif
334 }
335 
336 
337 signed char FileMgr::existsFile(const char *ipath, const char *ifileName)
338 {
339  int len = (int)strlen(ipath) + ((ifileName)?strlen(ifileName):0) + 3;
340  char *ch;
341  char *path = new char [ len ];
342  strcpy(path, ipath);
343 
344  if ((path[strlen(path)-1] == '\\') || (path[strlen(path)-1] == '/'))
345  path[strlen(path)-1] = 0;
346 
347  if (ifileName) {
348  ch = path + strlen(path);
349  sprintf(ch, "/%s", ifileName);
350  }
351  signed char retVal = hasAccess(path, 04) ? 1 : 0;
352  delete [] path;
353  return retVal;
354 }
355 
356 
357 signed char FileMgr::existsDir(const char *ipath, const char *idirName)
358 {
359  char *ch;
360  int len = (int)strlen(ipath) + ((idirName)?strlen(idirName):0) + 1;
361  if (idirName)
362  len += strlen(idirName);
363  char *path = new char [ len ];
364  strcpy(path, ipath);
365 
366  if ((path[strlen(path)-1] == '\\') || (path[strlen(path)-1] == '/'))
367  path[strlen(path)-1] = 0;
368 
369  if (idirName) {
370  ch = path + strlen(path);
371  sprintf(ch, "/%s", idirName);
372  }
373  signed char retVal = hasAccess(path, 04) ? 1 : 0;
374  delete [] path;
375  return retVal;
376 }
377 
378 
379 std::vector<struct DirEntry> FileMgr::getDirList(const char *dirPath, bool includeSize, bool includeIsDirectory) {
380  std::vector<struct DirEntry> dirList;
381  SWBuf basePath = dirPath;
382  if (!basePath.endsWith("/") && !basePath.endsWith("\\")) basePath += "/";
383 
384 #ifndef WIN32
385  DIR *dir;
386  struct dirent *ent;
387  if ((dir = opendir(dirPath))) {
388  rewinddir(dir);
389  while ((ent = readdir(dir))) {
390  if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
391  struct DirEntry i;
392  i.name = ent->d_name;
393  if (includeIsDirectory || includeSize) i.isDirectory = FileMgr::isDirectory(basePath + ent->d_name);
394  if (!i.isDirectory && includeSize) i.size = FileMgr::getFileSize(basePath + ent->d_name);
395  dirList.push_back(i);
396  }
397  }
398  closedir(dir);
399  }
400 
401 #else
402  // Crappy Windows-specific code because well... They can't be conformant
403  WIN32_FIND_DATAW fileData;
404  SWBuf wcharBuf = utf8ToWChar(basePath+"*");
405  const wchar_t *wcharPath = (const wchar_t *)wcharBuf.getRawData();
406  HANDLE findIterator = FindFirstFileW(wcharPath, &fileData);
407  if (findIterator != INVALID_HANDLE_VALUE) {
408  do {
409  SWBuf dirEntName = wcharToUTF8(fileData.cFileName);
410  if (dirEntName != "." && dirEntName != "..") {
411  struct DirEntry i;
412  i.name = dirEntName;
413  i.isDirectory = fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
414  if (!i.isDirectory && includeSize) i.size = FileMgr::getFileSize(basePath + i.name);
415  dirList.push_back(i);
416  }
417  } while (FindNextFileW(findIterator, &fileData) != 0);
418  FindClose(findIterator);
419  }
420 #endif
421 
422  return dirList;
423 }
424 
425 
426 int FileMgr::createParent(const char *pName) {
427  char *buf = new char [ strlen(pName) + 1 ];
428  int retCode = 0;
429 
430  strcpy(buf, pName);
431  int end = (int)strlen(buf) - 1;
432  while (end) {
433  if ((buf[end] == '/') || (buf[end] == '\\'))
434  break;
435  end--;
436  }
437  buf[end] = 0;
438  if (strlen(buf)>0) {
439  if (!hasAccess(buf, 02)) { // not exists with write access?
440  retCode =
441 #ifndef WIN32
442  mkdir(buf, 0755);
443 #else
444  _wmkdir((const wchar_t *)utf8ToWChar(buf).getRawData());
445 #endif
446  if (retCode) {
447  createParent(buf);
448  retCode =
449 #ifndef WIN32
450  mkdir(buf, 0755);
451 #else
452  _wmkdir((const wchar_t *)utf8ToWChar(buf).getRawData());
453 #endif
454  }
455  }
456  }
457  else retCode = -1;
458  delete [] buf;
459  return retCode;
460 }
461 
462 
463 int FileMgr::openFile(const char *fName, int mode, int perms) {
464  int fd =
465 #ifndef WIN32
466  ::open(fName, mode, perms);
467 #else
468  ::_wopen((const wchar_t *)utf8ToWChar(fName).getRawData(), mode, perms);
469 #endif
470  return fd;
471 }
472 
473 
474 int FileMgr::openFileReadOnly(const char *fName) {
475  return openFile(fName, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
476 }
477 
478 
479 int FileMgr::createPathAndFile(const char *fName) {
480  int fd;
481 
482  fd = openFile(fName, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
483  if (fd < 1) {
484  createParent(fName);
485  fd = openFile(fName, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
486  }
487  return fd;
488 }
489 
490 
491 void FileMgr::closeFile(int fd) {
492  ::close(fd);
493 }
494 
495 
496 int FileMgr::copyFile(const char *sourceFile, const char *targetFile) {
497  int sfd, dfd, len;
498  char buf[4096];
499 
500  if ((sfd = openFile(sourceFile, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) < 1)
501  return -1;
502  if ((dfd = createPathAndFile(targetFile)) < 1)
503  return -1;
504 
505  do {
506  len = (int)read(sfd, buf, 4096);
507  if (write(dfd, buf, len) != len) break;
508  }
509  while(len == 4096);
510  ::close(dfd);
511  ::close(sfd);
512 
513  return 0;
514 }
515 
516 
517 int FileMgr::removeFile(const char *fName) {
518  return
519 #ifndef WIN32
520  ::remove(fName);
521 #else
522  ::_wremove((const wchar_t *)utf8ToWChar(fName).getRawData());
523 #endif
524 }
525 
526 
527 char FileMgr::getLine(FileDesc *fDesc, SWBuf &line) {
528  int len = 0;
529  bool more = true;
530  char chunk[255];
531 
532  line = "";
533 
534  // assert we have a valid file handle
535  if (fDesc->getFd() < 1)
536  return 0;
537 
538  while (more) {
539  more = false;
540  long index = fDesc->seek(0, SEEK_CUR);
541  len = (int)fDesc->read(chunk, 254);
542 
543  // assert we have a readable file (not a directory)
544  if (len < 1)
545  break;
546 
547  int start = 0;
548  // clean up any preceding white space if we're at the beginning of line
549  if (!line.length()) {
550  for (;start < len; start++) {
551  if ((chunk[start] != 13) && (chunk[start] != ' ') && (chunk[start] != '\t'))
552  break;
553  }
554  }
555 
556  // find the end
557  int end;
558  for (end = start; ((end < (len-1)) && (chunk[end] != 10)); end++);
559 
560  if ((chunk[end] != 10) && (len == 254)) {
561  more = true;
562  }
563  index += (end + 1);
564 
565  // reposition to next valid place to read
566  fDesc->seek(index, SEEK_SET);
567 
568  // clean up any trailing junk on line if we're at the end
569  if (!more) {
570  for (; end > start; end--) {
571  if ((chunk[end] != 10) && (chunk[end] != 13) && (chunk[end] != ' ') && (chunk[end] != '\t')) {
572  if (chunk[end] == '\\') {
573  more = true;
574  end--;
575  }
576  break;
577  }
578  }
579  }
580 
581  int size = (end - start) + 1;
582 
583  if (size > 0) {
584  // line.appendFormatted("%.*s", size, chunk+start);
585  line.append(chunk+start, size);
586  }
587  }
588  return ((len > 0) || line.length());
589 }
590 
591 
592 char FileMgr::isDirectory(const char *path) {
593 #ifndef WIN32
594  struct stat stats;
595  int error = stat(path, &stats);
596 #else
597  struct _stat stats;
598  int error = _wstat((const wchar_t *)utf8ToWChar(path).getRawData(), &stats);
599 #endif
600  if (error) return 0;
601  return ((stats.st_mode & S_IFDIR) == S_IFDIR);
602 }
603 
604 
605 long FileMgr::getFileSize(const char *path) {
606 #ifndef WIN32
607  struct stat stats;
608  int error = stat(path, &stats);
609 #else
610  struct _stat stats;
611  int error = _wstat((const wchar_t *)utf8ToWChar(path).getRawData(), &stats);
612 #endif
613  if (error) return 0;
614  return stats.st_size;
615 }
616 
617 
618 int FileMgr::copyDir(const char *srcDir, const char *destDir) {
619  SWBuf baseSrcPath = srcDir;
620  if (!baseSrcPath.endsWith("/") && !baseSrcPath.endsWith("\\")) baseSrcPath += "/";
621  SWBuf baseDestPath = destDir;
622  if (!baseDestPath.endsWith("/") && !baseDestPath.endsWith("\\")) baseDestPath += "/";
623  int retVal = 0;
624  std::vector<DirEntry> dirList = getDirList(srcDir);
625  for (unsigned int i = 0; i < dirList.size() && !retVal; ++i) {
626  SWBuf srcPath = baseSrcPath + dirList[i].name;
627  SWBuf destPath = baseDestPath + dirList[i].name;
628  if (!dirList[i].isDirectory) {
629  retVal = copyFile(srcPath.c_str(), destPath.c_str());
630  }
631  else {
632  retVal = copyDir(srcPath.c_str(), destPath.c_str());
633  }
634  }
635  return retVal;
636 }
637 
638 
639 int FileMgr::removeDir(const char *targetDir) {
640  SWBuf basePath = targetDir;
641  if (!basePath.endsWith("/") && !basePath.endsWith("\\")) basePath += "/";
642  std::vector<DirEntry> dirList = getDirList(targetDir);
643  for (unsigned int i = 0; i < dirList.size(); ++i) {
644  SWBuf targetPath = basePath + dirList[i].name;
645  if (!dirList[i].isDirectory) {
646  FileMgr::removeFile(targetPath.c_str());
647  }
648  else {
649  FileMgr::removeDir(targetPath.c_str());
650  }
651  }
652  FileMgr::removeFile(targetDir);
653  return 0;
654 }
655 
656 
658  FileDesc **loop;
659 
660  for (loop = &files; *loop; loop = &((*loop)->next)) {
661  if ((*loop)->fd > 0) {
662  (*loop)->offset = lseek((*loop)->fd, 0, SEEK_CUR);
663  ::close((*loop)->fd);
664  (*loop)->fd = -77;
665  }
666  }
667 }
668 
670  long count = 0;
671  FileDesc **loop;
672  for (loop = &files; *loop; loop = &((*loop)->next)) {
673  if ((*loop)->fd > 0) {
674  count++;
675  }
676  }
677  return count;
678 }
679 
680 
682 
683  // figure out 'home' directory for app data
684  SWBuf homeDir = getEnvValue("HOME");
685  if (!homeDir.length()) {
686  // silly windows
687  homeDir = getEnvValue("APPDATA");
688  }
689  if (homeDir.length()) {
690  if ((homeDir[homeDir.length()-1] != '\\') && (homeDir[homeDir.length()-1] != '/')) {
691  homeDir += "/";
692  }
693  }
694 
695  return homeDir;
696 }
697 
698 
700 
701 
static signed char existsFile(const char *ipath, const char *ifileName=0)
Definition: filemgr.cpp:337
bool isDirectory
Definition: filemgr.h:43
#define SWORD_NAMESPACE_START
Definition: defs.h:39
long seek(long offset, int whence)
Definition: filemgr.cpp:143
static int removeDir(const char *targetDir)
Definition: filemgr.cpp:639
FileDesc * open(const char *path, int mode, bool tryDowngrade)
Definition: filemgr.cpp:175
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
#define SEEK_CUR
Definition: zconf.h:245
unsigned long size
Definition: filemgr.h:42
#define S_IRGRP
Definition: filemgr.cpp:52
static signed char existsDir(const char *ipath, const char *idirName=0)
Definition: filemgr.cpp:357
static unsigned int RDONLY
Definition: filemgr.h:75
static SWBuf getEnvValue(const char *variableName)
Definition: filemgr.cpp:316
static int openFileReadOnly(const char *fName)
Definition: filemgr.cpp:474
int fd
Definition: filemgr.h:220
int perms
Definition: filemgr.h:251
SWBuf wcharToUTF8(const wchar_t *buf)
Definition: utilstr.cpp:263
static unsigned int RDWR
Definition: filemgr.h:76
#define S_IREAD
Definition: filemgr.cpp:70
static unsigned int TRUNC
Definition: filemgr.h:74
int mode
Definition: filemgr.h:248
static void closeFile(int fd)
Definition: filemgr.cpp:491
friend class FileDesc
Definition: filemgr.h:64
SWBuf utf8ToWChar(const char *buf)
Definition: utilstr.cpp:239
FileDesc(FileMgr *parent, const char *path, int mode, int perms, bool tryDowngrade)
Definition: filemgr.cpp:122
~FileMgr()
Definition: filemgr.cpp:164
virtual ~FileDesc()
Definition: filemgr.cpp:134
Definition: dirent.h:24
#define O_BINARY
Definition: filemgr.cpp:48
int getFd()
Definition: filemgr.h:231
char * path
Definition: filemgr.h:245
int maxFiles
Definition: filemgr.h:85
bool endsWith(const SWBuf &postfix) const
Definition: swbuf.h:501
long write(const void *buf, long count)
Definition: filemgr.cpp:153
signed char trunc(FileDesc *file)
Definition: filemgr.cpp:256
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
Definition: dirent.cpp:27
void close(FileDesc *file)
Definition: filemgr.cpp:196
char * getRawData()
Definition: swbuf.h:379
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
static int removeFile(const char *fName)
Definition: filemgr.cpp:517
SWDLLEXPORT void rewinddir(DIR *dir)
Definition: dirent.cpp:119
SWBuf name
Definition: filemgr.h:41
static int copyFile(const char *srcFile, const char *destFile)
Definition: filemgr.cpp:496
char * d_name
Definition: dirent.h:26
virtual void flush()
Definition: filemgr.cpp:657
static bool hasAccess(const char *path, int mode)
Definition: filemgr.cpp:327
static unsigned int APPEND
Definition: filemgr.h:73
#define S_IROTH
Definition: filemgr.cpp:56
SWDLLEXPORT DIR * opendir(const char *name)
Definition: dirent.cpp:35
SWDLLEXPORT struct dirent * readdir(DIR *dir)
Definition: dirent.cpp:99
int sysOpen(FileDesc *file)
Definition: filemgr.cpp:209
static int createParent(const char *pName)
Definition: filemgr.cpp:426
SWDLLEXPORT int closedir(DIR *dir)
Definition: dirent.cpp:76
long offset
Definition: filemgr.h:219
static std::vector< struct DirEntry > getDirList(const char *dirPath, bool includeSize=false, bool includeIsDirectory=true)
Definition: filemgr.cpp:379
static long write(int fd, const void *buf, long count)
Definition: filemgr.cpp:115
#define SEEK_SET
Definition: zconf.h:244
int size
Definition: regex.c:5043
static long getFileSize(const char *path)
Definition: filemgr.cpp:605
static unsigned int CREAT
Definition: filemgr.h:72
virtual long resourceConsumption()
Definition: filemgr.cpp:669
static void setSystemFileMgr(FileMgr *newFileMgr)
Definition: filemgr.cpp:109
static FileMgr * systemFileMgr
Definition: filemgr.h:70
static int createPathAndFile(const char *fName)
Definition: filemgr.cpp:479
static int copyDir(const char *srcDir, const char *destDir)
Definition: filemgr.cpp:618
#define S_IWRITE
Definition: filemgr.cpp:73
static unsigned int IWRITE
Definition: filemgr.h:79
static unsigned int WRONLY
Definition: filemgr.h:77
long read(void *buf, long count)
Definition: filemgr.cpp:148
static char getLine(FileDesc *fDesc, SWBuf &line)
Definition: filemgr.cpp:527
FileDesc * files
Definition: filemgr.h:67
static unsigned int IREAD
Definition: filemgr.h:78
static int openFile(const char *fName, int mode, int perms)
Definition: filemgr.cpp:463
FileDesc * next
Definition: filemgr.h:222
#define SWORD_NAMESPACE_END
Definition: defs.h:40
class __staticsystemFileMgr _staticsystemFileMgr
SWBuf getHomeDir()
Definition: filemgr.cpp:681
FileMgr(int maxFiles=35)
Definition: filemgr.cpp:158
FileMgr * parent
Definition: filemgr.h:221
bool tryDowngrade
Definition: filemgr.h:254
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
static char isDirectory(const char *path)
Definition: filemgr.cpp:592