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.
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 // Please pass in just the filename and not the entire path.
77 UT_API bool UTisHiddenFile(const char *filename);
78 
79 /// Returns true if the given path is a readable, _regular_ file, ie. not a
80 /// directory.
81 UT_API bool UTisValidRegularFile(const char *path);
82 
83 /// Returns true if the given path is a readable _directory_.
84 UT_API bool UTisValidDirectory(const char *path);
85 
86 /// Returns true if path is a _directory_, without permission checks
87 UT_API bool UTisDirectory(const char *path);
88 
89 /// Returns true if path is a _regular_ file, without permission checks
90 UT_API bool UTisRegularFile(const char *path);
91 
92 /// Returns true if file path exists, without permission checks.
93 /// This is optimized for known platforms.
94 UT_API bool UTfileExists(const char *path);
95 
96 #ifdef WIN32
97  #include <sys/types.h>
98  #include <direct.h>
99  #include <errno.h>
100 
101  // Define dummy value to compare with errno in assertions related
102  // to Linux libraries and large file systems. This define now exists on
103  // newer versions of Visual Studio. The current value is defined to be the
104  // same as the one found in VC10.
105  #ifndef EOVERFLOW
106  #define EOVERFLOW 132
107  #endif
108 
109  typedef void* DIR;
110  struct dirent {
111  char *d_name;
112  };
113  UT_API DIR *opendir( const char *name );
114  UT_API struct dirent *readdir( DIR *dirp );
115  UT_API void closedir( DIR *dirp );
116 
117  /// Get the current working directory
118  UT_API char *getUnixCwd( char *buffer, int maxlen );
119 #else
120  #include <sys/types.h>
121  #include <sys/stat.h>
122  #include <string.h>
123  #include <dirent.h>
124  #include <unistd.h>
125  #include <stdlib.h>
126 
127  /// Get the current working directory
128  UT_API char *getUnixCwd( char *buffer, int maxlen );
129 #endif
130 
131 /// Do the equivalent of a stat on the last file from readdir or opendir.
132 UT_API int statLastRead(DIR *dirp, const char *path, UT_FileStat &file_stat);
133 
134 #endif
135 
GT_API const UT_StringHolder filename
UT_API bool UTisHiddenFile(const char *filename)
GLuint const GLchar * name
Definition: glew.h:1814
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)
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)
UT_API void UTmakeAbsoluteFilePath(UT_String &path, const char *basepath=nullptr)
GLuint buffer
Definition: glew.h:1680
UT_API int UTfullPathSpecified(const char *name)
UT_API bool UTfileExists(const char *path)
UT_API void UTaddAbsolutePathPrefix(const char *prefix)
GLsizei const GLchar *const * path
Definition: glew.h:6461
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)