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 #ifdef RUDIMENTS_NAMESPACE
10 namespace rudiments {
11 #endif
12 
13 class fileprivate;
14 
25 class RUDIMENTS_DLLSPEC file : public filedescriptor {
26  public:
27 
29  file();
30 
33  file(const file &f);
34 
37  file &operator=(const file &f);
38 
40  virtual ~file();
41 
44  bool open(const char *name, int32_t flags);
45 
50  bool open(const char *name, int32_t flags, mode_t perms);
51 
55  bool create(const char *name, mode_t perms);
56 
61  ssize_t create(const char *name, mode_t perms, uint16_t number);
62 
67  ssize_t create(const char *name, mode_t perms,
68  unsigned long number);
69 
74  ssize_t create(const char *name, mode_t perms, float number);
75 
80  ssize_t create(const char *name, mode_t perms, double number);
81 
86  ssize_t create(const char *name, mode_t perms, char number);
87 
92  ssize_t create(const char *name, mode_t perms,
93  const char *string);
94 
100  ssize_t create(const char *name, mode_t perms,
101  const char *string, size_t size);
102 
108  ssize_t create(const char *name, mode_t perms,
109  const void *data, size_t size);
110 
111 
121  char *getContents();
122 
130  ssize_t getContents(unsigned char *buffer, size_t buffersize);
131 
132 
136  bool truncate() const;
137 
141  bool truncate(off64_t length) const;
142 
143 
147  off64_t getCurrentPosition() const;
148 
152  off64_t setPositionRelativeToBeginning(off64_t offset) const;
153 
157  off64_t setPositionRelativeToCurrent(off64_t offset) const;
158 
166  off64_t setPositionRelativeToEnd(off64_t offset) const;
167 
171  bool tryLockFile(int16_t type) const;
172 
177  bool lockFile(int16_t type) const;
178 
193  bool checkLockFile(int16_t type,
194  int16_t *conftype,
195  int16_t *confwhence,
196  off64_t *confstart,
197  off64_t *conflen) const;
198 
201  bool unlockFile() const;
202 
208  bool tryLockRegion(int16_t type, off64_t start,
209  off64_t len) const;
210 
216  bool lockRegion(int16_t type, off64_t start,
217  off64_t len) const;
218 
234  bool checkLockRegion(int16_t type,
235  off64_t start,
236  off64_t len,
237  int16_t *conftype,
238  int16_t *confwhence,
239  off64_t *confstart,
240  off64_t *conflen) const;
241 
246  bool unlockRegion(off64_t start, off64_t len) const;
247 
252  bool tryLockFromCurrent(int16_t type, off64_t len) const;
253 
259  bool tryLockFromCurrent(int16_t type, off64_t start,
260  off64_t len) const;
261 
267  bool lockFromCurrent(int16_t type, off64_t len) const;
268 
274  bool lockFromCurrent(int16_t type, off64_t start,
275  off64_t len) const;
276 
291  bool checkLockFromCurrent(int16_t type, off64_t len,
292  int16_t *conftype,
293  int16_t *confwhence,
294  off64_t *confstart,
295  off64_t *conflen) const;
296 
312  bool checkLockFromCurrent(int16_t type, off64_t start,
313  off64_t len,
314  int16_t *conftype,
315  int16_t *confwhence,
316  off64_t *confstart,
317  off64_t *conflen) const;
318 
322  bool unlockFromCurrent(off64_t len) const;
323 
328  bool unlockFromCurrent(off64_t start, off64_t len) const;
329 
334  bool tryLockFromEnd(int16_t type, off64_t len) const;
335 
341  bool tryLockFromEnd(int16_t type, off64_t start,
342  off64_t len) const;
343 
349  bool lockFromEnd(int16_t type, off64_t len) const;
350 
356  bool lockFromEnd(int16_t type, off64_t start,
357  off64_t len) const;
358 
373  bool checkLockFromEnd(int16_t type, off64_t len,
374  int16_t *conftype,
375  int16_t *confwhence,
376  off64_t *confstart,
377  off64_t *conflen) const;
378 
394  bool checkLockFromEnd(int16_t type, off64_t start,
395  off64_t len,
396  int16_t *conftype,
397  int16_t *confwhence,
398  off64_t *confstart,
399  off64_t *conflen) const;
400 
404  bool unlockFromEnd(off64_t len) const;
405 
410  bool unlockFromEnd(off64_t start, off64_t len) const;
411 
417  bool tryLockRemainder(int16_t type, off64_t start) const;
418 
424  bool lockRemainder(int16_t type, off64_t start) const;
425 
441  bool checkLockRemainder(int16_t type, off64_t start,
442  int16_t *conftype,
443  int16_t *confwhence,
444  off64_t *confstart,
445  off64_t *conflen) const;
446 
451  bool unlockRemainder(off64_t start) const;
452 
457  bool tryLockRemainderFromCurrent(int16_t type) const;
458 
463  bool tryLockRemainderFromCurrent(int16_t type,
464  off64_t start) const;
465 
470  bool lockRemainderFromCurrent(int16_t type) const;
471 
477  bool lockRemainderFromCurrent(int16_t type,
478  off64_t start) const;
479 
494  bool checkLockRemainderFromCurrent(int16_t type,
495  int16_t *conftype,
496  int16_t *confwhence,
497  off64_t *confstart,
498  off64_t *conflen) const;
499 
515  bool checkLockRemainderFromCurrent(int16_t type,
516  off64_t start,
517  int16_t *conftype,
518  int16_t *confwhence,
519  off64_t *confstart,
520  off64_t *conflen) const;
521 
525  bool unlockRemainderFromCurrent() const;
526 
531  bool unlockRemainderFromCurrent(off64_t start) const;
532 
537  bool tryLockRemainderFromEnd(int16_t type) const;
538 
543  bool tryLockRemainderFromEnd(int16_t type,
544  off64_t start) const;
545 
550  bool lockRemainderFromEnd(int16_t type) const;
551 
556  bool lockRemainderFromEnd(int16_t type, off64_t start) const;
557 
572  bool checkLockRemainderFromEnd(int16_t type,
573  int16_t *conftype,
574  int16_t *confwhence,
575  off64_t *confstart,
576  off64_t *conflen) const;
577 
592  bool checkLockRemainderFromEnd(int16_t type,
593  off64_t start,
594  int16_t *conftype,
595  int16_t *confwhence,
596  off64_t *confstart,
597  off64_t *conflen) const;
598 
602  bool unlockRemainderFromEnd() const;
603 
607  bool unlockRemainderFromEnd(off64_t start) const;
608 
609 
619  bool sequentialAccess(off64_t start, size_t len) const;
620 
630  bool randomAccess(off64_t start, size_t len) const;
631 
641  bool onlyOnce(off64_t start, size_t len) const;
642 
652  bool willNeed(off64_t start, size_t len) const;
653 
663  bool wontNeed(off64_t start, size_t len) const;
664 
674  bool normalAccess(off64_t start, size_t len) const;
675 
676 
684  bool reserve(off64_t start, size_t len) const;
685 
686 
699  bool sync() const;
700 
716  bool dataSync() const;
717 
718 
723  void dontGetCurrentPropertiesOnOpen();
724 
734  void getCurrentPropertiesOnOpen();
735 
740  bool getCurrentProperties();
741 
743  mode_t getPermissions() const;
744 
746  uid_t getOwnerUserId() const;
747 
749  gid_t getOwnerGroupId() const;
750 
752  off64_t getSize() const;
753 
757  blksize_t getBlockSize() const;
758 
761  blkcnt_t getBlockCount() const;
762 
765  int32_t isSocket() const;
766 
769  int32_t isSymbolicLink() const;
770 
773  int32_t isRegularFile() const;
774 
777  int32_t isBlockDevice() const;
778 
781  int32_t isDirectory() const;
784  int32_t isCharacterDevice() const;
785 
788  int32_t isFifo() const;
789 
791  time_t getLastAccessTime() const;
792 
797  time_t getLastModificationTime() const;
798 
803  time_t getLastChangeTime() const;
804 
806  dev_t getDevice() const;
807 
809  dev_t getDeviceType() const;
810 
812  ino_t getInode() const;
813 
815  nlink_t getNumberOfHardLinks() const;
816 
817 
820  bool changeOwner(const char *newuser,
821  const char *newgroup) const;
822 
825  bool changeOwner(uid_t uid, gid_t gid) const;
826 
829  bool changeOwnerUser(const char *newuser) const;
830 
833  bool changeOwnerUser(uid_t uid) const;
834 
837  bool changeOwnerGroup(const char *newgroup) const;
838 
841  bool changeOwnerGroup(gid_t gid) const;
842 
846  bool canChangeOwner() const;
847 
850  long maxLinks() const;
851 
852 
858  const char * const *listAttributes() const;
859 
860 
863  bool getAttribute(const char *name,
864  uint16_t *number) const;
865 
868  bool getAttribute(const char *name,
869  unsigned long *number) const;
870 
873  bool getAttribute(const char *name, int16_t *number) const;
874 
877  bool getAttribute(const char *name, long *number) const;
878 
881  bool getAttribute(const char *name, float *number) const;
882 
885  bool getAttribute(const char *name, double *number) const;
886 
889  bool getAttribute(const char *name,
890  unsigned char *character) const;
891 
894  bool getAttribute(const char *name, char *character) const;
895 
898  bool getAttribute(const char *name, bool *value) const;
899 
904  bool getAttribute(const char *name,
905  unsigned char **string) const;
906 
911  bool getAttribute(const char *name,
912  char **string) const;
913 
919  bool getAttribute(const char *name,
920  unsigned char **string,
921  size_t *size) const;
922 
928  bool getAttribute(const char *name,
929  char **string, size_t *size) const;
930 
936  bool getAttribute(const char *name,
937  void **buffer, size_t *size) const;
938 
939 
942  bool createAttribute(const char *name,
943  uint16_t number) const;
944 
947  bool createAttribute(const char *name,
948  unsigned long number) const;
949 
952  bool createAttribute(const char *name, int16_t number) const;
953 
956  bool createAttribute(const char *name, long number) const;
957 
960  bool createAttribute(const char *name, float number) const;
961 
964  bool createAttribute(const char *name, double number) const;
965 
968  bool createAttribute(const char *name,
969  unsigned char character) const;
970 
973  bool createAttribute(const char *name, char character) const;
974 
977  bool createAttribute(const char *name, bool value) const;
978 
981  bool createAttribute(const char *name,
982  const unsigned char *string) const;
983 
986  bool createAttribute(const char *name,
987  const char *string) const;
988 
992  bool createAttribute(const char *name,
993  const unsigned char *string,
994  size_t size) const;
995 
999  bool createAttribute(const char *name,
1000  const char *string, size_t size) const;
1001 
1005  bool createAttribute(const char *name,
1006  const void *buffer, size_t size) const;
1007 
1008 
1012  bool replaceAttribute(const char *name,
1013  uint16_t number) const;
1014 
1018  bool replaceAttribute(const char *name,
1019  unsigned long number) const;
1020 
1024  bool replaceAttribute(const char *name,
1025  int16_t number) const;
1026 
1030  bool replaceAttribute(const char *name, long number) const;
1031 
1035  bool replaceAttribute(const char *name, float number) const;
1036 
1040  bool replaceAttribute(const char *name, double number) const;
1041 
1045  bool replaceAttribute(const char *name,
1046  unsigned char character) const;
1047 
1051  bool replaceAttribute(const char *name,
1052  char character) const;
1053 
1057  bool replaceAttribute(const char *name, bool value) const;
1058 
1062  bool replaceAttribute(const char *name,
1063  const unsigned char *string) const;
1064 
1068  bool replaceAttribute(const char *name,
1069  const char *string) const;
1070 
1074  bool replaceAttribute(const char *name,
1075  const unsigned char *string,
1076  size_t size) const;
1077 
1081  bool replaceAttribute(const char *name,
1082  const char *string,
1083  size_t size) const;
1084 
1088  bool replaceAttribute(const char *name,
1089  const void *buffer,
1090  size_t size) const;
1091 
1092 
1096  bool setAttribute(const char *name,
1097  uint16_t number) const;
1098 
1102  bool setAttribute(const char *name,
1103  unsigned long number) const;
1104 
1108  bool setAttribute(const char *name, int16_t number) const;
1109 
1113  bool setAttribute(const char *name, long number) const;
1114 
1118  bool setAttribute(const char *name, float number) const;
1119 
1123  bool setAttribute(const char *name, double number) const;
1124 
1128  bool setAttribute(const char *name,
1129  unsigned char character) const;
1130 
1134  bool setAttribute(const char *name, char character) const;
1135 
1139  bool setAttribute(const char *name, bool value) const;
1140 
1144  bool setAttribute(const char *name,
1145  const unsigned char *string) const;
1146 
1150  bool setAttribute(const char *name,
1151  const char *string) const;
1152 
1157  bool setAttribute(const char *name,
1158  const unsigned char *string,
1159  size_t size) const;
1160 
1165  bool setAttribute(const char *name,
1166  const char *string,
1167  size_t size) const;
1168 
1173  bool setAttribute(const char *name,
1174  const void *buffer,
1175  size_t size) const;
1176 
1177 
1180  bool removeAttribute(const char *name) const;
1181 
1184  void *getInternalFileStatisticsStructure();
1185 
1186 
1190  static bool createFile(const char *name, mode_t perms);
1191 
1197  static ssize_t createFile(const char *name,
1198  mode_t perms,
1199  uint16_t number);
1200 
1206  static ssize_t createFile(const char *name,
1207  mode_t perms,
1208  unsigned long number);
1209 
1215  static ssize_t createFile(const char *name,
1216  mode_t perms,
1217  float number);
1218 
1224  static ssize_t createFile(const char *name,
1225  mode_t perms,
1226  double number);
1227 
1233  static ssize_t createFile(const char *name,
1234  mode_t perms,
1235  char number);
1236 
1242  static ssize_t createFile(const char *name,
1243  mode_t perms,
1244  const char *string);
1245 
1251  static ssize_t createFile(const char *name,
1252  mode_t perms,
1253  const char *string,
1254  size_t size);
1255 
1261  static ssize_t createFile(const char *name,
1262  mode_t perms,
1263  const void *data,
1264  size_t size);
1265 
1266 
1269  static bool createFifo(const char *filename, mode_t perms);
1270 
1273  static bool createPipe(filedescriptor *readfd,
1274  filedescriptor *writefd);
1275 
1284  static int32_t createTemporaryFile(char *templatefilename);
1285 
1288  static bool createHardLink(const char *oldpath,
1289  const char *newpath);
1290 
1294  static bool createSymbolicLink(const char *oldpath,
1295  const char *newpath);
1296 
1303  static char *resolveSymbolicLink(const char *filename);
1304 
1305 
1308  static bool rename(const char *oldpath,
1309  const char *newpath);
1310 
1313  static bool remove(const char *filename);
1314 
1315 
1318  static bool truncate(const char *filename);
1319 
1322  static bool truncate(const char *filename, off64_t length);
1323 
1324 
1334  static char *getContents(const char *name);
1335 
1343  static ssize_t getContents(const char *name,
1344  unsigned char *buffer,
1345  size_t buffersize);
1346 
1347 
1349  static bool exists(const char *filename);
1350 
1353  static bool readable(const char *filename);
1354 
1357  static bool writeable(const char *filename);
1358 
1361  static bool executable(const char *filename);
1362 
1371  static bool accessible(const char *filename, int32_t mode);
1372 
1373 
1376  static bool getPermissions(const char *filename,
1377  mode_t *perms);
1378 
1381  static bool getOwnerUserId(const char *filename,
1382  uid_t *uid);
1383 
1386  static bool getOwnerGroupId(const char *filename,
1387  gid_t *gid);
1388 
1391  static bool getSize(const char *filename,
1392  off64_t *size);
1393 
1397  static bool getBlockSize(const char *filename,
1398  blksize_t *size);
1399 
1403  static bool getBlockCount(const char *filename,
1404  blkcnt_t *blocks);
1405 
1408  static int32_t isSocket(const char *filename);
1409 
1412  static int32_t isSymbolicLink(const char *filename);
1413 
1416  static int32_t isRegularFile(const char *filename);
1417 
1420  static int32_t isBlockDevice(const char *filename);
1421 
1424  static int32_t isDirectory(const char *filename);
1425 
1428  static int32_t isCharacterDevice(const char *filename);
1429 
1432  static int32_t isFifo(const char *filename);
1433 
1436  static bool getLastAccessTime(const char *filename,
1437  time_t *atime);
1438 
1444  static bool getLastModificationTime(const char *filename,
1445  time_t *mtime);
1446 
1452  static bool getLastChangeTime(const char *filename,
1453  time_t *ctime);
1454 
1457  static bool getDevice(const char *filename, dev_t *dev);
1458 
1461  static bool getDeviceType(const char *filename,
1462  dev_t *devtype);
1463 
1466  static bool getInode(const char *filename, ino_t *inode);
1467 
1470  static bool getNumberOfHardLinks(const char *filename,
1471  nlink_t *nlink);
1472 
1475  static bool changeOwner(const char *filename,
1476  const char *newuser,
1477  const char *newgroup);
1478 
1481  static bool changeOwner(const char *filename,
1482  uid_t uid, gid_t gid);
1483 
1486  static bool changeOwnerUser(const char *filename,
1487  const char *newuser);
1488 
1491  static bool changeOwnerUser(const char *filename,
1492  uid_t uid);
1493 
1496  static bool changeOwnerGroup(const char *filename,
1497  const char *newgroup);
1498 
1501  static bool changeOwnerGroup(const char *filename,
1502  gid_t gid);
1503 
1506  static bool canChangeOwner(const char *filename);
1507 
1508 
1512  static bool setLastAccessTime(const char *filename,
1513  time_t lastaccesstime);
1514 
1518  static bool setLastModificationTime(const char *filename,
1519  time_t lastmodtime);
1520 
1525  static bool setLastAccessAndModificationTimes(
1526  const char *filename,
1527  time_t lastaccesstime,
1528  time_t lastmodtime);
1529 
1533  static bool setLastAccessAndModificationTimes(
1534  const char *filename);
1535 
1536 
1541  static char *dirname(const char *filename);
1542 
1546  static char *basename(const char *filename);
1547 
1553  static char *basename(const char *filename,
1554  const char *suffix);
1555 
1556 
1562  static key_t generateKey(const char *filename, int32_t id);
1563 
1566  static long maxLinks(const char *filename);
1567 
1568  #include <rudiments/private/file.h>
1569 };
1570 
1571 #ifdef RUDIMENTS_NAMESPACE
1572 }
1573 #endif
1574 
1575 #endif