HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_DirUtil.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_DirUtil.C (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef _UT_DIRUTIL_H_
12 #define _UT_DIRUTIL_H_
13 
14 #include "UT_API.h"
15 #include "UT_FileStat.h"
16 #include <SYS/SYS_Deprecated.h>
17 
18 #include <time.h>
19 
20 class UT_FileStat;
21 class UT_String;
22 class UT_StringArray;
23 class UT_StringHolder;
24 
25 UT_API int UTunixFullPathSpecified(const char *name);
26 UT_API int UTfullPathSpecified(const char *name);
27 // This, unlike, UTfullPathSpecified, returns false for ./filename
28 UT_API bool UTisAbsolutePath(const char *filename);
29 UT_API bool UTisRootPath(const char *filename);
30 
31 /// UTgetRootPrefixLength() returns the length of the root part of the file
32 /// path.
33 ///
34 /// The remainder of the file path after the root part length will have
35 /// one of the following forms:
36 /// '/path/to/file' => for absolute paths
37 /// 'relative/path/to/file' => for relative paths
38 /// '' => for root paths
39 ///
40 /// Some examples of input file paths and output root lengths:
41 /// '/path/to/file' => 0
42 /// 'relative/path/to/file' => 0
43 /// 'C:/path/to/file' => 2 (Windows only)
44 /// 'C:relative/path/to/file' => 2 (Windows only)
45 /// '//path/to/file' => 1 (Windows only)
46 /// '//path/to/file' => 0 (Unix only)
47 /// 'file:///path/to/file' => 5
48 /// 'file:/path/to/file' => 5
49 /// 'file:relative/path/to/file'=> 5
50 UT_API int UTgetRootPrefixLength(const char *filename);
51 
53  const char *basepath = nullptr);
55  const char *basepath = nullptr);
57 UT_API void UTaddAbsolutePathPrefix(const char *prefix);
58 
59 // Please pass in just the filename and not the entire path.
60 UT_API bool UTisHiddenFile(const char *filename);
61 
62 /// Returns true if the given path is a readable, _regular_ file, ie. not a
63 /// directory.
64 UT_API bool UTisValidRegularFile(const char *path);
65 
66 /// Returns true if the given path is a readable _directory_.
67 UT_API bool UTisValidDirectory(const char *path);
68 
69 /// Returns true if path is a _directory_, without permission checks
70 UT_API bool UTisDirectory(const char *path);
71 
72 /// Returns true if path is a _regular_ file, without permission checks
73 UT_API bool UTisRegularFile(const char *path);
74 
75 /// Returns true if file path exists, without permission checks.
76 /// This is optimized for known platforms.
77 UT_API bool UTfileExists(const char *path);
78 
79 #ifdef WIN32
80  #include <sys/types.h>
81  #include <direct.h>
82  #include <errno.h>
83 
84  // Define dummy value to compare with errno in assertions related
85  // to Linux libraries and large file systems. This define now exists on
86  // newer versions of Visual Studio. The current value is defined to be the
87  // same as the one found in VC10.
88  #ifndef EOVERFLOW
89  #define EOVERFLOW 132
90  #endif
91 
92  typedef void* DIR;
93  struct dirent {
94  char *d_name;
95  };
96  UT_API DIR *opendir( const char *name );
97  UT_API struct dirent *readdir( DIR *dirp );
98  UT_API void closedir( DIR *dirp );
99 
100  /// Get the current working directory
101  UT_API char *getUnixCwd( char *buffer, int maxlen );
102 #else
103  #include <sys/types.h>
104  #include <sys/stat.h>
105  #include <string.h>
106  #include <dirent.h>
107  #include <unistd.h>
108  #include <stdlib.h>
109 
110  /// Get the current working directory
111  UT_API char *getUnixCwd( char *buffer, int maxlen );
112 #endif
113 
114 /// Do the equivalent of a stat on the last file from readdir or opendir.
115 UT_API int statLastRead(DIR *dirp, const char *path, UT_FileStat &file_stat);
116 
117 #endif
118 
GT_API const UT_StringHolder filename
UT_API bool UTisHiddenFile(const char *filename)
UT_API int UTunixFullPathSpecified(const char *name)
UT_API bool UTisRootPath(const char *filename)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
UT_API const UT_StringArray & UTgetAbsolutePathPrefixes()
#define UT_API
Definition: UT_API.h:13
UT_API bool UTisValidDirectory(const char *path)
Returns true if the given path is a readable directory.
UT_API int UTgetRootPrefixLength(const char *filename)
GLuint buffer
Definition: glcorearb.h:659
UT_API void UTmakeAbsoluteFilePath(UT_String &path, const char *basepath=nullptr)
UT_API int UTfullPathSpecified(const char *name)
GLuint const GLchar * name
Definition: glcorearb.h:785
UT_API bool UTfileExists(const char *path)
UT_API void UTaddAbsolutePathPrefix(const char *prefix)
UT_API bool UTisRegularFile(const char *path)
Returns true if path is a regular file, without permission checks.
UT_API char * getUnixCwd(char *buffer, int maxlen)
Get the current working directory.
UT_API bool UTisDirectory(const char *path)
Returns true if path is a directory, without permission checks.
UT_API bool UTisAbsolutePath(const char *filename)
UT_API int statLastRead(DIR *dirp, const char *path, UT_FileStat &file_stat)
Do the equivalent of a stat on the last file from readdir or opendir.
UT_API bool UTisValidRegularFile(const char *path)