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 /// Resolves symlinks, symbolic links on a path.
70 /// Calls ::realpath() or fs::canonical() depdending of the platform.
73 
74 /// Normalizes a file path. This means ensuring all slashes are forward
75 /// slashes, removing redundant slashes, and collapsing '..' and '.'
76 /// components as much as possible (whether they occur at the start or
77 /// in the middle of the path).
80 
81 /// Checks if the file name starts with '.'. basepath (parent directory)
82 /// is ignored in non Windows envirenment, whereas in Windows full path
83 /// is needed to see if the file has the hidden attribute.
84 UT_API bool UTisHiddenFile(const char *basepath, const char *filename);
85 
86 /// Returns true if the given path is a readable, _regular_ file, ie. not a
87 /// directory.
88 UT_API bool UTisValidRegularFile(const char *path);
89 
90 /// Returns true if the given path is a readable _directory_.
91 UT_API bool UTisValidDirectory(const char *path);
92 
93 /// Returns true if path is a _directory_, without permission checks
94 UT_API bool UTisDirectory(const char *path);
95 
96 /// Returns true if path is a _regular_ file, without permission checks
97 UT_API bool UTisRegularFile(const char *path);
98 
99 /// Returns true if file path exists, without permission checks.
100 /// This is optimized for known platforms.
101 UT_API bool UTfileExists(const char *path);
102 
103 #ifdef WIN32
104  #include <sys/types.h>
105  #include <direct.h>
106  #include <errno.h>
107 
108  // Define dummy value to compare with errno in assertions related
109  // to Linux libraries and large file systems. This define now exists on
110  // newer versions of Visual Studio. The current value is defined to be the
111  // same as the one found in VC10.
112  #ifndef EOVERFLOW
113  #define EOVERFLOW 132
114  #endif
115 
116  typedef void* DIR;
117  struct dirent {
118  char *d_name;
119  };
120  UT_API DIR *opendir( const char *name );
121  UT_API struct dirent *readdir( DIR *dirp );
122  UT_API void closedir( DIR *dirp );
123 
124  /// Get the current working directory
125  UT_API char *getUnixCwd( char *buffer, int maxlen );
126 #else
127  #include <sys/types.h>
128  #include <sys/stat.h>
129  #include <string.h>
130  #include <dirent.h>
131  #include <unistd.h>
132  #include <stdlib.h>
133 
134  /// Get the current working directory
135  UT_API char *getUnixCwd( char *buffer, int maxlen );
136 #endif
137 
138 /// Do the equivalent of a stat on the last file from readdir or opendir.
139 UT_API int statLastRead(DIR *dirp, const char *path, UT_FileStat &file_stat);
140 
141 #endif
142 
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 void UTrealPath(UT_String &path)
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)