blob: 357cb2f27eea492e4d7cf38776472a8870bbb464 [file] [log] [blame]
Reid Spencerb016a372004-09-15 05:49:50 +00001//===- llvm/System/Linux/Path.cpp - Linux Path Implementation ---*- C++ -*-===//
2//
Reid Spencercbad7012004-09-11 04:59:30 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencerb016a372004-09-15 05:49:50 +00007//
8// Modified by Henrik Bach to comply with at least MinGW.
Reid Spencerd0c9e0e2004-09-18 19:29:16 +00009// Ported to Win32 by Jeff Cohen.
Reid Spencerb016a372004-09-15 05:49:50 +000010//
Reid Spencercbad7012004-09-11 04:59:30 +000011//===----------------------------------------------------------------------===//
12//
13// This file provides the Win32 specific implementation of the Path class.
14//
15//===----------------------------------------------------------------------===//
16
17//===----------------------------------------------------------------------===//
Reid Spencerb016a372004-09-15 05:49:50 +000018//=== WARNING: Implementation here must contain only generic Win32 code that
19//=== is guaranteed to work on *all* Win32 variants.
Reid Spencercbad7012004-09-11 04:59:30 +000020//===----------------------------------------------------------------------===//
21
Reid Spencerd0c9e0e2004-09-18 19:29:16 +000022#include "Win32.h"
Reid Spencerd0c9e0e2004-09-18 19:29:16 +000023#include <malloc.h>
Reid Spencercbad7012004-09-11 04:59:30 +000024
Jeff Cohencb652552004-12-24 02:38:34 +000025// We need to undo a macro defined in Windows.h, otherwise we won't compile:
26#undef CopyFile
Anton Korobeynikov64ddbe42007-12-22 14:26:49 +000027#undef GetCurrentDirectory
Jeff Cohencb652552004-12-24 02:38:34 +000028
Jeff Cohen966fa412005-07-09 18:42:49 +000029// Windows happily accepts either forward or backward slashes, though any path
30// returned by a Win32 API will have backward slashes. As LLVM code basically
31// assumes forward slashes are used, backward slashs are converted where they
32// can be introduced into a path.
33//
34// Another invariant is that a path ends with a slash if and only if the path
35// is a root directory. Any other use of a trailing slash is stripped. Unlike
36// in Unix, Windows has a rather complicated notion of a root path and this
37// invariant helps simply the code.
38
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000039static void FlipBackSlashes(std::string& s) {
40 for (size_t i = 0; i < s.size(); i++)
41 if (s[i] == '\\')
42 s[i] = '/';
43}
44
Reid Spencercbad7012004-09-11 04:59:30 +000045namespace llvm {
Reid Spencerb016a372004-09-15 05:49:50 +000046namespace sys {
Chris Lattnera17fa282008-03-13 05:17:59 +000047const char PathSeparator = ';';
Chris Lattnere1b332a2008-02-27 06:17:10 +000048
Reid Spencerb016a372004-09-15 05:49:50 +000049bool
Reid Spencer07adb282004-11-05 22:15:36 +000050Path::isValid() const {
Reid Spencerb016a372004-09-15 05:49:50 +000051 if (path.empty())
52 return false;
Reid Spencerd0c9e0e2004-09-18 19:29:16 +000053
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000054 // If there is a colon, it must be the second character, preceded by a letter
55 // and followed by something.
56 size_t len = path.size();
57 size_t pos = path.rfind(':',len);
Jeff Cohen8f0e8f22005-07-08 04:50:08 +000058 size_t rootslash = 0;
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000059 if (pos != std::string::npos) {
60 if (pos != 1 || !isalpha(path[0]) || len < 3)
61 return false;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +000062 rootslash = 2;
63 }
Jeff Cohen85c716f2005-07-08 05:02:13 +000064
Jeff Cohen8f0e8f22005-07-08 04:50:08 +000065 // Look for a UNC path, and if found adjust our notion of the root slash.
66 if (len > 3 && path[0] == '/' && path[1] == '/') {
67 rootslash = path.find('/', 2);
68 if (rootslash == std::string::npos)
69 rootslash = 0;
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000070 }
Reid Spencerd0c9e0e2004-09-18 19:29:16 +000071
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000072 // Check for illegal characters.
73 if (path.find_first_of("\\<>\"|\001\002\003\004\005\006\007\010\011\012"
74 "\013\014\015\016\017\020\021\022\023\024\025\026"
75 "\027\030\031\032\033\034\035\036\037")
76 != std::string::npos)
77 return false;
Jeff Cohen85c716f2005-07-08 05:02:13 +000078
Jeff Cohen8f0e8f22005-07-08 04:50:08 +000079 // Remove trailing slash, unless it's a root slash.
80 if (len > rootslash+1 && path[len-1] == '/')
81 path.erase(--len);
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000082
Jeff Cohen3bbbcc12005-01-14 04:09:39 +000083 // Check each component for legality.
84 for (pos = 0; pos < len; ++pos) {
85 // A component may not end in a space.
86 if (path[pos] == ' ') {
87 if (path[pos+1] == '/' || path[pos+1] == '\0')
88 return false;
89 }
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000090
Jeff Cohen3bbbcc12005-01-14 04:09:39 +000091 // A component may not end in a period.
92 if (path[pos] == '.') {
93 if (path[pos+1] == '/' || path[pos+1] == '\0') {
94 // Unless it is the pseudo-directory "."...
95 if (pos == 0 || path[pos-1] == '/' || path[pos-1] == ':')
96 return true;
97 // or "..".
98 if (pos > 0 && path[pos-1] == '.') {
99 if (pos == 1 || path[pos-2] == '/' || path[pos-2] == ':')
100 return true;
101 }
102 return false;
103 }
104 }
105 }
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000106
107 return true;
Reid Spencercbad7012004-09-11 04:59:30 +0000108}
109
Reid Spencer69cce812007-03-29 16:43:20 +0000110bool
111Path::isAbsolute() const {
Jeff Cohen84892be2007-03-29 17:27:38 +0000112 switch (path.length()) {
113 case 0:
114 return false;
115 case 1:
116 case 2:
117 return path[0] == '/';
118 default:
119 return path[0] == '/' || (path[1] == ':' && path[2] == '/');
120 }
Reid Spencer69cce812007-03-29 16:43:20 +0000121}
122
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000123static Path *TempDirectory = NULL;
124
Reid Spencerb016a372004-09-15 05:49:50 +0000125Path
Reid Spencercab0e432006-08-22 22:46:39 +0000126Path::GetTemporaryDirectory(std::string* ErrMsg) {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000127 if (TempDirectory)
128 return *TempDirectory;
129
130 char pathname[MAX_PATH];
Reid Spencercab0e432006-08-22 22:46:39 +0000131 if (!GetTempPath(MAX_PATH, pathname)) {
132 if (ErrMsg)
133 *ErrMsg = "Can't determine temporary directory";
134 return Path();
135 }
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000136
Reid Spencerb016a372004-09-15 05:49:50 +0000137 Path result;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000138 result.set(pathname);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000139
140 // Append a subdirectory passed on our process id so multiple LLVMs don't
141 // step on each other's toes.
Jeff Cohend41b30d2006-11-05 19:31:28 +0000142#ifdef __MINGW32__
143 // Mingw's Win32 header files are broken.
Reid Spencerab4d9b02006-06-08 18:08:43 +0000144 sprintf(pathname, "LLVM_%u", unsigned(GetCurrentProcessId()));
Jeff Cohend41b30d2006-11-05 19:31:28 +0000145#else
146 sprintf(pathname, "LLVM_%u", GetCurrentProcessId());
147#endif
Jeff Cohenedb9d6b2005-07-08 02:48:42 +0000148 result.appendComponent(pathname);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000149
150 // If there's a directory left over from a previous LLVM execution that
151 // happened to have the same process id, get rid of it.
Reid Spencera229c5c2005-07-08 03:08:58 +0000152 result.eraseFromDisk(true);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000153
154 // And finally (re-)create the empty directory.
Reid Spencera229c5c2005-07-08 03:08:58 +0000155 result.createDirectoryOnDisk(false);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000156 TempDirectory = new Path(result);
157 return *TempDirectory;
Reid Spencerb016a372004-09-15 05:49:50 +0000158}
159
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000160// FIXME: the following set of functions don't map to Windows very well.
Reid Spencerb016a372004-09-15 05:49:50 +0000161Path
162Path::GetRootDirectory() {
163 Path result;
Jeff Cohen966fa412005-07-09 18:42:49 +0000164 result.set("C:/");
Reid Spencerb016a372004-09-15 05:49:50 +0000165 return result;
166}
167
Jeff Cohen85c716f2005-07-08 05:02:13 +0000168void
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000169Path::GetSystemLibraryPaths(std::vector<sys::Path>& Paths) {
Jeff Cohen966fa412005-07-09 18:42:49 +0000170 Paths.push_back(sys::Path("C:/WINDOWS/SYSTEM32"));
171 Paths.push_back(sys::Path("C:/WINDOWS"));
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000172}
173
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000174void
Gabor Greifdb5565a2007-07-06 20:28:40 +0000175Path::GetBitcodeLibraryPaths(std::vector<sys::Path>& Paths) {
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000176 char * env_var = getenv("LLVM_LIB_SEARCH_PATH");
177 if (env_var != 0) {
178 getPathList(env_var,Paths);
179 }
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000180#ifdef LLVM_LIBDIR
181 {
182 Path tmpPath;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000183 if (tmpPath.set(LLVM_LIBDIR))
Reid Spencerc7f08322005-07-07 18:21:42 +0000184 if (tmpPath.canRead())
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000185 Paths.push_back(tmpPath);
186 }
187#endif
188 GetSystemLibraryPaths(Paths);
Reid Spencerb016a372004-09-15 05:49:50 +0000189}
190
191Path
192Path::GetLLVMDefaultConfigDir() {
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000193 // TODO: this isn't going to fly on Windows
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000194 return Path("/etc/llvm");
Reid Spencerb016a372004-09-15 05:49:50 +0000195}
196
197Path
Reid Spencerb016a372004-09-15 05:49:50 +0000198Path::GetUserHomeDirectory() {
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000199 // TODO: Typical Windows setup doesn't define HOME.
Reid Spencerb016a372004-09-15 05:49:50 +0000200 const char* home = getenv("HOME");
201 if (home) {
202 Path result;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000203 if (result.set(home))
Reid Spencerb016a372004-09-15 05:49:50 +0000204 return result;
205 }
206 return GetRootDirectory();
207}
Ted Kremenek79200782007-12-18 22:07:33 +0000208
209Path
210Path::GetCurrentDirectory() {
211 char pathname[MAX_PATH];
Anton Korobeynikov64ddbe42007-12-22 14:26:49 +0000212 ::GetCurrentDirectoryA(MAX_PATH,pathname);
Ted Kremenek79200782007-12-18 22:07:33 +0000213 return Path(pathname);
214}
215
Chris Lattner1a091442008-03-03 02:55:43 +0000216/// GetMainExecutable - Return the path to the main executable, given the
217/// value of argv[0] from program startup.
218Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
219 return Path();
220}
221
Ted Kremenek79200782007-12-18 22:07:33 +0000222
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000223// FIXME: the above set of functions don't map to Windows very well.
224
Jeff Cohen966fa412005-07-09 18:42:49 +0000225
226bool
227Path::isRootDirectory() const {
228 size_t len = path.size();
229 return len > 0 && path[len-1] == '/';
Reid Spencera229c5c2005-07-08 03:08:58 +0000230}
231
Ted Kremenek9b01cc02008-04-07 22:01:32 +0000232std::string Path::getDirname() const {
233 return getDirnameCharSep(path, '\\');
234}
Ted Kremenekcf55c8e2008-04-07 21:53:57 +0000235
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000236std::string
Reid Spencer07adb282004-11-05 22:15:36 +0000237Path::getBasename() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000238 // Find the last slash
239 size_t slash = path.rfind('/');
240 if (slash == std::string::npos)
241 slash = 0;
242 else
243 slash++;
244
Jeff Cohen966fa412005-07-09 18:42:49 +0000245 size_t dot = path.rfind('.');
246 if (dot == std::string::npos || dot < slash)
247 return path.substr(slash);
248 else
249 return path.substr(slash, dot - slash);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000250}
251
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000252bool
Reid Spencerb016a372004-09-15 05:49:50 +0000253Path::exists() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000254 DWORD attr = GetFileAttributes(path.c_str());
255 return attr != INVALID_FILE_ATTRIBUTES;
Reid Spencerb016a372004-09-15 05:49:50 +0000256}
257
258bool
Ted Kremenekfd527112007-12-18 19:46:22 +0000259Path::isDirectory() const {
260 DWORD attr = GetFileAttributes(path.c_str());
261 return (attr != INVALID_FILE_ATTRIBUTES) &&
262 (attr & FILE_ATTRIBUTE_DIRECTORY);
263}
264
265bool
Reid Spencerc7f08322005-07-07 18:21:42 +0000266Path::canRead() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000267 // FIXME: take security attributes into account.
268 DWORD attr = GetFileAttributes(path.c_str());
269 return attr != INVALID_FILE_ATTRIBUTES;
Reid Spencerb016a372004-09-15 05:49:50 +0000270}
271
272bool
Reid Spencerc7f08322005-07-07 18:21:42 +0000273Path::canWrite() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000274 // FIXME: take security attributes into account.
275 DWORD attr = GetFileAttributes(path.c_str());
276 return (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_READONLY);
Reid Spencerb016a372004-09-15 05:49:50 +0000277}
278
279bool
Reid Spencerc7f08322005-07-07 18:21:42 +0000280Path::canExecute() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000281 // FIXME: take security attributes into account.
282 DWORD attr = GetFileAttributes(path.c_str());
283 return attr != INVALID_FILE_ATTRIBUTES;
Reid Spencerb016a372004-09-15 05:49:50 +0000284}
285
286std::string
287Path::getLast() const {
288 // Find the last slash
289 size_t pos = path.rfind('/');
290
291 // Handle the corner cases
292 if (pos == std::string::npos)
293 return path;
294
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000295 // If the last character is a slash, we have a root directory
296 if (pos == path.length()-1)
297 return path;
298
Reid Spencerb016a372004-09-15 05:49:50 +0000299 // Return everything after the last slash
300 return path.substr(pos+1);
301}
302
Reid Spencer8475ec02007-03-29 19:05:44 +0000303const FileStatus *
Reid Spencer2ae9d112007-04-07 18:52:17 +0000304PathWithStatus::getFileStatus(bool update, std::string *ErrStr) const {
305 if (!fsIsValid || update) {
Reid Spencer69cce812007-03-29 16:43:20 +0000306 WIN32_FILE_ATTRIBUTE_DATA fi;
Reid Spencer8475ec02007-03-29 19:05:44 +0000307 if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) {
308 MakeErrMsg(ErrStr, "getStatusInfo():" + std::string(path) +
Reid Spencer69cce812007-03-29 16:43:20 +0000309 ": Can't get status: ");
Reid Spencer8475ec02007-03-29 19:05:44 +0000310 return 0;
311 }
Jeff Cohen626e38e2004-12-14 05:26:43 +0000312
Reid Spencer2ae9d112007-04-07 18:52:17 +0000313 status.fileSize = fi.nFileSizeHigh;
314 status.fileSize <<= sizeof(fi.nFileSizeHigh)*8;
315 status.fileSize += fi.nFileSizeLow;
Jeff Cohen626e38e2004-12-14 05:26:43 +0000316
Reid Spencer2ae9d112007-04-07 18:52:17 +0000317 status.mode = fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0555 : 0777;
318 status.user = 9999; // Not applicable to Windows, so...
319 status.group = 9999; // Not applicable to Windows, so...
Jeff Cohen626e38e2004-12-14 05:26:43 +0000320
Reid Spencer4031bef2007-03-29 17:00:31 +0000321 // FIXME: this is only unique if the file is accessed by the same file path.
322 // How do we do this for C:\dir\file and ..\dir\file ? Unix has inode
323 // numbers, but the concept doesn't exist in Windows.
Reid Spencer2ae9d112007-04-07 18:52:17 +0000324 status.uniqueID = 0;
Reid Spencer4031bef2007-03-29 17:00:31 +0000325 for (unsigned i = 0; i < path.length(); ++i)
Reid Spencer2ae9d112007-04-07 18:52:17 +0000326 status.uniqueID += path[i];
Reid Spencer4031bef2007-03-29 17:00:31 +0000327
Reid Spencer69cce812007-03-29 16:43:20 +0000328 __int64 ft = *reinterpret_cast<__int64*>(&fi.ftLastWriteTime);
Reid Spencer2ae9d112007-04-07 18:52:17 +0000329 status.modTime.fromWin32Time(ft);
Reid Spencer69cce812007-03-29 16:43:20 +0000330
Reid Spencer2ae9d112007-04-07 18:52:17 +0000331 status.isDir = fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
332 fsIsValid = true;
Reid Spencer69cce812007-03-29 16:43:20 +0000333 }
Reid Spencer2ae9d112007-04-07 18:52:17 +0000334 return &status;
Jeff Cohen626e38e2004-12-14 05:26:43 +0000335}
336
Reid Spencera34a1572006-08-22 23:54:35 +0000337bool Path::makeReadableOnDisk(std::string* ErrMsg) {
Jeff Cohen626e38e2004-12-14 05:26:43 +0000338 // All files are readable on Windows (ignoring security attributes).
Reid Spencera34a1572006-08-22 23:54:35 +0000339 return false;
Reid Spencer77cc91d2004-12-13 19:59:50 +0000340}
341
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000342bool Path::makeWriteableOnDisk(std::string* ErrMsg) {
Jeff Cohen626e38e2004-12-14 05:26:43 +0000343 DWORD attr = GetFileAttributes(path.c_str());
344
345 // If it doesn't exist, we're done.
346 if (attr == INVALID_FILE_ATTRIBUTES)
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000347 return false;
Jeff Cohen626e38e2004-12-14 05:26:43 +0000348
349 if (attr & FILE_ATTRIBUTE_READONLY) {
Reid Spencera34a1572006-08-22 23:54:35 +0000350 if (!SetFileAttributes(path.c_str(), attr & ~FILE_ATTRIBUTE_READONLY)) {
351 MakeErrMsg(ErrMsg, std::string(path) + ": Can't make file writable: ");
352 return true;
353 }
Jeff Cohen626e38e2004-12-14 05:26:43 +0000354 }
Reid Spencera34a1572006-08-22 23:54:35 +0000355 return false;
Reid Spencer77cc91d2004-12-13 19:59:50 +0000356}
357
Reid Spencera34a1572006-08-22 23:54:35 +0000358bool Path::makeExecutableOnDisk(std::string* ErrMsg) {
Jeff Cohen626e38e2004-12-14 05:26:43 +0000359 // All files are executable on Windows (ignoring security attributes).
Reid Spencera34a1572006-08-22 23:54:35 +0000360 return false;
Reid Spencer77cc91d2004-12-13 19:59:50 +0000361}
362
Reid Spencerb016a372004-09-15 05:49:50 +0000363bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000364Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const {
Jeff Cohen31102892007-04-07 20:47:27 +0000365 WIN32_FILE_ATTRIBUTE_DATA fi;
366 if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) {
367 MakeErrMsg(ErrMsg, path + ": can't get status of file");
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000368 return true;
Jeff Cohen31102892007-04-07 20:47:27 +0000369 }
370
371 if (!(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
372 if (ErrMsg)
373 *ErrMsg = path + ": not a directory";
Reid Spencer142ca8e2006-08-23 06:56:27 +0000374 return true;
375 }
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000376
377 result.clear();
378 WIN32_FIND_DATA fd;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000379 std::string searchpath = path;
380 if (path.size() == 0 || searchpath[path.size()-1] == '/')
Jeff Cohen85c716f2005-07-08 05:02:13 +0000381 searchpath += "*";
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000382 else
383 searchpath += "/*";
Jeff Cohen85c716f2005-07-08 05:02:13 +0000384
Jeff Cohen9437bb62005-01-27 03:49:03 +0000385 HANDLE h = FindFirstFile(searchpath.c_str(), &fd);
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000386 if (h == INVALID_HANDLE_VALUE) {
Jeff Cohen9437bb62005-01-27 03:49:03 +0000387 if (GetLastError() == ERROR_FILE_NOT_FOUND)
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000388 return true; // not really an error, now is it?
Reid Spencer142ca8e2006-08-23 06:56:27 +0000389 MakeErrMsg(ErrMsg, path + ": Can't read directory: ");
390 return true;
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000391 }
392
393 do {
Jeff Cohend40a7de2004-12-31 05:07:26 +0000394 if (fd.cFileName[0] == '.')
395 continue;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000396 Path aPath(path);
397 aPath.appendComponent(&fd.cFileName[0]);
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000398 result.insert(aPath);
399 } while (FindNextFile(h, &fd));
400
Jeff Cohen51b8d212004-12-31 19:01:08 +0000401 DWORD err = GetLastError();
402 FindClose(h);
403 if (err != ERROR_NO_MORE_FILES) {
404 SetLastError(err);
Reid Spencer142ca8e2006-08-23 06:56:27 +0000405 MakeErrMsg(ErrMsg, path + ": Can't read directory: ");
406 return true;
Jeff Cohen51b8d212004-12-31 19:01:08 +0000407 }
Reid Spencer142ca8e2006-08-23 06:56:27 +0000408 return false;
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000409}
410
411bool
Reid Spencer1cf2d042005-07-07 23:35:23 +0000412Path::set(const std::string& a_path) {
Dan Gohman30359592008-01-29 13:02:09 +0000413 if (a_path.empty())
Reid Spencerb016a372004-09-15 05:49:50 +0000414 return false;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000415 std::string save(path);
Reid Spencerb016a372004-09-15 05:49:50 +0000416 path = a_path;
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000417 FlipBackSlashes(path);
Reid Spencer07adb282004-11-05 22:15:36 +0000418 if (!isValid()) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000419 path = save;
Reid Spencerb016a372004-09-15 05:49:50 +0000420 return false;
421 }
422 return true;
423}
424
425bool
Jeff Cohenedb9d6b2005-07-08 02:48:42 +0000426Path::appendComponent(const std::string& name) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000427 if (name.empty())
Reid Spencerb016a372004-09-15 05:49:50 +0000428 return false;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000429 std::string save(path);
430 if (!path.empty()) {
431 size_t last = path.size() - 1;
Jeff Cohen85c716f2005-07-08 05:02:13 +0000432 if (path[last] != '/')
Reid Spencer1cf2d042005-07-07 23:35:23 +0000433 path += '/';
434 }
435 path += name;
Reid Spencer07adb282004-11-05 22:15:36 +0000436 if (!isValid()) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000437 path = save;
Reid Spencerb016a372004-09-15 05:49:50 +0000438 return false;
439 }
440 return true;
441}
442
443bool
Reid Spencer1cf2d042005-07-07 23:35:23 +0000444Path::eraseComponent() {
Reid Spencerb016a372004-09-15 05:49:50 +0000445 size_t slashpos = path.rfind('/',path.size());
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000446 if (slashpos == path.size() - 1 || slashpos == std::string::npos)
Reid Spencerb016a372004-09-15 05:49:50 +0000447 return false;
Jeff Cohen966fa412005-07-09 18:42:49 +0000448 std::string save(path);
Reid Spencerb016a372004-09-15 05:49:50 +0000449 path.erase(slashpos);
Jeff Cohen966fa412005-07-09 18:42:49 +0000450 if (!isValid()) {
451 path = save;
452 return false;
453 }
Reid Spencerb016a372004-09-15 05:49:50 +0000454 return true;
455}
456
457bool
Reid Spencer07adb282004-11-05 22:15:36 +0000458Path::appendSuffix(const std::string& suffix) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000459 std::string save(path);
Reid Spencerb016a372004-09-15 05:49:50 +0000460 path.append(".");
461 path.append(suffix);
Reid Spencer07adb282004-11-05 22:15:36 +0000462 if (!isValid()) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000463 path = save;
Reid Spencerb016a372004-09-15 05:49:50 +0000464 return false;
465 }
466 return true;
467}
468
469bool
Reid Spencer1cf2d042005-07-07 23:35:23 +0000470Path::eraseSuffix() {
Reid Spencerb016a372004-09-15 05:49:50 +0000471 size_t dotpos = path.rfind('.',path.size());
472 size_t slashpos = path.rfind('/',path.size());
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000473 if (dotpos != std::string::npos) {
Jeff Cohen966fa412005-07-09 18:42:49 +0000474 if (slashpos == std::string::npos || dotpos > slashpos+1) {
475 std::string save(path);
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000476 path.erase(dotpos, path.size()-dotpos);
Jeff Cohen966fa412005-07-09 18:42:49 +0000477 if (!isValid()) {
478 path = save;
479 return false;
480 }
Jeff Cohen85c716f2005-07-08 05:02:13 +0000481 return true;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000482 }
Reid Spencerb016a372004-09-15 05:49:50 +0000483 }
484 return false;
485}
486
Reid Spencer30300992006-08-24 18:58:37 +0000487inline bool PathMsg(std::string* ErrMsg, const char* pathname, const char*msg) {
488 if (ErrMsg)
489 *ErrMsg = std::string(pathname) + ": " + std::string(msg);
490 return true;
491}
492
Reid Spencerb016a372004-09-15 05:49:50 +0000493bool
Reid Spencer30300992006-08-24 18:58:37 +0000494Path::createDirectoryOnDisk(bool create_parents, std::string* ErrMsg) {
Reid Spencerb016a372004-09-15 05:49:50 +0000495 // Get a writeable copy of the path name
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000496 size_t len = path.length();
497 char *pathname = reinterpret_cast<char *>(_alloca(len+2));
498 path.copy(pathname, len);
499 pathname[len] = 0;
Jeff Cohen85c716f2005-07-08 05:02:13 +0000500
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000501 // Make sure it ends with a slash.
502 if (len == 0 || pathname[len - 1] != '/') {
503 pathname[len] = '/';
504 pathname[++len] = 0;
505 }
Reid Spencerb016a372004-09-15 05:49:50 +0000506
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000507 // Determine starting point for initial / search.
508 char *next = pathname;
509 if (pathname[0] == '/' && pathname[1] == '/') {
510 // Skip host name.
511 next = strchr(pathname+2, '/');
512 if (next == NULL)
Reid Spencer30300992006-08-24 18:58:37 +0000513 return PathMsg(ErrMsg, pathname, "badly formed remote directory");
514
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000515 // Skip share name.
516 next = strchr(next+1, '/');
517 if (next == NULL)
Reid Spencer30300992006-08-24 18:58:37 +0000518 return PathMsg(ErrMsg, pathname,"badly formed remote directory");
519
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000520 next++;
521 if (*next == 0)
Reid Spencer30300992006-08-24 18:58:37 +0000522 return PathMsg(ErrMsg, pathname, "badly formed remote directory");
523
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000524 } else {
525 if (pathname[1] == ':')
526 next += 2; // skip drive letter
527 if (*next == '/')
528 next++; // skip root directory
529 }
Reid Spencerb016a372004-09-15 05:49:50 +0000530
531 // If we're supposed to create intermediate directories
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000532 if (create_parents) {
Reid Spencerb016a372004-09-15 05:49:50 +0000533 // Loop through the directory components until we're done
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000534 while (*next) {
535 next = strchr(next, '/');
Reid Spencerb016a372004-09-15 05:49:50 +0000536 *next = 0;
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000537 if (!CreateDirectory(pathname, NULL))
Reid Spencer30300992006-08-24 18:58:37 +0000538 return MakeErrMsg(ErrMsg,
539 std::string(pathname) + ": Can't create directory: ");
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000540 *next++ = '/';
Reid Spencerb016a372004-09-15 05:49:50 +0000541 }
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000542 } else {
543 // Drop trailing slash.
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000544 pathname[len-1] = 0;
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000545 if (!CreateDirectory(pathname, NULL)) {
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000546 return MakeErrMsg(ErrMsg, std::string(pathname) + ": Can't create directory: ");
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000547 }
Reid Spencerb016a372004-09-15 05:49:50 +0000548 }
Reid Spencer30300992006-08-24 18:58:37 +0000549 return false;
Reid Spencerb016a372004-09-15 05:49:50 +0000550}
551
552bool
Reid Spencer30300992006-08-24 18:58:37 +0000553Path::createFileOnDisk(std::string* ErrMsg) {
Reid Spencerb016a372004-09-15 05:49:50 +0000554 // Create the file
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000555 HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW,
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000556 FILE_ATTRIBUTE_NORMAL, NULL);
557 if (h == INVALID_HANDLE_VALUE)
Reid Spencer30300992006-08-24 18:58:37 +0000558 return MakeErrMsg(ErrMsg, path + ": Can't create file: ");
Reid Spencerb016a372004-09-15 05:49:50 +0000559
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000560 CloseHandle(h);
Reid Spencer30300992006-08-24 18:58:37 +0000561 return false;
Reid Spencerb016a372004-09-15 05:49:50 +0000562}
563
564bool
Chris Lattner0c332312006-07-28 22:29:50 +0000565Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
Jeff Cohen31102892007-04-07 20:47:27 +0000566 WIN32_FILE_ATTRIBUTE_DATA fi;
567 if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
568 return true;
Chris Lattnerc7c453a2006-08-01 17:51:09 +0000569
Jeff Cohen31102892007-04-07 20:47:27 +0000570 if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000571 // If it doesn't exist, we're done.
Jeff Cohen85c716f2005-07-08 05:02:13 +0000572 if (!exists())
Chris Lattner0c332312006-07-28 22:29:50 +0000573 return false;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000574
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000575 char *pathname = reinterpret_cast<char *>(_alloca(path.length()+3));
Reid Spencer1cf2d042005-07-07 23:35:23 +0000576 int lastchar = path.length() - 1 ;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000577 path.copy(pathname, lastchar+1);
Reid Spencer1cf2d042005-07-07 23:35:23 +0000578
579 // Make path end with '/*'.
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000580 if (pathname[lastchar] != '/')
581 pathname[++lastchar] = '/';
Reid Spencer1cf2d042005-07-07 23:35:23 +0000582 pathname[lastchar+1] = '*';
583 pathname[lastchar+2] = 0;
584
585 if (remove_contents) {
586 WIN32_FIND_DATA fd;
587 HANDLE h = FindFirstFile(pathname, &fd);
588
589 // It's a bad idea to alter the contents of a directory while enumerating
590 // its contents. So build a list of its contents first, then destroy them.
591
592 if (h != INVALID_HANDLE_VALUE) {
593 std::vector<Path> list;
594
595 do {
596 if (strcmp(fd.cFileName, ".") == 0)
597 continue;
598 if (strcmp(fd.cFileName, "..") == 0)
599 continue;
600
Jeff Cohen85c716f2005-07-08 05:02:13 +0000601 Path aPath(path);
602 aPath.appendComponent(&fd.cFileName[0]);
Reid Spencer1cf2d042005-07-07 23:35:23 +0000603 list.push_back(aPath);
604 } while (FindNextFile(h, &fd));
605
606 DWORD err = GetLastError();
607 FindClose(h);
608 if (err != ERROR_NO_MORE_FILES) {
609 SetLastError(err);
Reid Spencer05545752006-08-25 21:37:17 +0000610 return MakeErrMsg(ErrStr, path + ": Can't read directory: ");
Reid Spencer1cf2d042005-07-07 23:35:23 +0000611 }
612
Jeff Cohen85c716f2005-07-08 05:02:13 +0000613 for (std::vector<Path>::iterator I = list.begin(); I != list.end();
Reid Spencer1cf2d042005-07-07 23:35:23 +0000614 ++I) {
615 Path &aPath = *I;
Reid Spencera229c5c2005-07-08 03:08:58 +0000616 aPath.eraseFromDisk(true);
Reid Spencer1cf2d042005-07-07 23:35:23 +0000617 }
618 } else {
619 if (GetLastError() != ERROR_FILE_NOT_FOUND)
Reid Spencer05545752006-08-25 21:37:17 +0000620 return MakeErrMsg(ErrStr, path + ": Can't read directory: ");
Reid Spencer1cf2d042005-07-07 23:35:23 +0000621 }
622 }
623
624 pathname[lastchar] = 0;
625 if (!RemoveDirectory(pathname))
Reid Spencer05545752006-08-25 21:37:17 +0000626 return MakeErrMsg(ErrStr,
627 std::string(pathname) + ": Can't destroy directory: ");
Chris Lattner0c332312006-07-28 22:29:50 +0000628 return false;
Jeff Cohen31102892007-04-07 20:47:27 +0000629 } else {
630 // Read-only files cannot be deleted on Windows. Must remove the read-only
631 // attribute first.
632 if (fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
633 if (!SetFileAttributes(path.c_str(),
634 fi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY))
635 return MakeErrMsg(ErrStr, path + ": Can't destroy file: ");
636 }
637
638 if (!DeleteFile(path.c_str()))
639 return MakeErrMsg(ErrStr, path + ": Can't destroy file: ");
640 return false;
641 }
Reid Spencerb016a372004-09-15 05:49:50 +0000642}
643
Reid Spencer3b0cc782004-12-14 18:42:13 +0000644bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
Reid Spencer3b0cc782004-12-14 18:42:13 +0000645 assert(len < 1024 && "Request for magic string too long");
646 char* buf = (char*) alloca(1 + len);
Jeff Cohen51b8d212004-12-31 19:01:08 +0000647
648 HANDLE h = CreateFile(path.c_str(),
649 GENERIC_READ,
650 FILE_SHARE_READ,
651 NULL,
652 OPEN_EXISTING,
653 FILE_ATTRIBUTE_NORMAL,
654 NULL);
655 if (h == INVALID_HANDLE_VALUE)
Reid Spencer3b0cc782004-12-14 18:42:13 +0000656 return false;
Jeff Cohen51b8d212004-12-31 19:01:08 +0000657
658 DWORD nRead = 0;
659 BOOL ret = ReadFile(h, buf, len, &nRead, NULL);
660 CloseHandle(h);
661
662 if (!ret || nRead != len)
Reid Spencer3b0cc782004-12-14 18:42:13 +0000663 return false;
Jeff Cohen51b8d212004-12-31 19:01:08 +0000664
Reid Spencer3b0cc782004-12-14 18:42:13 +0000665 buf[len] = '\0';
666 Magic = buf;
667 return true;
668}
669
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000670bool
Reid Spencer5a060772006-08-23 07:30:48 +0000671Path::renamePathOnDisk(const Path& newName, std::string* ErrMsg) {
Jeff Cohene564de22006-05-07 02:51:51 +0000672 if (!MoveFileEx(path.c_str(), newName.c_str(), MOVEFILE_REPLACE_EXISTING))
Reid Spencer5a060772006-08-23 07:30:48 +0000673 return MakeErrMsg(ErrMsg, "Can't move '" + path + "' to '" + newName.path
674 + "': ");
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000675 return true;
676}
677
678bool
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000679Path::setStatusInfoOnDisk(const FileStatus &si, std::string *ErrMsg) const {
Jeff Cohen966fa412005-07-09 18:42:49 +0000680 // FIXME: should work on directories also.
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000681 if (!si.isFile) {
682 return true;
683 }
684
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000685 HANDLE h = CreateFile(path.c_str(),
686 FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
687 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
Jeff Cohend40a7de2004-12-31 05:07:26 +0000688 NULL,
689 OPEN_EXISTING,
690 FILE_ATTRIBUTE_NORMAL,
691 NULL);
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000692 if (h == INVALID_HANDLE_VALUE)
Chris Lattner1bebfb52006-07-28 22:36:17 +0000693 return true;
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000694
695 BY_HANDLE_FILE_INFORMATION bhfi;
696 if (!GetFileInformationByHandle(h, &bhfi)) {
Jeff Cohen51b8d212004-12-31 19:01:08 +0000697 DWORD err = GetLastError();
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000698 CloseHandle(h);
Jeff Cohen51b8d212004-12-31 19:01:08 +0000699 SetLastError(err);
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000700 return MakeErrMsg(ErrMsg, path + ": GetFileInformationByHandle: ");
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000701 }
702
703 FILETIME ft;
704 (uint64_t&)ft = si.modTime.toWin32Time();
705 BOOL ret = SetFileTime(h, NULL, &ft, &ft);
Jeff Cohen51b8d212004-12-31 19:01:08 +0000706 DWORD err = GetLastError();
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000707 CloseHandle(h);
Jeff Cohen51b8d212004-12-31 19:01:08 +0000708 if (!ret) {
709 SetLastError(err);
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000710 return MakeErrMsg(ErrMsg, path + ": SetFileTime: ");
Jeff Cohen51b8d212004-12-31 19:01:08 +0000711 }
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000712
713 // Best we can do with Unix permission bits is to interpret the owner
714 // writable bit.
715 if (si.mode & 0200) {
716 if (bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
717 if (!SetFileAttributes(path.c_str(),
Jeff Cohend40a7de2004-12-31 05:07:26 +0000718 bhfi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY))
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000719 return MakeErrMsg(ErrMsg, path + ": SetFileAttributes: ");
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000720 }
721 } else {
722 if (!(bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
723 if (!SetFileAttributes(path.c_str(),
Jeff Cohend40a7de2004-12-31 05:07:26 +0000724 bhfi.dwFileAttributes | FILE_ATTRIBUTE_READONLY))
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000725 return MakeErrMsg(ErrMsg, path + ": SetFileAttributes: ");
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000726 }
727 }
728
Chris Lattner1bebfb52006-07-28 22:36:17 +0000729 return false;
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000730}
731
Reid Spencer30300992006-08-24 18:58:37 +0000732bool
733CopyFile(const sys::Path &Dest, const sys::Path &Src, std::string* ErrMsg) {
Jeff Cohencb652552004-12-24 02:38:34 +0000734 // Can't use CopyFile macro defined in Windows.h because it would mess up the
735 // above line. We use the expansion it would have in a non-UNICODE build.
736 if (!::CopyFileA(Src.c_str(), Dest.c_str(), false))
Reid Spencer30300992006-08-24 18:58:37 +0000737 return MakeErrMsg(ErrMsg, "Can't copy '" + Src.toString() +
Jeff Cohend40a7de2004-12-31 05:07:26 +0000738 "' to '" + Dest.toString() + "': ");
Reid Spencer30300992006-08-24 18:58:37 +0000739 return false;
Reid Spencerc29befb2004-12-15 01:50:13 +0000740}
741
Reid Spencer30300992006-08-24 18:58:37 +0000742bool
743Path::makeUnique(bool reuse_current, std::string* ErrMsg) {
Reid Spencer07f9f4e2004-12-15 08:32:45 +0000744 if (reuse_current && !exists())
Reid Spencer30300992006-08-24 18:58:37 +0000745 return false; // File doesn't exist already, just use it!
Reid Spencerc29befb2004-12-15 01:50:13 +0000746
Jeff Cohen9437bb62005-01-27 03:49:03 +0000747 // Reserve space for -XXXXXX at the end.
748 char *FNBuffer = (char*) alloca(path.size()+8);
749 unsigned offset = path.size();
750 path.copy(FNBuffer, offset);
Reid Spencerc29befb2004-12-15 01:50:13 +0000751
Jeff Cohen966fa412005-07-09 18:42:49 +0000752 // Find a numeric suffix that isn't used by an existing file. Assume there
753 // won't be more than 1 million files with the same prefix. Probably a safe
754 // bet.
Jeff Cohen9437bb62005-01-27 03:49:03 +0000755 static unsigned FCounter = 0;
756 do {
757 sprintf(FNBuffer+offset, "-%06u", FCounter);
758 if (++FCounter > 999999)
759 FCounter = 0;
760 path = FNBuffer;
761 } while (exists());
Reid Spencer30300992006-08-24 18:58:37 +0000762 return false;
Reid Spencerc29befb2004-12-15 01:50:13 +0000763}
764
Reid Spencer07f9f4e2004-12-15 08:32:45 +0000765bool
Reid Spencer30300992006-08-24 18:58:37 +0000766Path::createTemporaryFileOnDisk(bool reuse_current, std::string* ErrMsg) {
Reid Spencer07f9f4e2004-12-15 08:32:45 +0000767 // Make this into a unique file name
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000768 makeUnique(reuse_current, ErrMsg);
Jeff Cohen9437bb62005-01-27 03:49:03 +0000769
770 // Now go and create it
771 HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW,
772 FILE_ATTRIBUTE_NORMAL, NULL);
773 if (h == INVALID_HANDLE_VALUE)
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000774 return MakeErrMsg(ErrMsg, path + ": can't create file");
Jeff Cohen9437bb62005-01-27 03:49:03 +0000775
776 CloseHandle(h);
Reid Spencer30300992006-08-24 18:58:37 +0000777 return false;
Reid Spencer07f9f4e2004-12-15 08:32:45 +0000778}
779
Chris Lattner799ed102008-04-01 06:00:12 +0000780/// MapInFilePages - Not yet implemented on win32.
781const char *Path::MapInFilePages(int FD, uint64_t FileSize) {
782 return 0;
783}
784
785/// MapInFilePages - Not yet implemented on win32.
786void Path::UnMapFilePages(const char *Base, uint64_t FileSize) {
787 assert(0 && "NOT IMPLEMENTED");
788}
789
Reid Spencerb016a372004-09-15 05:49:50 +0000790}
Reid Spencercbad7012004-09-11 04:59:30 +0000791}