common: prevent buffer overflow
[supercollider.git] / include / common / SC_DirUtils.h
blob1e709deac35e805ee4f35d6d2e12c47f59be3bcb
1 /*
2 * Copyright (c) 2005 Tim Walters. All rights reserved.
3 * Created by Tim Walters on 10/19/05.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
22 #ifndef SC_DIR_UTILS_H_INCLUDED
23 #define SC_DIR_UTILS_H_INCLUDED
25 #include <limits.h>
26 #include <stdio.h>
28 #ifdef _WIN32
29 # include <stdio.h>
30 # ifndef PATH_MAX
31 # define PATH_MAX _MAX_PATH
32 # endif
33 # include <string.h>
34 # define strcasecmp stricmp
35 # define snprintf _snprintf
36 #endif
38 # ifndef MAXPATHLEN
39 # define MAXPATHLEN PATH_MAX
40 # endif
42 #ifdef _WIN32
43 #define SC_PATH_DELIMITER "\\"
44 #else
45 #define SC_PATH_DELIMITER "/"
46 #endif
48 // General path utilities
50 // Add 'component' to 'path' using the platform path separator.
51 void sc_AppendToPath(char *path, size_t max_size, const char *component);
53 // Returns the expanded path with users home directory (also in newpath2)
54 char *sc_StandardizePath(const char *path, char *newpath2);
56 // Return TRUE iff 'path' is a symbolic link.
57 bool sc_IsSymlink(const char *path);
59 // Return TRUE iff 'dirname' is an existing directory.
60 bool sc_DirectoryExists(const char *dirname);
62 // Returns TRUE iff 'name' is a directory pertaining to another platform.
63 bool sc_IsNonHostPlatformDir(const char *name);
65 // Returns TRUE iff 'name' is to be ignored during compilation.
66 bool sc_SkipDirectory(const char *name);
68 int sc_ResolveIfAlias(const char *path, char *returnPath, bool &isAlias, int length);
70 extern const char * gIdeName; // string used for conditional compilation according to which IDE is in use this session.
71 // for example, if the value is "scapp" then folders "scide_scapp" will be included, all other "scide_*" excluded.
73 // Support for Bundles
75 void sc_GetResourceDirectory(char* pathBuf, int length);
76 bool sc_IsStandAlone();
78 // Support for Extensions
80 // Get the user home directory.
81 void sc_GetUserHomeDirectory(char *str, int size);
83 // Get the System level data directory.
84 void sc_GetSystemAppSupportDirectory(char *str, int size);
86 // Get the User level data directory.
87 void sc_GetUserAppSupportDirectory(char *str, int size);
89 // Get the System level 'Extensions' directory.
90 void sc_GetSystemExtensionDirectory(char *str, int size);
92 // Get the User level 'Extensions' directory.
93 void sc_GetUserExtensionDirectory(char *str, int size);
95 // Get the directory for the configuration files.
96 void sc_GetUserConfigDirectory(char *str, int size);
98 // Directory access
100 // Abstract directory handle
101 struct SC_DirHandle;
103 // Open directory dirname. Return NULL on failure.
104 SC_DirHandle* sc_OpenDir(const char *dirname);
106 // Close directory dir.
107 void sc_CloseDir(SC_DirHandle *dir);
109 // Get next entry from directory 'dir' with name 'dirname' and put it into 'path'.
110 // Skip compilation directories iff 'skipEntry' is TRUE.
111 // Return TRUE iff pointing to a valid dir entry.
112 // Return TRUE in 'skipEntry' iff entry should be skipped.
113 bool sc_ReadDir(SC_DirHandle *dir, const char *dirname, char *path, bool &skipEntry);
116 // Globbing
118 // Abstract glob handle
119 struct SC_GlobHandle;
121 // Create glob iterator from 'pattern'. Return NULL on failure.
122 SC_GlobHandle* sc_Glob(const char* pattern);
124 // Free glob handle.
125 void sc_GlobFree(SC_GlobHandle* glob);
127 // Return next path from glob iterator.
128 // Return NULL at end of stream.
129 const char* sc_GlobNext(SC_GlobHandle* glob);
131 #endif // SC_DIR_UTILS_H_INCLUDED