HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_FileStat.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_FileStat.h (UT Library, C++)
7  *
8  * COMMENTS: Cross-platform method of obtaining file statistics
9  */
10 
11 #ifndef __UT_FILESTAT_H_INCLUDED__
12 #define __UT_FILESTAT_H_INCLUDED__
13 
14 #include "UT_API.h"
15 #include <SYS/SYS_Types.h>
16 #include <time.h>
17 
19 {
20 public:
21  enum FileType
22  {
26  SHORTCUT, // only on Windows
30  SPECIAL
31  };
32 
33  // The permission type stores read/write/execute permissions for the file.
34  // We define it as 'int' to match UTaccess.
35  typedef int PermissionType;
36 
37  UT_FileStat(FileType ftype = REGULAR,
38  int64 fsize = 0,
39  time_t f_atime = 0,
40  time_t f_ctime = 0,
41  time_t f_mtime = 0,
42  PermissionType f_permissions = 0777)
43  : myFileType(ftype)
44  , mySize(fsize)
45  , myAccessTime(f_atime)
46  , myCreateTime(f_ctime)
47  , myModTime(f_mtime)
48  , myPermissions(f_permissions)
49  {
50  }
51 
52  void
54  {
55  // On Windows, the _findfirst/_findnext functions silently convert 0
56  // FILETIME values to -1 if something bad happens. Things can then fail
57  // down the line because of this. So clamp these to 0. For an example,
58  // see bug #63178.
59  if (myAccessTime < 0)
60  myAccessTime = 0;
61  if (myCreateTime < 0)
62  myCreateTime = 0;
63  if (myModTime < 0)
64  myModTime = 0;
65  }
66 
67  bool isFile() const
68  { return myFileType == REGULAR || myFileType == EXECUTABLE; }
69 
72  time_t myAccessTime;
73  time_t myCreateTime;
74  time_t myModTime;
76 };
77 
78 /// Obtain file statistics. Returns 0 on success, else error code.
79 /// The UT_FileStat structure is only written-to when returning 0.
80 /// @{
81 UT_API int UTfileStat(const char *path, UT_FileStat *file_stat);
82 UT_API int UTfileFStat(int file_descriptor, UT_FileStat *file_stat);
83 /// @}
84 
85 #endif // __UT_FILESTAT_H_INCLUDED__
int PermissionType
Definition: UT_FileStat.h:35
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
PermissionType myPermissions
Definition: UT_FileStat.h:75
#define UT_API
Definition: UT_API.h:12
int64 mySize
Definition: UT_FileStat.h:71
long long int64
Definition: SYS_Types.h:100
time_t myAccessTime
Definition: UT_FileStat.h:72
time_t myCreateTime
Definition: UT_FileStat.h:73
UT_API int UTfileStat(const char *path, UT_FileStat *file_stat)
time_t myModTime
Definition: UT_FileStat.h:74
UT_API int UTfileFStat(int file_descriptor, UT_FileStat *file_stat)
UT_FileStat(FileType ftype=REGULAR, int64 fsize=0, time_t f_atime=0, time_t f_ctime=0, time_t f_mtime=0, PermissionType f_permissions=0777)
Definition: UT_FileStat.h:37
void fixInvalidTimestamps()
Definition: UT_FileStat.h:53
FileType myFileType
Definition: UT_FileStat.h:70
bool isFile() const
Definition: UT_FileStat.h:67