blob: 0499e617957d0727c0872c33efb9bd4ccdb5dc17 [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 {
Reid Spencercbad7012004-09-11 04:59:30 +000047
Chris Lattnere1b332a2008-02-27 06:17:10 +000048extern const char sys::PathSeparator = ';';
49
Reid Spencerb016a372004-09-15 05:49:50 +000050bool
Reid Spencer07adb282004-11-05 22:15:36 +000051Path::isValid() const {
Reid Spencerb016a372004-09-15 05:49:50 +000052 if (path.empty())
53 return false;
Reid Spencerd0c9e0e2004-09-18 19:29:16 +000054
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000055 // If there is a colon, it must be the second character, preceded by a letter
56 // and followed by something.
57 size_t len = path.size();
58 size_t pos = path.rfind(':',len);
Jeff Cohen8f0e8f22005-07-08 04:50:08 +000059 size_t rootslash = 0;
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000060 if (pos != std::string::npos) {
61 if (pos != 1 || !isalpha(path[0]) || len < 3)
62 return false;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +000063 rootslash = 2;
64 }
Jeff Cohen85c716f2005-07-08 05:02:13 +000065
Jeff Cohen8f0e8f22005-07-08 04:50:08 +000066 // Look for a UNC path, and if found adjust our notion of the root slash.
67 if (len > 3 && path[0] == '/' && path[1] == '/') {
68 rootslash = path.find('/', 2);
69 if (rootslash == std::string::npos)
70 rootslash = 0;
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000071 }
Reid Spencerd0c9e0e2004-09-18 19:29:16 +000072
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000073 // Check for illegal characters.
74 if (path.find_first_of("\\<>\"|\001\002\003\004\005\006\007\010\011\012"
75 "\013\014\015\016\017\020\021\022\023\024\025\026"
76 "\027\030\031\032\033\034\035\036\037")
77 != std::string::npos)
78 return false;
Jeff Cohen85c716f2005-07-08 05:02:13 +000079
Jeff Cohen8f0e8f22005-07-08 04:50:08 +000080 // Remove trailing slash, unless it's a root slash.
81 if (len > rootslash+1 && path[len-1] == '/')
82 path.erase(--len);
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000083
Jeff Cohen3bbbcc12005-01-14 04:09:39 +000084 // Check each component for legality.
85 for (pos = 0; pos < len; ++pos) {
86 // A component may not end in a space.
87 if (path[pos] == ' ') {
88 if (path[pos+1] == '/' || path[pos+1] == '\0')
89 return false;
90 }
Reid Spencer6a0ec6f2004-09-29 00:01:17 +000091
Jeff Cohen3bbbcc12005-01-14 04:09:39 +000092 // A component may not end in a period.
93 if (path[pos] == '.') {
94 if (path[pos+1] == '/' || path[pos+1] == '\0') {
95 // Unless it is the pseudo-directory "."...
96 if (pos == 0 || path[pos-1] == '/' || path[pos-1] == ':')
97 return true;
98 // or "..".
99 if (pos > 0 && path[pos-1] == '.') {
100 if (pos == 1 || path[pos-2] == '/' || path[pos-2] == ':')
101 return true;
102 }
103 return false;
104 }
105 }
106 }
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000107
108 return true;
Reid Spencercbad7012004-09-11 04:59:30 +0000109}
110
Reid Spencer69cce812007-03-29 16:43:20 +0000111bool
112Path::isAbsolute() const {
Jeff Cohen84892be2007-03-29 17:27:38 +0000113 switch (path.length()) {
114 case 0:
115 return false;
116 case 1:
117 case 2:
118 return path[0] == '/';
119 default:
120 return path[0] == '/' || (path[1] == ':' && path[2] == '/');
121 }
Reid Spencer69cce812007-03-29 16:43:20 +0000122}
123
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000124static Path *TempDirectory = NULL;
125
Reid Spencerb016a372004-09-15 05:49:50 +0000126Path
Reid Spencercab0e432006-08-22 22:46:39 +0000127Path::GetTemporaryDirectory(std::string* ErrMsg) {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000128 if (TempDirectory)
129 return *TempDirectory;
130
131 char pathname[MAX_PATH];
Reid Spencercab0e432006-08-22 22:46:39 +0000132 if (!GetTempPath(MAX_PATH, pathname)) {
133 if (ErrMsg)
134 *ErrMsg = "Can't determine temporary directory";
135 return Path();
136 }
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000137
Reid Spencerb016a372004-09-15 05:49:50 +0000138 Path result;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000139 result.set(pathname);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000140
141 // Append a subdirectory passed on our process id so multiple LLVMs don't
142 // step on each other's toes.
Jeff Cohend41b30d2006-11-05 19:31:28 +0000143#ifdef __MINGW32__
144 // Mingw's Win32 header files are broken.
Reid Spencerab4d9b02006-06-08 18:08:43 +0000145 sprintf(pathname, "LLVM_%u", unsigned(GetCurrentProcessId()));
Jeff Cohend41b30d2006-11-05 19:31:28 +0000146#else
147 sprintf(pathname, "LLVM_%u", GetCurrentProcessId());
148#endif
Jeff Cohenedb9d6b2005-07-08 02:48:42 +0000149 result.appendComponent(pathname);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000150
151 // If there's a directory left over from a previous LLVM execution that
152 // happened to have the same process id, get rid of it.
Reid Spencera229c5c2005-07-08 03:08:58 +0000153 result.eraseFromDisk(true);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000154
155 // And finally (re-)create the empty directory.
Reid Spencera229c5c2005-07-08 03:08:58 +0000156 result.createDirectoryOnDisk(false);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000157 TempDirectory = new Path(result);
158 return *TempDirectory;
Reid Spencerb016a372004-09-15 05:49:50 +0000159}
160
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000161// FIXME: the following set of functions don't map to Windows very well.
Reid Spencerb016a372004-09-15 05:49:50 +0000162Path
163Path::GetRootDirectory() {
164 Path result;
Jeff Cohen966fa412005-07-09 18:42:49 +0000165 result.set("C:/");
Reid Spencerb016a372004-09-15 05:49:50 +0000166 return result;
167}
168
Jeff Cohen85c716f2005-07-08 05:02:13 +0000169void
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000170Path::GetSystemLibraryPaths(std::vector<sys::Path>& Paths) {
Jeff Cohen966fa412005-07-09 18:42:49 +0000171 Paths.push_back(sys::Path("C:/WINDOWS/SYSTEM32"));
172 Paths.push_back(sys::Path("C:/WINDOWS"));
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000173}
174
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000175void
Gabor Greifdb5565a2007-07-06 20:28:40 +0000176Path::GetBitcodeLibraryPaths(std::vector<sys::Path>& Paths) {
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000177 char * env_var = getenv("LLVM_LIB_SEARCH_PATH");
178 if (env_var != 0) {
179 getPathList(env_var,Paths);
180 }
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000181#ifdef LLVM_LIBDIR
182 {
183 Path tmpPath;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000184 if (tmpPath.set(LLVM_LIBDIR))
Reid Spencerc7f08322005-07-07 18:21:42 +0000185 if (tmpPath.canRead())
Reid Spencer6c4b7bd2004-12-13 03:03:42 +0000186 Paths.push_back(tmpPath);
187 }
188#endif
189 GetSystemLibraryPaths(Paths);
Reid Spencerb016a372004-09-15 05:49:50 +0000190}
191
192Path
193Path::GetLLVMDefaultConfigDir() {
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000194 // TODO: this isn't going to fly on Windows
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000195 return Path("/etc/llvm");
Reid Spencerb016a372004-09-15 05:49:50 +0000196}
197
198Path
Reid Spencerb016a372004-09-15 05:49:50 +0000199Path::GetUserHomeDirectory() {
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000200 // TODO: Typical Windows setup doesn't define HOME.
Reid Spencerb016a372004-09-15 05:49:50 +0000201 const char* home = getenv("HOME");
202 if (home) {
203 Path result;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000204 if (result.set(home))
Reid Spencerb016a372004-09-15 05:49:50 +0000205 return result;
206 }
207 return GetRootDirectory();
208}
Ted Kremenek79200782007-12-18 22:07:33 +0000209
210Path
211Path::GetCurrentDirectory() {
212 char pathname[MAX_PATH];
Anton Korobeynikov64ddbe42007-12-22 14:26:49 +0000213 ::GetCurrentDirectoryA(MAX_PATH,pathname);
Ted Kremenek79200782007-12-18 22:07:33 +0000214 return Path(pathname);
215}
216
Chris Lattner1a091442008-03-03 02:55:43 +0000217/// GetMainExecutable - Return the path to the main executable, given the
218/// value of argv[0] from program startup.
219Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
220 return Path();
221}
222
Ted Kremenek79200782007-12-18 22:07:33 +0000223
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000224// FIXME: the above set of functions don't map to Windows very well.
225
Jeff Cohen966fa412005-07-09 18:42:49 +0000226
227bool
228Path::isRootDirectory() const {
229 size_t len = path.size();
230 return len > 0 && path[len-1] == '/';
Reid Spencera229c5c2005-07-08 03:08:58 +0000231}
232
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000233std::string
Reid Spencer07adb282004-11-05 22:15:36 +0000234Path::getBasename() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000235 // Find the last slash
236 size_t slash = path.rfind('/');
237 if (slash == std::string::npos)
238 slash = 0;
239 else
240 slash++;
241
Jeff Cohen966fa412005-07-09 18:42:49 +0000242 size_t dot = path.rfind('.');
243 if (dot == std::string::npos || dot < slash)
244 return path.substr(slash);
245 else
246 return path.substr(slash, dot - slash);
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000247}
248
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000249bool
Reid Spencerb016a372004-09-15 05:49:50 +0000250Path::exists() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000251 DWORD attr = GetFileAttributes(path.c_str());
252 return attr != INVALID_FILE_ATTRIBUTES;
Reid Spencerb016a372004-09-15 05:49:50 +0000253}
254
255bool
Ted Kremenekfd527112007-12-18 19:46:22 +0000256Path::isDirectory() const {
257 DWORD attr = GetFileAttributes(path.c_str());
258 return (attr != INVALID_FILE_ATTRIBUTES) &&
259 (attr & FILE_ATTRIBUTE_DIRECTORY);
260}
261
262bool
Reid Spencerc7f08322005-07-07 18:21:42 +0000263Path::canRead() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000264 // FIXME: take security attributes into account.
265 DWORD attr = GetFileAttributes(path.c_str());
266 return attr != INVALID_FILE_ATTRIBUTES;
Reid Spencerb016a372004-09-15 05:49:50 +0000267}
268
269bool
Reid Spencerc7f08322005-07-07 18:21:42 +0000270Path::canWrite() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000271 // FIXME: take security attributes into account.
272 DWORD attr = GetFileAttributes(path.c_str());
273 return (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_READONLY);
Reid Spencerb016a372004-09-15 05:49:50 +0000274}
275
276bool
Reid Spencerc7f08322005-07-07 18:21:42 +0000277Path::canExecute() const {
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000278 // FIXME: take security attributes into account.
279 DWORD attr = GetFileAttributes(path.c_str());
280 return attr != INVALID_FILE_ATTRIBUTES;
Reid Spencerb016a372004-09-15 05:49:50 +0000281}
282
283std::string
284Path::getLast() const {
285 // Find the last slash
286 size_t pos = path.rfind('/');
287
288 // Handle the corner cases
289 if (pos == std::string::npos)
290 return path;
291
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000292 // If the last character is a slash, we have a root directory
293 if (pos == path.length()-1)
294 return path;
295
Reid Spencerb016a372004-09-15 05:49:50 +0000296 // Return everything after the last slash
297 return path.substr(pos+1);
298}
299
Reid Spencer8475ec02007-03-29 19:05:44 +0000300const FileStatus *
Reid Spencer2ae9d112007-04-07 18:52:17 +0000301PathWithStatus::getFileStatus(bool update, std::string *ErrStr) const {
302 if (!fsIsValid || update) {
Reid Spencer69cce812007-03-29 16:43:20 +0000303 WIN32_FILE_ATTRIBUTE_DATA fi;
Reid Spencer8475ec02007-03-29 19:05:44 +0000304 if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) {
305 MakeErrMsg(ErrStr, "getStatusInfo():" + std::string(path) +
Reid Spencer69cce812007-03-29 16:43:20 +0000306 ": Can't get status: ");
Reid Spencer8475ec02007-03-29 19:05:44 +0000307 return 0;
308 }
Jeff Cohen626e38e2004-12-14 05:26:43 +0000309
Reid Spencer2ae9d112007-04-07 18:52:17 +0000310 status.fileSize = fi.nFileSizeHigh;
311 status.fileSize <<= sizeof(fi.nFileSizeHigh)*8;
312 status.fileSize += fi.nFileSizeLow;
Jeff Cohen626e38e2004-12-14 05:26:43 +0000313
Reid Spencer2ae9d112007-04-07 18:52:17 +0000314 status.mode = fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0555 : 0777;
315 status.user = 9999; // Not applicable to Windows, so...
316 status.group = 9999; // Not applicable to Windows, so...
Jeff Cohen626e38e2004-12-14 05:26:43 +0000317
Reid Spencer4031bef2007-03-29 17:00:31 +0000318 // FIXME: this is only unique if the file is accessed by the same file path.
319 // How do we do this for C:\dir\file and ..\dir\file ? Unix has inode
320 // numbers, but the concept doesn't exist in Windows.
Reid Spencer2ae9d112007-04-07 18:52:17 +0000321 status.uniqueID = 0;
Reid Spencer4031bef2007-03-29 17:00:31 +0000322 for (unsigned i = 0; i < path.length(); ++i)
Reid Spencer2ae9d112007-04-07 18:52:17 +0000323 status.uniqueID += path[i];
Reid Spencer4031bef2007-03-29 17:00:31 +0000324
Reid Spencer69cce812007-03-29 16:43:20 +0000325 __int64 ft = *reinterpret_cast<__int64*>(&fi.ftLastWriteTime);
Reid Spencer2ae9d112007-04-07 18:52:17 +0000326 status.modTime.fromWin32Time(ft);
Reid Spencer69cce812007-03-29 16:43:20 +0000327
Reid Spencer2ae9d112007-04-07 18:52:17 +0000328 status.isDir = fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
329 fsIsValid = true;
Reid Spencer69cce812007-03-29 16:43:20 +0000330 }
Reid Spencer2ae9d112007-04-07 18:52:17 +0000331 return &status;
Jeff Cohen626e38e2004-12-14 05:26:43 +0000332}
333
Reid Spencera34a1572006-08-22 23:54:35 +0000334bool Path::makeReadableOnDisk(std::string* ErrMsg) {
Jeff Cohen626e38e2004-12-14 05:26:43 +0000335 // All files are readable on Windows (ignoring security attributes).
Reid Spencera34a1572006-08-22 23:54:35 +0000336 return false;
Reid Spencer77cc91d2004-12-13 19:59:50 +0000337}
338
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000339bool Path::makeWriteableOnDisk(std::string* ErrMsg) {
Jeff Cohen626e38e2004-12-14 05:26:43 +0000340 DWORD attr = GetFileAttributes(path.c_str());
341
342 // If it doesn't exist, we're done.
343 if (attr == INVALID_FILE_ATTRIBUTES)
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000344 return false;
Jeff Cohen626e38e2004-12-14 05:26:43 +0000345
346 if (attr & FILE_ATTRIBUTE_READONLY) {
Reid Spencera34a1572006-08-22 23:54:35 +0000347 if (!SetFileAttributes(path.c_str(), attr & ~FILE_ATTRIBUTE_READONLY)) {
348 MakeErrMsg(ErrMsg, std::string(path) + ": Can't make file writable: ");
349 return true;
350 }
Jeff Cohen626e38e2004-12-14 05:26:43 +0000351 }
Reid Spencera34a1572006-08-22 23:54:35 +0000352 return false;
Reid Spencer77cc91d2004-12-13 19:59:50 +0000353}
354
Reid Spencera34a1572006-08-22 23:54:35 +0000355bool Path::makeExecutableOnDisk(std::string* ErrMsg) {
Jeff Cohen626e38e2004-12-14 05:26:43 +0000356 // All files are executable on Windows (ignoring security attributes).
Reid Spencera34a1572006-08-22 23:54:35 +0000357 return false;
Reid Spencer77cc91d2004-12-13 19:59:50 +0000358}
359
Reid Spencerb016a372004-09-15 05:49:50 +0000360bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000361Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const {
Jeff Cohen31102892007-04-07 20:47:27 +0000362 WIN32_FILE_ATTRIBUTE_DATA fi;
363 if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) {
364 MakeErrMsg(ErrMsg, path + ": can't get status of file");
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000365 return true;
Jeff Cohen31102892007-04-07 20:47:27 +0000366 }
367
368 if (!(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
369 if (ErrMsg)
370 *ErrMsg = path + ": not a directory";
Reid Spencer142ca8e2006-08-23 06:56:27 +0000371 return true;
372 }
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000373
374 result.clear();
375 WIN32_FIND_DATA fd;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000376 std::string searchpath = path;
377 if (path.size() == 0 || searchpath[path.size()-1] == '/')
Jeff Cohen85c716f2005-07-08 05:02:13 +0000378 searchpath += "*";
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000379 else
380 searchpath += "/*";
Jeff Cohen85c716f2005-07-08 05:02:13 +0000381
Jeff Cohen9437bb62005-01-27 03:49:03 +0000382 HANDLE h = FindFirstFile(searchpath.c_str(), &fd);
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000383 if (h == INVALID_HANDLE_VALUE) {
Jeff Cohen9437bb62005-01-27 03:49:03 +0000384 if (GetLastError() == ERROR_FILE_NOT_FOUND)
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000385 return true; // not really an error, now is it?
Reid Spencer142ca8e2006-08-23 06:56:27 +0000386 MakeErrMsg(ErrMsg, path + ": Can't read directory: ");
387 return true;
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000388 }
389
390 do {
Jeff Cohend40a7de2004-12-31 05:07:26 +0000391 if (fd.cFileName[0] == '.')
392 continue;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000393 Path aPath(path);
394 aPath.appendComponent(&fd.cFileName[0]);
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000395 result.insert(aPath);
396 } while (FindNextFile(h, &fd));
397
Jeff Cohen51b8d212004-12-31 19:01:08 +0000398 DWORD err = GetLastError();
399 FindClose(h);
400 if (err != ERROR_NO_MORE_FILES) {
401 SetLastError(err);
Reid Spencer142ca8e2006-08-23 06:56:27 +0000402 MakeErrMsg(ErrMsg, path + ": Can't read directory: ");
403 return true;
Jeff Cohen51b8d212004-12-31 19:01:08 +0000404 }
Reid Spencer142ca8e2006-08-23 06:56:27 +0000405 return false;
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000406}
407
408bool
Reid Spencer1cf2d042005-07-07 23:35:23 +0000409Path::set(const std::string& a_path) {
Dan Gohman30359592008-01-29 13:02:09 +0000410 if (a_path.empty())
Reid Spencerb016a372004-09-15 05:49:50 +0000411 return false;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000412 std::string save(path);
Reid Spencerb016a372004-09-15 05:49:50 +0000413 path = a_path;
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000414 FlipBackSlashes(path);
Reid Spencer07adb282004-11-05 22:15:36 +0000415 if (!isValid()) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000416 path = save;
Reid Spencerb016a372004-09-15 05:49:50 +0000417 return false;
418 }
419 return true;
420}
421
422bool
Jeff Cohenedb9d6b2005-07-08 02:48:42 +0000423Path::appendComponent(const std::string& name) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000424 if (name.empty())
Reid Spencerb016a372004-09-15 05:49:50 +0000425 return false;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000426 std::string save(path);
427 if (!path.empty()) {
428 size_t last = path.size() - 1;
Jeff Cohen85c716f2005-07-08 05:02:13 +0000429 if (path[last] != '/')
Reid Spencer1cf2d042005-07-07 23:35:23 +0000430 path += '/';
431 }
432 path += name;
Reid Spencer07adb282004-11-05 22:15:36 +0000433 if (!isValid()) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000434 path = save;
Reid Spencerb016a372004-09-15 05:49:50 +0000435 return false;
436 }
437 return true;
438}
439
440bool
Reid Spencer1cf2d042005-07-07 23:35:23 +0000441Path::eraseComponent() {
Reid Spencerb016a372004-09-15 05:49:50 +0000442 size_t slashpos = path.rfind('/',path.size());
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000443 if (slashpos == path.size() - 1 || slashpos == std::string::npos)
Reid Spencerb016a372004-09-15 05:49:50 +0000444 return false;
Jeff Cohen966fa412005-07-09 18:42:49 +0000445 std::string save(path);
Reid Spencerb016a372004-09-15 05:49:50 +0000446 path.erase(slashpos);
Jeff Cohen966fa412005-07-09 18:42:49 +0000447 if (!isValid()) {
448 path = save;
449 return false;
450 }
Reid Spencerb016a372004-09-15 05:49:50 +0000451 return true;
452}
453
454bool
Reid Spencer07adb282004-11-05 22:15:36 +0000455Path::appendSuffix(const std::string& suffix) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000456 std::string save(path);
Reid Spencerb016a372004-09-15 05:49:50 +0000457 path.append(".");
458 path.append(suffix);
Reid Spencer07adb282004-11-05 22:15:36 +0000459 if (!isValid()) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000460 path = save;
Reid Spencerb016a372004-09-15 05:49:50 +0000461 return false;
462 }
463 return true;
464}
465
466bool
Reid Spencer1cf2d042005-07-07 23:35:23 +0000467Path::eraseSuffix() {
Reid Spencerb016a372004-09-15 05:49:50 +0000468 size_t dotpos = path.rfind('.',path.size());
469 size_t slashpos = path.rfind('/',path.size());
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000470 if (dotpos != std::string::npos) {
Jeff Cohen966fa412005-07-09 18:42:49 +0000471 if (slashpos == std::string::npos || dotpos > slashpos+1) {
472 std::string save(path);
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000473 path.erase(dotpos, path.size()-dotpos);
Jeff Cohen966fa412005-07-09 18:42:49 +0000474 if (!isValid()) {
475 path = save;
476 return false;
477 }
Jeff Cohen85c716f2005-07-08 05:02:13 +0000478 return true;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000479 }
Reid Spencerb016a372004-09-15 05:49:50 +0000480 }
481 return false;
482}
483
Reid Spencer30300992006-08-24 18:58:37 +0000484inline bool PathMsg(std::string* ErrMsg, const char* pathname, const char*msg) {
485 if (ErrMsg)
486 *ErrMsg = std::string(pathname) + ": " + std::string(msg);
487 return true;
488}
489
Reid Spencerb016a372004-09-15 05:49:50 +0000490bool
Reid Spencer30300992006-08-24 18:58:37 +0000491Path::createDirectoryOnDisk(bool create_parents, std::string* ErrMsg) {
Reid Spencerb016a372004-09-15 05:49:50 +0000492 // Get a writeable copy of the path name
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000493 size_t len = path.length();
494 char *pathname = reinterpret_cast<char *>(_alloca(len+2));
495 path.copy(pathname, len);
496 pathname[len] = 0;
Jeff Cohen85c716f2005-07-08 05:02:13 +0000497
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000498 // Make sure it ends with a slash.
499 if (len == 0 || pathname[len - 1] != '/') {
500 pathname[len] = '/';
501 pathname[++len] = 0;
502 }
Reid Spencerb016a372004-09-15 05:49:50 +0000503
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000504 // Determine starting point for initial / search.
505 char *next = pathname;
506 if (pathname[0] == '/' && pathname[1] == '/') {
507 // Skip host name.
508 next = strchr(pathname+2, '/');
509 if (next == NULL)
Reid Spencer30300992006-08-24 18:58:37 +0000510 return PathMsg(ErrMsg, pathname, "badly formed remote directory");
511
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000512 // Skip share name.
513 next = strchr(next+1, '/');
514 if (next == NULL)
Reid Spencer30300992006-08-24 18:58:37 +0000515 return PathMsg(ErrMsg, pathname,"badly formed remote directory");
516
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000517 next++;
518 if (*next == 0)
Reid Spencer30300992006-08-24 18:58:37 +0000519 return PathMsg(ErrMsg, pathname, "badly formed remote directory");
520
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000521 } else {
522 if (pathname[1] == ':')
523 next += 2; // skip drive letter
524 if (*next == '/')
525 next++; // skip root directory
526 }
Reid Spencerb016a372004-09-15 05:49:50 +0000527
528 // If we're supposed to create intermediate directories
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000529 if (create_parents) {
Reid Spencerb016a372004-09-15 05:49:50 +0000530 // Loop through the directory components until we're done
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000531 while (*next) {
532 next = strchr(next, '/');
Reid Spencerb016a372004-09-15 05:49:50 +0000533 *next = 0;
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000534 if (!CreateDirectory(pathname, NULL))
Reid Spencer30300992006-08-24 18:58:37 +0000535 return MakeErrMsg(ErrMsg,
536 std::string(pathname) + ": Can't create directory: ");
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000537 *next++ = '/';
Reid Spencerb016a372004-09-15 05:49:50 +0000538 }
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000539 } else {
540 // Drop trailing slash.
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000541 pathname[len-1] = 0;
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000542 if (!CreateDirectory(pathname, NULL)) {
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000543 return MakeErrMsg(ErrMsg, std::string(pathname) + ": Can't create directory: ");
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000544 }
Reid Spencerb016a372004-09-15 05:49:50 +0000545 }
Reid Spencer30300992006-08-24 18:58:37 +0000546 return false;
Reid Spencerb016a372004-09-15 05:49:50 +0000547}
548
549bool
Reid Spencer30300992006-08-24 18:58:37 +0000550Path::createFileOnDisk(std::string* ErrMsg) {
Reid Spencerb016a372004-09-15 05:49:50 +0000551 // Create the file
Reid Spencer6a0ec6f2004-09-29 00:01:17 +0000552 HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW,
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000553 FILE_ATTRIBUTE_NORMAL, NULL);
554 if (h == INVALID_HANDLE_VALUE)
Reid Spencer30300992006-08-24 18:58:37 +0000555 return MakeErrMsg(ErrMsg, path + ": Can't create file: ");
Reid Spencerb016a372004-09-15 05:49:50 +0000556
Reid Spencerd0c9e0e2004-09-18 19:29:16 +0000557 CloseHandle(h);
Reid Spencer30300992006-08-24 18:58:37 +0000558 return false;
Reid Spencerb016a372004-09-15 05:49:50 +0000559}
560
561bool
Chris Lattner0c332312006-07-28 22:29:50 +0000562Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
Jeff Cohen31102892007-04-07 20:47:27 +0000563 WIN32_FILE_ATTRIBUTE_DATA fi;
564 if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
565 return true;
Chris Lattnerc7c453a2006-08-01 17:51:09 +0000566
Jeff Cohen31102892007-04-07 20:47:27 +0000567 if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
Reid Spencer1cf2d042005-07-07 23:35:23 +0000568 // If it doesn't exist, we're done.
Jeff Cohen85c716f2005-07-08 05:02:13 +0000569 if (!exists())
Chris Lattner0c332312006-07-28 22:29:50 +0000570 return false;
Reid Spencer1cf2d042005-07-07 23:35:23 +0000571
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000572 char *pathname = reinterpret_cast<char *>(_alloca(path.length()+3));
Reid Spencer1cf2d042005-07-07 23:35:23 +0000573 int lastchar = path.length() - 1 ;
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000574 path.copy(pathname, lastchar+1);
Reid Spencer1cf2d042005-07-07 23:35:23 +0000575
576 // Make path end with '/*'.
Jeff Cohen8f0e8f22005-07-08 04:50:08 +0000577 if (pathname[lastchar] != '/')
578 pathname[++lastchar] = '/';
Reid Spencer1cf2d042005-07-07 23:35:23 +0000579 pathname[lastchar+1] = '*';
580 pathname[lastchar+2] = 0;
581
582 if (remove_contents) {
583 WIN32_FIND_DATA fd;
584 HANDLE h = FindFirstFile(pathname, &fd);
585
586 // It's a bad idea to alter the contents of a directory while enumerating
587 // its contents. So build a list of its contents first, then destroy them.
588
589 if (h != INVALID_HANDLE_VALUE) {
590 std::vector<Path> list;
591
592 do {
593 if (strcmp(fd.cFileName, ".") == 0)
594 continue;
595 if (strcmp(fd.cFileName, "..") == 0)
596 continue;
597
Jeff Cohen85c716f2005-07-08 05:02:13 +0000598 Path aPath(path);
599 aPath.appendComponent(&fd.cFileName[0]);
Reid Spencer1cf2d042005-07-07 23:35:23 +0000600 list.push_back(aPath);
601 } while (FindNextFile(h, &fd));
602
603 DWORD err = GetLastError();
604 FindClose(h);
605 if (err != ERROR_NO_MORE_FILES) {
606 SetLastError(err);
Reid Spencer05545752006-08-25 21:37:17 +0000607 return MakeErrMsg(ErrStr, path + ": Can't read directory: ");
Reid Spencer1cf2d042005-07-07 23:35:23 +0000608 }
609
Jeff Cohen85c716f2005-07-08 05:02:13 +0000610 for (std::vector<Path>::iterator I = list.begin(); I != list.end();
Reid Spencer1cf2d042005-07-07 23:35:23 +0000611 ++I) {
612 Path &aPath = *I;
Reid Spencera229c5c2005-07-08 03:08:58 +0000613 aPath.eraseFromDisk(true);
Reid Spencer1cf2d042005-07-07 23:35:23 +0000614 }
615 } else {
616 if (GetLastError() != ERROR_FILE_NOT_FOUND)
Reid Spencer05545752006-08-25 21:37:17 +0000617 return MakeErrMsg(ErrStr, path + ": Can't read directory: ");
Reid Spencer1cf2d042005-07-07 23:35:23 +0000618 }
619 }
620
621 pathname[lastchar] = 0;
622 if (!RemoveDirectory(pathname))
Reid Spencer05545752006-08-25 21:37:17 +0000623 return MakeErrMsg(ErrStr,
624 std::string(pathname) + ": Can't destroy directory: ");
Chris Lattner0c332312006-07-28 22:29:50 +0000625 return false;
Jeff Cohen31102892007-04-07 20:47:27 +0000626 } else {
627 // Read-only files cannot be deleted on Windows. Must remove the read-only
628 // attribute first.
629 if (fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
630 if (!SetFileAttributes(path.c_str(),
631 fi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY))
632 return MakeErrMsg(ErrStr, path + ": Can't destroy file: ");
633 }
634
635 if (!DeleteFile(path.c_str()))
636 return MakeErrMsg(ErrStr, path + ": Can't destroy file: ");
637 return false;
638 }
Reid Spencerb016a372004-09-15 05:49:50 +0000639}
640
Reid Spencer3b0cc782004-12-14 18:42:13 +0000641bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
Reid Spencer3b0cc782004-12-14 18:42:13 +0000642 assert(len < 1024 && "Request for magic string too long");
643 char* buf = (char*) alloca(1 + len);
Jeff Cohen51b8d212004-12-31 19:01:08 +0000644
645 HANDLE h = CreateFile(path.c_str(),
646 GENERIC_READ,
647 FILE_SHARE_READ,
648 NULL,
649 OPEN_EXISTING,
650 FILE_ATTRIBUTE_NORMAL,
651 NULL);
652 if (h == INVALID_HANDLE_VALUE)
Reid Spencer3b0cc782004-12-14 18:42:13 +0000653 return false;
Jeff Cohen51b8d212004-12-31 19:01:08 +0000654
655 DWORD nRead = 0;
656 BOOL ret = ReadFile(h, buf, len, &nRead, NULL);
657 CloseHandle(h);
658
659 if (!ret || nRead != len)
Reid Spencer3b0cc782004-12-14 18:42:13 +0000660 return false;
Jeff Cohen51b8d212004-12-31 19:01:08 +0000661
Reid Spencer3b0cc782004-12-14 18:42:13 +0000662 buf[len] = '\0';
663 Magic = buf;
664 return true;
665}
666
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000667bool
Reid Spencer5a060772006-08-23 07:30:48 +0000668Path::renamePathOnDisk(const Path& newName, std::string* ErrMsg) {
Jeff Cohene564de22006-05-07 02:51:51 +0000669 if (!MoveFileEx(path.c_str(), newName.c_str(), MOVEFILE_REPLACE_EXISTING))
Reid Spencer5a060772006-08-23 07:30:48 +0000670 return MakeErrMsg(ErrMsg, "Can't move '" + path + "' to '" + newName.path
671 + "': ");
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000672 return true;
673}
674
675bool
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000676Path::setStatusInfoOnDisk(const FileStatus &si, std::string *ErrMsg) const {
Jeff Cohen966fa412005-07-09 18:42:49 +0000677 // FIXME: should work on directories also.
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000678 if (!si.isFile) {
679 return true;
680 }
681
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000682 HANDLE h = CreateFile(path.c_str(),
683 FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
684 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
Jeff Cohend40a7de2004-12-31 05:07:26 +0000685 NULL,
686 OPEN_EXISTING,
687 FILE_ATTRIBUTE_NORMAL,
688 NULL);
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000689 if (h == INVALID_HANDLE_VALUE)
Chris Lattner1bebfb52006-07-28 22:36:17 +0000690 return true;
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000691
692 BY_HANDLE_FILE_INFORMATION bhfi;
693 if (!GetFileInformationByHandle(h, &bhfi)) {
Jeff Cohen51b8d212004-12-31 19:01:08 +0000694 DWORD err = GetLastError();
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000695 CloseHandle(h);
Jeff Cohen51b8d212004-12-31 19:01:08 +0000696 SetLastError(err);
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000697 return MakeErrMsg(ErrMsg, path + ": GetFileInformationByHandle: ");
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000698 }
699
700 FILETIME ft;
701 (uint64_t&)ft = si.modTime.toWin32Time();
702 BOOL ret = SetFileTime(h, NULL, &ft, &ft);
Jeff Cohen51b8d212004-12-31 19:01:08 +0000703 DWORD err = GetLastError();
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000704 CloseHandle(h);
Jeff Cohen51b8d212004-12-31 19:01:08 +0000705 if (!ret) {
706 SetLastError(err);
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000707 return MakeErrMsg(ErrMsg, path + ": SetFileTime: ");
Jeff Cohen51b8d212004-12-31 19:01:08 +0000708 }
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000709
710 // Best we can do with Unix permission bits is to interpret the owner
711 // writable bit.
712 if (si.mode & 0200) {
713 if (bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
714 if (!SetFileAttributes(path.c_str(),
Jeff Cohend40a7de2004-12-31 05:07:26 +0000715 bhfi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY))
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000716 return MakeErrMsg(ErrMsg, path + ": SetFileAttributes: ");
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000717 }
718 } else {
719 if (!(bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
720 if (!SetFileAttributes(path.c_str(),
Jeff Cohend40a7de2004-12-31 05:07:26 +0000721 bhfi.dwFileAttributes | FILE_ATTRIBUTE_READONLY))
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000722 return MakeErrMsg(ErrMsg, path + ": SetFileAttributes: ");
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000723 }
724 }
725
Chris Lattner1bebfb52006-07-28 22:36:17 +0000726 return false;
Jeff Cohenebcb9b32004-12-31 04:39:07 +0000727}
728
Reid Spencer30300992006-08-24 18:58:37 +0000729bool
730CopyFile(const sys::Path &Dest, const sys::Path &Src, std::string* ErrMsg) {
Jeff Cohencb652552004-12-24 02:38:34 +0000731 // Can't use CopyFile macro defined in Windows.h because it would mess up the
732 // above line. We use the expansion it would have in a non-UNICODE build.
733 if (!::CopyFileA(Src.c_str(), Dest.c_str(), false))
Reid Spencer30300992006-08-24 18:58:37 +0000734 return MakeErrMsg(ErrMsg, "Can't copy '" + Src.toString() +
Jeff Cohend40a7de2004-12-31 05:07:26 +0000735 "' to '" + Dest.toString() + "': ");
Reid Spencer30300992006-08-24 18:58:37 +0000736 return false;
Reid Spencerc29befb2004-12-15 01:50:13 +0000737}
738
Reid Spencer30300992006-08-24 18:58:37 +0000739bool
740Path::makeUnique(bool reuse_current, std::string* ErrMsg) {
Reid Spencer07f9f4e2004-12-15 08:32:45 +0000741 if (reuse_current && !exists())
Reid Spencer30300992006-08-24 18:58:37 +0000742 return false; // File doesn't exist already, just use it!
Reid Spencerc29befb2004-12-15 01:50:13 +0000743
Jeff Cohen9437bb62005-01-27 03:49:03 +0000744 // Reserve space for -XXXXXX at the end.
745 char *FNBuffer = (char*) alloca(path.size()+8);
746 unsigned offset = path.size();
747 path.copy(FNBuffer, offset);
Reid Spencerc29befb2004-12-15 01:50:13 +0000748
Jeff Cohen966fa412005-07-09 18:42:49 +0000749 // Find a numeric suffix that isn't used by an existing file. Assume there
750 // won't be more than 1 million files with the same prefix. Probably a safe
751 // bet.
Jeff Cohen9437bb62005-01-27 03:49:03 +0000752 static unsigned FCounter = 0;
753 do {
754 sprintf(FNBuffer+offset, "-%06u", FCounter);
755 if (++FCounter > 999999)
756 FCounter = 0;
757 path = FNBuffer;
758 } while (exists());
Reid Spencer30300992006-08-24 18:58:37 +0000759 return false;
Reid Spencerc29befb2004-12-15 01:50:13 +0000760}
761
Reid Spencer07f9f4e2004-12-15 08:32:45 +0000762bool
Reid Spencer30300992006-08-24 18:58:37 +0000763Path::createTemporaryFileOnDisk(bool reuse_current, std::string* ErrMsg) {
Reid Spencer07f9f4e2004-12-15 08:32:45 +0000764 // Make this into a unique file name
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000765 makeUnique(reuse_current, ErrMsg);
Jeff Cohen9437bb62005-01-27 03:49:03 +0000766
767 // Now go and create it
768 HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW,
769 FILE_ATTRIBUTE_NORMAL, NULL);
770 if (h == INVALID_HANDLE_VALUE)
Anton Korobeynikov7d515442006-09-01 20:35:17 +0000771 return MakeErrMsg(ErrMsg, path + ": can't create file");
Jeff Cohen9437bb62005-01-27 03:49:03 +0000772
773 CloseHandle(h);
Reid Spencer30300992006-08-24 18:58:37 +0000774 return false;
Reid Spencer07f9f4e2004-12-15 08:32:45 +0000775}
776
Reid Spencerb016a372004-09-15 05:49:50 +0000777}
Reid Spencercbad7012004-09-11 04:59:30 +0000778}