Rudiments
file.h
1 // Copyright (c) 2002 David Muse
2 // See the COPYING file for more information.
3 
4 #ifndef RUDIMENTS_FILE_H
5 #define RUDIMENTS_FILE_H
6 
7 #include <rudiments/private/fileincludes.h>
8 
9 class fileprivate;
10 
21 class RUDIMENTS_DLLSPEC file : public filedescriptor {
22  public:
23 
25  file();
26 
29  file(const file &f);
30 
33  file &operator=(const file &f);
34 
36  virtual ~file();
37 
40  bool open(const char *name, int32_t flags);
41 
46  bool open(const char *name, int32_t flags, mode_t perms);
47 
51  bool create(const char *name, mode_t perms);
52 
62  char *getContents();
63 
71  ssize_t getContents(unsigned char *buffer, size_t buffersize);
72 
73 
77  bool truncate() const;
78 
82  bool truncate(off64_t length) const;
83 
84 
88  off64_t getCurrentPosition() const;
89 
93  off64_t setPositionRelativeToBeginning(off64_t offset) const;
94 
98  off64_t setPositionRelativeToCurrent(off64_t offset) const;
99 
107  off64_t setPositionRelativeToEnd(off64_t offset) const;
108 
112  bool tryLockFile(int16_t type) const;
113 
118  bool lockFile(int16_t type) const;
119 
134  bool checkLockFile(int16_t type,
135  int16_t *conftype,
136  int16_t *confwhence,
137  off64_t *confstart,
138  off64_t *conflen) const;
139 
142  bool unlockFile() const;
143 
149  bool tryLockRegion(int16_t type, off64_t start,
150  off64_t len) const;
151 
157  bool lockRegion(int16_t type, off64_t start,
158  off64_t len) const;
159 
175  bool checkLockRegion(int16_t type,
176  off64_t start,
177  off64_t len,
178  int16_t *conftype,
179  int16_t *confwhence,
180  off64_t *confstart,
181  off64_t *conflen) const;
182 
187  bool unlockRegion(off64_t start, off64_t len) const;
188 
193  bool tryLockFromCurrent(int16_t type, off64_t len) const;
194 
200  bool tryLockFromCurrent(int16_t type, off64_t start,
201  off64_t len) const;
202 
208  bool lockFromCurrent(int16_t type, off64_t len) const;
209 
215  bool lockFromCurrent(int16_t type, off64_t start,
216  off64_t len) const;
217 
232  bool checkLockFromCurrent(int16_t type, off64_t len,
233  int16_t *conftype,
234  int16_t *confwhence,
235  off64_t *confstart,
236  off64_t *conflen) const;
237 
253  bool checkLockFromCurrent(int16_t type, off64_t start,
254  off64_t len,
255  int16_t *conftype,
256  int16_t *confwhence,
257  off64_t *confstart,
258  off64_t *conflen) const;
259 
263  bool unlockFromCurrent(off64_t len) const;
264 
269  bool unlockFromCurrent(off64_t start, off64_t len) const;
270 
275  bool tryLockFromEnd(int16_t type, off64_t len) const;
276 
282  bool tryLockFromEnd(int16_t type, off64_t start,
283  off64_t len) const;
284 
290  bool lockFromEnd(int16_t type, off64_t len) const;
291 
297  bool lockFromEnd(int16_t type, off64_t start,
298  off64_t len) const;
299 
314  bool checkLockFromEnd(int16_t type, off64_t len,
315  int16_t *conftype,
316  int16_t *confwhence,
317  off64_t *confstart,
318  off64_t *conflen) const;
319 
335  bool checkLockFromEnd(int16_t type, off64_t start,
336  off64_t len,
337  int16_t *conftype,
338  int16_t *confwhence,
339  off64_t *confstart,
340  off64_t *conflen) const;
341 
345  bool unlockFromEnd(off64_t len) const;
346 
351  bool unlockFromEnd(off64_t start, off64_t len) const;
352 
358  bool tryLockRemainder(int16_t type, off64_t start) const;
359 
365  bool lockRemainder(int16_t type, off64_t start) const;
366 
382  bool checkLockRemainder(int16_t type, off64_t start,
383  int16_t *conftype,
384  int16_t *confwhence,
385  off64_t *confstart,
386  off64_t *conflen) const;
387 
392  bool unlockRemainder(off64_t start) const;
393 
398  bool tryLockRemainderFromCurrent(int16_t type) const;
399 
404  bool tryLockRemainderFromCurrent(int16_t type,
405  off64_t start) const;
406 
411  bool lockRemainderFromCurrent(int16_t type) const;
412 
418  bool lockRemainderFromCurrent(int16_t type,
419  off64_t start) const;
420 
435  bool checkLockRemainderFromCurrent(int16_t type,
436  int16_t *conftype,
437  int16_t *confwhence,
438  off64_t *confstart,
439  off64_t *conflen) const;
440 
456  bool checkLockRemainderFromCurrent(int16_t type,
457  off64_t start,
458  int16_t *conftype,
459  int16_t *confwhence,
460  off64_t *confstart,
461  off64_t *conflen) const;
462 
466  bool unlockRemainderFromCurrent() const;
467 
472  bool unlockRemainderFromCurrent(off64_t start) const;
473 
478  bool tryLockRemainderFromEnd(int16_t type) const;
479 
484  bool tryLockRemainderFromEnd(int16_t type,
485  off64_t start) const;
486 
491  bool lockRemainderFromEnd(int16_t type) const;
492 
497  bool lockRemainderFromEnd(int16_t type, off64_t start) const;
498 
513  bool checkLockRemainderFromEnd(int16_t type,
514  int16_t *conftype,
515  int16_t *confwhence,
516  off64_t *confstart,
517  off64_t *conflen) const;
518 
533  bool checkLockRemainderFromEnd(int16_t type,
534  off64_t start,
535  int16_t *conftype,
536  int16_t *confwhence,
537  off64_t *confstart,
538  off64_t *conflen) const;
539 
543  bool unlockRemainderFromEnd() const;
544 
548  bool unlockRemainderFromEnd(off64_t start) const;
549 
550 
560  bool sequentialAccess(off64_t start, size_t len) const;
561 
571  bool randomAccess(off64_t start, size_t len) const;
572 
582  bool onlyOnce(off64_t start, size_t len) const;
583 
593  bool willNeed(off64_t start, size_t len) const;
594 
604  bool wontNeed(off64_t start, size_t len) const;
605 
615  bool normalAccess(off64_t start, size_t len) const;
616 
617 
625  bool reserve(off64_t start, size_t len) const;
626 
627 
640  bool sync() const;
641 
657  bool dataSync() const;
658 
659 
664  void dontGetCurrentPropertiesOnOpen();
665 
675  void getCurrentPropertiesOnOpen();
676 
681  bool getCurrentProperties();
682 
684  mode_t getPermissions() const;
685 
687  uid_t getOwnerUserId() const;
688 
690  gid_t getOwnerGroupId() const;
691 
693  off64_t getSize() const;
694 
698  blksize_t getBlockSize() const;
699 
702  blkcnt_t getBlockCount() const;
703 
706  int32_t isSocket() const;
707 
710  int32_t isSymbolicLink() const;
711 
714  int32_t isRegularFile() const;
715 
718  int32_t isBlockDevice() const;
719 
722  int32_t isDirectory() const;
725  int32_t isCharacterDevice() const;
726 
729  int32_t isFifo() const;
730 
732  time_t getLastAccessTime() const;
733 
738  time_t getLastModificationTime() const;
739 
744  time_t getLastChangeTime() const;
745 
747  dev_t getDevice() const;
748 
750  dev_t getDeviceType() const;
751 
753  uint64_t getInode() const;
754 
756  nlink_t getNumberOfHardLinks() const;
757 
758 
761  bool changeOwner(const char *newuser,
762  const char *newgroup) const;
763 
766  bool changeOwner(uid_t uid, gid_t gid) const;
767 
771  bool canChangeOwner() const;
772 
775  int64_t maxLinks() const;
776 
777 
780  void *getInternalFileStatisticsStructure();
781 
782 
786  static bool createFile(const char *name, mode_t perms);
787 
790  static bool createFifo(const char *filename, mode_t perms);
791 
794  static bool createPipe(filedescriptor *readfd,
795  filedescriptor *writefd);
796 
805  static int32_t createTemporaryFile(char *templatefilename);
806 
809  static bool createHardLink(const char *oldpath,
810  const char *newpath);
811 
815  static bool createSymbolicLink(const char *oldpath,
816  const char *newpath);
817 
824  static char *resolveSymbolicLink(const char *filename);
825 
826 
829  static bool rename(const char *oldpath,
830  const char *newpath);
831 
834  static bool remove(const char *filename);
835 
836 
839  static bool truncate(const char *filename);
840 
843  static bool truncate(const char *filename, off64_t length);
844 
845 
855  static char *getContents(const char *name);
856 
864  static ssize_t getContents(const char *name,
865  unsigned char *buffer,
866  size_t buffersize);
867 
868 
870  static bool exists(const char *filename);
871 
874  static bool readable(const char *filename);
875 
878  static bool writeable(const char *filename);
879 
882  static bool executable(const char *filename);
883 
892  static bool accessible(const char *filename, int32_t mode);
893 
899  static bool getLastChangeTime(const char *filename,
900  time_t *ctime);
901 
904  static bool changeOwner(const char *filename,
905  const char *newuser,
906  const char *newgroup);
907 
910  static bool changeOwner(const char *filename,
911  uid_t uid, gid_t gid);
912 
915  static bool canChangeOwner(const char *filename);
916 
917 
921  static bool setLastAccessTime(const char *filename,
922  time_t lastaccesstime);
923 
927  static bool setLastModificationTime(const char *filename,
928  time_t lastmodtime);
929 
934  static bool setLastAccessAndModificationTimes(
935  const char *filename,
936  time_t lastaccesstime,
937  time_t lastmodtime);
938 
942  static bool setLastAccessAndModificationTimes(
943  const char *filename);
944 
945 
950  static char *dirname(const char *filename);
951 
955  static char *basename(const char *filename);
956 
962  static char *basename(const char *filename,
963  const char *suffix);
964 
970  static char *eightDotThree(const char *filename);
971 
972 
978  static key_t generateKey(const char *filename, int32_t id);
979 
982  static int64_t maxLinks(const char *filename);
983 
984  #include <rudiments/private/file.h>
985 };
986 
987 #endif
Definition: file.h:21
filedescriptor & operator=(const filedescriptor &f)
Definition: filedescriptor.h:14