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 
783  const char * const *listAttributes() const;
784 
785 
788  bool getAttribute(const char *name, uint16_t *number) const;
789 
792  bool getAttribute(const char *name, uint32_t *number) const;
793 
796  bool getAttribute(const char *name, uint64_t *number) const;
797 
800  bool getAttribute(const char *name, int16_t *number) const;
801 
804  bool getAttribute(const char *name, int32_t *number) const;
805 
808  bool getAttribute(const char *name, int64_t *number) const;
809 
812  bool getAttribute(const char *name, float *number) const;
813 
816  bool getAttribute(const char *name, double *number) const;
817 
820  bool getAttribute(const char *name,
821  unsigned char *character) const;
822 
825  bool getAttribute(const char *name, char *character) const;
826 
829  bool getAttribute(const char *name, bool *value) const;
830 
835  bool getAttribute(const char *name,
836  unsigned char **string) const;
837 
842  bool getAttribute(const char *name,
843  char **string) const;
844 
850  bool getAttribute(const char *name,
851  unsigned char **string,
852  size_t *size) const;
853 
859  bool getAttribute(const char *name,
860  char **string, size_t *size) const;
861 
867  bool getAttribute(const char *name,
868  void **buffer, size_t *size) const;
869 
873  bool getAttribute(const char *name,
874  void *buffer, size_t size) const;
875 
876 
879  bool createAttribute(const char *name,
880  uint16_t number) const;
881 
884  bool createAttribute(const char *name,
885  uint32_t number) const;
886 
889  bool createAttribute(const char *name,
890  uint64_t number) const;
891 
894  bool createAttribute(const char *name, int16_t number) const;
895 
898  bool createAttribute(const char *name, int32_t number) const;
899 
902  bool createAttribute(const char *name, int64_t number) const;
903 
906  bool createAttribute(const char *name, float number) const;
907 
910  bool createAttribute(const char *name, double number) const;
911 
914  bool createAttribute(const char *name,
915  unsigned char character) const;
916 
919  bool createAttribute(const char *name, char character) const;
920 
923  bool createAttribute(const char *name, bool value) const;
924 
927  bool createAttribute(const char *name,
928  const unsigned char *string) const;
929 
932  bool createAttribute(const char *name,
933  const char *string) const;
934 
938  bool createAttribute(const char *name,
939  const unsigned char *string,
940  size_t size) const;
941 
945  bool createAttribute(const char *name,
946  const char *string, size_t size) const;
947 
951  bool createAttribute(const char *name,
952  const void *buffer, size_t size) const;
953 
954 
958  bool replaceAttribute(const char *name,
959  uint16_t number) const;
960 
964  bool replaceAttribute(const char *name,
965  uint32_t number) const;
966 
970  bool replaceAttribute(const char *name,
971  uint64_t number) const;
972 
976  bool replaceAttribute(const char *name,
977  int16_t number) const;
978 
982  bool replaceAttribute(const char *name,
983  int32_t number) const;
984 
988  bool replaceAttribute(const char *name,
989  int64_t number) const;
990 
994  bool replaceAttribute(const char *name, float number) const;
995 
999  bool replaceAttribute(const char *name, double number) const;
1000 
1004  bool replaceAttribute(const char *name,
1005  unsigned char character) const;
1006 
1010  bool replaceAttribute(const char *name,
1011  char character) const;
1012 
1016  bool replaceAttribute(const char *name, bool value) const;
1017 
1021  bool replaceAttribute(const char *name,
1022  const unsigned char *string) const;
1023 
1027  bool replaceAttribute(const char *name,
1028  const char *string) const;
1029 
1033  bool replaceAttribute(const char *name,
1034  const unsigned char *string,
1035  size_t size) const;
1036 
1040  bool replaceAttribute(const char *name,
1041  const char *string,
1042  size_t size) const;
1043 
1047  bool replaceAttribute(const char *name,
1048  const void *buffer,
1049  size_t size) const;
1050 
1051 
1055  bool setAttribute(const char *name,
1056  uint16_t number) const;
1057 
1061  bool setAttribute(const char *name,
1062  uint32_t number) const;
1063 
1067  bool setAttribute(const char *name,
1068  uint64_t number) const;
1069 
1073  bool setAttribute(const char *name, int16_t number) const;
1074 
1078  bool setAttribute(const char *name, int32_t number) const;
1079 
1083  bool setAttribute(const char *name, int64_t number) const;
1084 
1088  bool setAttribute(const char *name, float number) const;
1089 
1093  bool setAttribute(const char *name, double number) const;
1094 
1098  bool setAttribute(const char *name,
1099  unsigned char character) const;
1100 
1104  bool setAttribute(const char *name, char character) const;
1105 
1109  bool setAttribute(const char *name, bool value) const;
1110 
1114  bool setAttribute(const char *name,
1115  const unsigned char *string) const;
1116 
1120  bool setAttribute(const char *name,
1121  const char *string) const;
1122 
1127  bool setAttribute(const char *name,
1128  const unsigned char *string,
1129  size_t size) const;
1130 
1135  bool setAttribute(const char *name,
1136  const char *string,
1137  size_t size) const;
1138 
1143  bool setAttribute(const char *name,
1144  const void *buffer,
1145  size_t size) const;
1146 
1147 
1150  bool removeAttribute(const char *name) const;
1151 
1154  void *getInternalFileStatisticsStructure();
1155 
1159  static bool createFile(const char *name, mode_t perms);
1160 
1163  static bool createFifo(const char *filename, mode_t perms);
1164 
1167  static bool createPipe(filedescriptor *readfd,
1168  filedescriptor *writefd);
1169 
1178  static int32_t createTemporaryFile(char *templatefilename);
1179 
1182  static bool createHardLink(const char *oldpath,
1183  const char *newpath);
1184 
1188  static bool createSymbolicLink(const char *oldpath,
1189  const char *newpath);
1190 
1197  static char *resolveSymbolicLink(const char *filename);
1198 
1199 
1202  static bool rename(const char *oldpath,
1203  const char *newpath);
1204 
1207  static bool remove(const char *filename);
1208 
1209 
1212  static bool truncate(const char *filename);
1213 
1216  static bool truncate(const char *filename, off64_t length);
1217 
1218 
1228  static char *getContents(const char *name);
1229 
1237  static ssize_t getContents(const char *name,
1238  unsigned char *buffer,
1239  size_t buffersize);
1240 
1241 
1243  static bool exists(const char *filename);
1244 
1247  static bool readable(const char *filename);
1248 
1251  static bool writeable(const char *filename);
1252 
1255  static bool executable(const char *filename);
1256 
1265  static bool accessible(const char *filename, int32_t mode);
1266 
1272  static bool getLastChangeTime(const char *filename,
1273  time_t *ctime);
1274 
1277  static bool changeOwner(const char *filename,
1278  const char *newuser,
1279  const char *newgroup);
1280 
1283  static bool changeOwner(const char *filename,
1284  uid_t uid, gid_t gid);
1285 
1288  static bool canChangeOwner(const char *filename);
1289 
1290 
1294  static bool setLastAccessTime(const char *filename,
1295  time_t lastaccesstime);
1296 
1300  static bool setLastModificationTime(const char *filename,
1301  time_t lastmodtime);
1302 
1307  static bool setLastAccessAndModificationTimes(
1308  const char *filename,
1309  time_t lastaccesstime,
1310  time_t lastmodtime);
1311 
1315  static bool setLastAccessAndModificationTimes(
1316  const char *filename);
1317 
1318 
1323  static char *dirname(const char *filename);
1324 
1328  static char *basename(const char *filename);
1329 
1335  static char *basename(const char *filename,
1336  const char *suffix);
1337 
1343  static char *eightDotThree(const char *filename);
1344 
1345 
1351  static key_t generateKey(const char *filename, int32_t id);
1352 
1355  static int64_t maxLinks(const char *filename);
1356 
1357  #include <rudiments/private/file.h>
1358 };
1359 
1360 #endif