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 
52 /// Functions to manage the set of prefixes which Houdini treats as being
53 /// valid ways to start an absolute path.
55 UT_API void UTaddAbsolutePathPrefix(const char *prefix);
56 
57 /// Functions to convert absolute paths into relative paths and vice versa,
58 /// given a path and a "base" path which is used as the root location for
59 /// relative paths. When basepath is not given, getUnixCwd() will be used.
61  const char *basepath = nullptr);
63  const char *basepath = nullptr);
65  const char *basepath = nullptr);
67  const char *basepath = nullptr);
68 
69 /// Normalizes a file path. This means ensuring all slashes are forward
70 /// slashes, removing redundant slashes, and collapsing '..' and '.'
71 /// components as much as possible (whether they occur at the start or
72 /// in the middle of the path).
75 
76 /// Checks if the file name starts with '.'. basepath (parent directory)
77 /// is ignored in non Windows envirenment, whereas in Windows full path
78 /// is needed to see if the file has the hidden attribute.
79 UT_API bool UTisHiddenFile(const char *basepath, const char *filename);
80 
81 /// Returns true if the given path is a readable, _regular_ file, ie. not a
82 /// directory.
83 UT_API bool UTisValidRegularFile(const char *path);
84 
85 /// Returns true if the given path is a readable _directory_.
86 UT_API bool UTisValidDirectory(const char *path);
87 
88 /// Returns true if path is a _directory_, without permission checks
89 UT_API bool UTisDirectory(const char *path);
90 
91 /// Returns true if path is a _regular_ file, without permission checks
92 UT_API bool UTisRegularFile(const char *path);
93 
94 /// Returns true if file path exists, without permission checks.
95 /// This is optimized for known platforms.
96 UT_API bool UTfileExists(const char *path);
97 
98 #ifdef WIN32
99  #include <sys/types.h>
100  #include <direct.h>
101  #include <errno.h>
102 
103  // Define dummy value to compare with errno in assertions related
104  // to Linux libraries and large file systems. This define now exists on
105  // newer versions of Visual Studio. The current value is defined to be the
106  // same as the one found in VC10.
107  #ifndef EOVERFLOW
108  #define EOVERFLOW 132
109  #endif
110 
111  typedef void* DIR;
112  struct dirent {
113  char *d_name;
114  };
115  UT_API DIR *opendir( const char *name );
116  UT_API struct dirent *readdir( DIR *dirp );
117  UT_API void closedir( DIR *dirp );
118 
119  /// Get the current working directory
120  UT_API char *getUnixCwd( char *buffer, int maxlen );
121 #else
122  #include <sys/types.h>
123  #include <sys/stat.h>
124  #include <string.h>
125  #include <dirent.h>
126  #include <unistd.h>
127  #include <stdlib.h>
128 
129  /// Get the current working directory
130  UT_API char *getUnixCwd( char *buffer, int maxlen );
131 #endif
132 
133 /// Do the equivalent of a stat on the last file from readdir or opendir.
134 UT_API int statLastRead(DIR *dirp, const char *path, UT_FileStat &file_stat);
135 
136 #endif
137 
GT_API const UT_StringHolder filename
UT_API int UTunixFullPathSpecified(const char *name)
UT_API bool UTisRootPath(const char *filename)
UT_API void UTmakeRelativeFilePath(UT_String &path, const char *basepath=nullptr)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
UT_API const UT_StringArray & UTgetAbsolutePathPrefixes()
#define UT_API
Definition: UT_API.h:14
UT_API bool UTisValidDirectory(const char *path)
Returns true if the given path is a readable directory.
UT_API int UTgetRootPrefixLength(const char *filename)
UT_API bool UTisHiddenFile(const char *basepath, const char *filename)
UT_API void UTmakeAbsoluteFilePath(UT_String &path, const char *basepath=nullptr)
Definition: core.h:760
UT_API int UTfullPathSpecified(const char *name)
GLuint const GLchar * name
Definition: glcorearb.h:786
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 void UTnormalizeFilePath(UT_String &path)
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)