1 //===-- FileSpec.cpp --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
19 #include "lldb/Host/Config.h" // Have to include this before we test the define...
20 #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/Support/Path.h"
26 #include "llvm/Support/Program.h"
28 #include "lldb/Host/File.h"
29 #include "lldb/Host/FileSpec.h"
30 #include "lldb/Core/DataBufferHeap.h"
31 #include "lldb/Core/DataBufferMemoryMap.h"
32 #include "lldb/Core/RegularExpression.h"
33 #include "lldb/Core/Stream.h"
34 #include "lldb/Host/Host.h"
35 #include "lldb/Utility/CleanUp.h"
38 using namespace lldb_private;
41 GetFileStats (const FileSpec *file_spec, struct stat *stats_ptr)
43 char resolved_path[PATH_MAX];
44 if (file_spec->GetPath (resolved_path, sizeof(resolved_path)))
45 return ::stat (resolved_path, stats_ptr) == 0;
49 #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
52 GetCachedGlobTildeSlash()
54 static std::string g_tilde;
57 struct passwd *user_entry;
58 user_entry = getpwuid(geteuid());
59 if (user_entry != NULL)
60 g_tilde = user_entry->pw_dir;
65 return g_tilde.c_str();
68 #endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
70 // Resolves the username part of a path of the form ~user/other/directories, and
71 // writes the result into dst_path.
72 // Returns 0 if there WAS a ~ in the path but the username couldn't be resolved.
73 // Otherwise returns the number of characters copied into dst_path. If the return
74 // is >= dst_len, then the resolved path is too long...
76 FileSpec::ResolveUsername (const char *src_path, char *dst_path, size_t dst_len)
78 if (src_path == NULL || src_path[0] == '\0')
81 #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
83 char user_home[PATH_MAX];
84 const char *user_name;
87 // If there's no ~, then just copy src_path straight to dst_path (they may be the same string...)
88 if (src_path[0] != '~')
90 size_t len = strlen (src_path);
93 ::bcopy (src_path, dst_path, dst_len - 1);
94 dst_path[dst_len] = '\0';
97 ::bcopy (src_path, dst_path, len + 1);
102 const char *first_slash = ::strchr (src_path, '/');
103 char remainder[PATH_MAX];
105 if (first_slash == NULL)
107 // The whole name is the username (minus the ~):
108 user_name = src_path + 1;
113 size_t user_name_len = first_slash - src_path - 1;
114 ::memcpy (user_home, src_path + 1, user_name_len);
115 user_home[user_name_len] = '\0';
116 user_name = user_home;
118 ::strcpy (remainder, first_slash);
121 if (user_name == NULL)
123 // User name of "" means the current user...
125 struct passwd *user_entry;
126 const char *home_dir = NULL;
128 if (user_name[0] == '\0')
130 home_dir = GetCachedGlobTildeSlash();
134 user_entry = ::getpwnam (user_name);
135 if (user_entry != NULL)
136 home_dir = user_entry->pw_dir;
139 if (home_dir == NULL)
142 return ::snprintf (dst_path, dst_len, "%s%s", home_dir, remainder);
144 // Resolving home directories is not supported, just copy the path...
145 return ::snprintf (dst_path, dst_len, "%s", src_path);
146 #endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
150 FileSpec::ResolvePartialUsername (const char *partial_name, StringList &matches)
152 #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
153 size_t extant_entries = matches.GetSize();
156 struct passwd *user_entry;
157 const char *name_start = partial_name + 1;
158 std::set<std::string> name_list;
160 while ((user_entry = getpwent()) != NULL)
162 if (strstr(user_entry->pw_name, name_start) == user_entry->pw_name)
164 std::string tmp_buf("~");
165 tmp_buf.append(user_entry->pw_name);
166 tmp_buf.push_back('/');
167 name_list.insert(tmp_buf);
170 std::set<std::string>::iterator pos, end = name_list.end();
171 for (pos = name_list.begin(); pos != end; pos++)
173 matches.AppendString((*pos).c_str());
175 return matches.GetSize() - extant_entries;
177 // Resolving home directories is not supported, just copy the path...
179 #endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
185 FileSpec::Resolve (const char *src_path, char *dst_path, size_t dst_len)
187 if (src_path == NULL || src_path[0] == '\0')
190 // Glob if needed for ~/, otherwise copy in case src_path is same as dst_path...
191 char unglobbed_path[PATH_MAX];
192 #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
193 if (src_path[0] == '~')
195 size_t return_count = ResolveUsername(src_path, unglobbed_path, sizeof(unglobbed_path));
197 // If we couldn't find the user referred to, or the resultant path was too long,
198 // then just copy over the src_path.
199 if (return_count == 0 || return_count >= sizeof(unglobbed_path))
200 ::snprintf (unglobbed_path, sizeof(unglobbed_path), "%s", src_path);
203 #endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
205 ::snprintf(unglobbed_path, sizeof(unglobbed_path), "%s", src_path);
208 // Now resolve the path if needed
209 char resolved_path[PATH_MAX];
210 if (::realpath (unglobbed_path, resolved_path))
212 // Success, copy the resolved path
213 return ::snprintf(dst_path, dst_len, "%s", resolved_path);
217 // Failed, just copy the unglobbed path
218 return ::snprintf(dst_path, dst_len, "%s", unglobbed_path);
222 FileSpec::FileSpec() :
228 //------------------------------------------------------------------
229 // Default constructor that can take an optional full path to a
231 //------------------------------------------------------------------
232 FileSpec::FileSpec(const char *pathname, bool resolve_path) :
237 if (pathname && pathname[0])
238 SetFile(pathname, resolve_path);
241 //------------------------------------------------------------------
243 //------------------------------------------------------------------
244 FileSpec::FileSpec(const FileSpec& rhs) :
245 m_directory (rhs.m_directory),
246 m_filename (rhs.m_filename),
247 m_is_resolved (rhs.m_is_resolved)
251 //------------------------------------------------------------------
253 //------------------------------------------------------------------
254 FileSpec::FileSpec(const FileSpec* rhs) :
262 //------------------------------------------------------------------
263 // Virtual destrcuctor in case anyone inherits from this class.
264 //------------------------------------------------------------------
265 FileSpec::~FileSpec()
269 //------------------------------------------------------------------
270 // Assignment operator.
271 //------------------------------------------------------------------
273 FileSpec::operator= (const FileSpec& rhs)
277 m_directory = rhs.m_directory;
278 m_filename = rhs.m_filename;
279 m_is_resolved = rhs.m_is_resolved;
284 //------------------------------------------------------------------
285 // Update the contents of this object with a new path. The path will
286 // be split up into a directory and filename and stored as uniqued
287 // string values for quick comparison and efficient memory usage.
288 //------------------------------------------------------------------
290 FileSpec::SetFile (const char *pathname, bool resolve)
294 m_is_resolved = false;
295 if (pathname == NULL || pathname[0] == '\0')
298 char resolved_path[PATH_MAX];
299 bool path_fit = true;
303 path_fit = (FileSpec::Resolve (pathname, resolved_path, sizeof(resolved_path)) < sizeof(resolved_path) - 1);
304 m_is_resolved = path_fit;
308 // Copy the path because "basename" and "dirname" want to muck with the
310 if (::strlen (pathname) > sizeof(resolved_path) - 1)
313 ::strcpy (resolved_path, pathname);
319 char *filename = ::basename (resolved_path);
322 m_filename.SetCString (filename);
323 // Truncate the basename off the end of the resolved path
325 // Only attempt to get the dirname if it looks like we have a path
326 if (strchr(resolved_path, '/'))
328 char *directory = ::dirname (resolved_path);
330 // Make sure we didn't get our directory resolved to "." without having
333 m_directory.SetCString(directory);
336 char *last_resolved_path_slash = strrchr(resolved_path, '/');
337 if (last_resolved_path_slash)
339 *last_resolved_path_slash = '\0';
340 m_directory.SetCString(resolved_path);
346 m_directory.SetCString(resolved_path);
350 //----------------------------------------------------------------------
351 // Convert to pointer operator. This allows code to check any FileSpec
352 // objects to see if they contain anything valid using code such as:
356 //----------------------------------------------------------------------
357 FileSpec::operator bool() const
359 return m_filename || m_directory;
362 //----------------------------------------------------------------------
363 // Logical NOT operator. This allows code to check any FileSpec
364 // objects to see if they are invalid using code such as:
368 //----------------------------------------------------------------------
370 FileSpec::operator!() const
372 return !m_directory && !m_filename;
375 //------------------------------------------------------------------
377 //------------------------------------------------------------------
379 FileSpec::operator== (const FileSpec& rhs) const
381 if (m_filename == rhs.m_filename)
383 if (m_directory == rhs.m_directory)
386 // TODO: determine if we want to keep this code in here.
387 // The code below was added to handle a case where we were
388 // trying to set a file and line breakpoint and one path
389 // was resolved, and the other not and the directory was
390 // in a mount point that resolved to a more complete path:
391 // "/tmp/a.c" == "/private/tmp/a.c". I might end up pulling
393 if (IsResolved() && rhs.IsResolved())
395 // Both paths are resolved, no need to look further...
399 FileSpec resolved_lhs(*this);
401 // If "this" isn't resolved, resolve it
404 if (resolved_lhs.ResolvePath())
406 // This path wasn't resolved but now it is. Check if the resolved
407 // directory is the same as our unresolved directory, and if so,
408 // we can mark this object as resolved to avoid more future resolves
409 m_is_resolved = (m_directory == resolved_lhs.m_directory);
415 FileSpec resolved_rhs(rhs);
416 if (!rhs.IsResolved())
418 if (resolved_rhs.ResolvePath())
420 // rhs's path wasn't resolved but now it is. Check if the resolved
421 // directory is the same as rhs's unresolved directory, and if so,
422 // we can mark this object as resolved to avoid more future resolves
423 rhs.m_is_resolved = (rhs.m_directory == resolved_rhs.m_directory);
429 // If we reach this point in the code we were able to resolve both paths
430 // and since we only resolve the paths if the basenames are equal, then
431 // we can just check if both directories are equal...
432 return resolved_lhs.GetDirectory() == resolved_rhs.GetDirectory();
437 //------------------------------------------------------------------
438 // Not equal to operator
439 //------------------------------------------------------------------
441 FileSpec::operator!= (const FileSpec& rhs) const
443 return !(*this == rhs);
446 //------------------------------------------------------------------
447 // Less than operator
448 //------------------------------------------------------------------
450 FileSpec::operator< (const FileSpec& rhs) const
452 return FileSpec::Compare(*this, rhs, true) < 0;
455 //------------------------------------------------------------------
456 // Dump a FileSpec object to a stream
457 //------------------------------------------------------------------
459 lldb_private::operator << (Stream &s, const FileSpec& f)
465 //------------------------------------------------------------------
466 // Clear this object by releasing both the directory and filename
467 // string values and making them both the empty string.
468 //------------------------------------------------------------------
476 //------------------------------------------------------------------
477 // Compare two FileSpec objects. If "full" is true, then both
478 // the directory and the filename must match. If "full" is false,
479 // then the directory names for "a" and "b" are only compared if
480 // they are both non-empty. This allows a FileSpec object to only
481 // contain a filename and it can match FileSpec objects that have
482 // matching filenames with different paths.
484 // Return -1 if the "a" is less than "b", 0 if "a" is equal to "b"
485 // and "1" if "a" is greater than "b".
486 //------------------------------------------------------------------
488 FileSpec::Compare(const FileSpec& a, const FileSpec& b, bool full)
492 // If full is true, then we must compare both the directory and filename.
494 // If full is false, then if either directory is empty, then we match on
495 // the basename only, and if both directories have valid values, we still
496 // do a full compare. This allows for matching when we just have a filename
497 // in one of the FileSpec objects.
499 if (full || (a.m_directory && b.m_directory))
501 result = ConstString::Compare(a.m_directory, b.m_directory);
505 return ConstString::Compare (a.m_filename, b.m_filename);
509 FileSpec::Equal (const FileSpec& a, const FileSpec& b, bool full)
511 if (!full && (a.GetDirectory().IsEmpty() || b.GetDirectory().IsEmpty()))
512 return a.m_filename == b.m_filename;
519 //------------------------------------------------------------------
520 // Dump the object to the supplied stream. If the object contains
521 // a valid directory name, it will be displayed followed by a
522 // directory delimiter, and the filename.
523 //------------------------------------------------------------------
525 FileSpec::Dump(Stream *s) const
527 static ConstString g_slash_only ("/");
531 if (m_directory && m_directory != g_slash_only)
537 //------------------------------------------------------------------
538 // Returns true if the file exists.
539 //------------------------------------------------------------------
541 FileSpec::Exists () const
543 struct stat file_stats;
544 return GetFileStats (this, &file_stats);
548 FileSpec::ResolveExecutableLocation ()
552 const char *file_cstr = m_filename.GetCString();
555 const std::string file_str (file_cstr);
556 llvm::sys::Path path = llvm::sys::Program::FindProgramByName (file_str);
557 const std::string &path_str = path.str();
558 llvm::StringRef dir_ref = llvm::sys::path::parent_path(path_str);
559 //llvm::StringRef dir_ref = path.getDirname();
560 if (! dir_ref.empty())
562 // FindProgramByName returns "." if it can't find the file.
563 if (strcmp (".", dir_ref.data()) == 0)
566 m_directory.SetCString (dir_ref.data());
571 // If FindProgramByName found the file, it returns the directory + filename in its return results.
572 // We need to separate them.
573 FileSpec tmp_file (dir_ref.data(), false);
574 if (tmp_file.Exists())
576 m_directory = tmp_file.m_directory;
588 FileSpec::ResolvePath ()
591 return true; // We have already resolved this path
593 char path_buf[PATH_MAX];
594 if (!GetPath (path_buf, PATH_MAX))
596 // SetFile(...) will set m_is_resolved correctly if it can resolve the path
597 SetFile (path_buf, true);
598 return m_is_resolved;
602 FileSpec::GetByteSize() const
604 struct stat file_stats;
605 if (GetFileStats (this, &file_stats))
606 return file_stats.st_size;
611 FileSpec::GetFileType () const
613 struct stat file_stats;
614 if (GetFileStats (this, &file_stats))
616 mode_t file_type = file_stats.st_mode & S_IFMT;
619 case S_IFDIR: return eFileTypeDirectory;
620 case S_IFIFO: return eFileTypePipe;
621 case S_IFREG: return eFileTypeRegular;
622 case S_IFSOCK: return eFileTypeSocket;
623 case S_IFLNK: return eFileTypeSymbolicLink;
627 return eFileTypeUnknown;
629 return eFileTypeInvalid;
633 FileSpec::GetModificationTime () const
636 struct stat file_stats;
637 if (GetFileStats (this, &file_stats))
638 mod_time.OffsetWithSeconds(file_stats.st_mtime);
642 //------------------------------------------------------------------
643 // Directory string get accessor.
644 //------------------------------------------------------------------
646 FileSpec::GetDirectory()
651 //------------------------------------------------------------------
652 // Directory string const get accessor.
653 //------------------------------------------------------------------
655 FileSpec::GetDirectory() const
660 //------------------------------------------------------------------
661 // Filename string get accessor.
662 //------------------------------------------------------------------
664 FileSpec::GetFilename()
669 //------------------------------------------------------------------
670 // Filename string const get accessor.
671 //------------------------------------------------------------------
673 FileSpec::GetFilename() const
678 //------------------------------------------------------------------
679 // Extract the directory and path into a fixed buffer. This is
680 // needed as the directory and path are stored in separate string
682 //------------------------------------------------------------------
684 FileSpec::GetPath(char *path, size_t path_max_len) const
688 const char *dirname = m_directory.GetCString();
689 const char *filename = m_filename.GetCString();
693 return ::snprintf (path, path_max_len, "%s/%s", dirname, filename);
695 return ::snprintf (path, path_max_len, "%s", dirname);
699 return ::snprintf (path, path_max_len, "%s", filename);
708 FileSpec::GetPath (void) const
710 static ConstString g_slash_only ("/");
712 const char *dirname = m_directory.GetCString();
713 const char *filename = m_filename.GetCString();
716 path.append (dirname);
717 if (filename && m_directory != g_slash_only)
721 path.append (filename);
726 FileSpec::GetFileNameExtension () const
730 const char *filename = m_filename.GetCString();
731 const char* dot_pos = strrchr(filename, '.');
732 if (dot_pos && dot_pos[1] != '\0')
733 return ConstString(dot_pos+1);
735 return ConstString();
739 FileSpec::GetFileNameStrippingExtension () const
741 const char *filename = m_filename.GetCString();
742 if (filename == NULL)
743 return ConstString();
745 const char* dot_pos = strrchr(filename, '.');
749 return ConstString(filename, dot_pos-filename);
752 //------------------------------------------------------------------
753 // Returns a shared pointer to a data buffer that contains all or
754 // part of the contents of a file. The data is memory mapped and
755 // will lazily page in data from the file as memory is accessed.
756 // The data that is mappped will start "file_offset" bytes into the
757 // file, and "file_size" bytes will be mapped. If "file_size" is
758 // greater than the number of bytes available in the file starting
759 // at "file_offset", the number of bytes will be appropriately
760 // truncated. The final number of bytes that get mapped can be
761 // verified using the DataBuffer::GetByteSize() function.
762 //------------------------------------------------------------------
764 FileSpec::MemoryMapFileContents(off_t file_offset, size_t file_size) const
766 DataBufferSP data_sp;
767 std::unique_ptr<DataBufferMemoryMap> mmap_data(new DataBufferMemoryMap());
770 const size_t mapped_length = mmap_data->MemoryMapFromFileSpec (this, file_offset, file_size);
771 if (((file_size == SIZE_MAX) && (mapped_length > 0)) || (mapped_length >= file_size))
772 data_sp.reset(mmap_data.release());
778 //------------------------------------------------------------------
779 // Return the size in bytes that this object takes in memory. This
780 // returns the size in bytes of this object, not any shared string
781 // values it may refer to.
782 //------------------------------------------------------------------
784 FileSpec::MemorySize() const
786 return m_filename.MemorySize() + m_directory.MemorySize();
791 FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len, Error *error_ptr) const
794 size_t bytes_read = 0;
795 char resolved_path[PATH_MAX];
796 if (GetPath(resolved_path, sizeof(resolved_path)))
799 error = file.Open(resolved_path, File::eOpenOptionRead);
802 off_t file_offset_after_seek = file_offset;
803 bytes_read = dst_len;
804 error = file.Read(dst, bytes_read, file_offset_after_seek);
809 error.SetErrorString("invalid file specification");
816 //------------------------------------------------------------------
817 // Returns a shared pointer to a data buffer that contains all or
818 // part of the contents of a file. The data copies into a heap based
819 // buffer that lives in the DataBuffer shared pointer object returned.
820 // The data that is cached will start "file_offset" bytes into the
821 // file, and "file_size" bytes will be mapped. If "file_size" is
822 // greater than the number of bytes available in the file starting
823 // at "file_offset", the number of bytes will be appropriately
824 // truncated. The final number of bytes that get mapped can be
825 // verified using the DataBuffer::GetByteSize() function.
826 //------------------------------------------------------------------
828 FileSpec::ReadFileContents (off_t file_offset, size_t file_size, Error *error_ptr) const
831 DataBufferSP data_sp;
832 char resolved_path[PATH_MAX];
833 if (GetPath(resolved_path, sizeof(resolved_path)))
836 error = file.Open(resolved_path, File::eOpenOptionRead);
839 const bool null_terminate = false;
840 error = file.Read (file_size, file_offset, null_terminate, data_sp);
845 error.SetErrorString("invalid file specification");
853 FileSpec::ReadFileContentsAsCString(Error *error_ptr)
856 DataBufferSP data_sp;
857 char resolved_path[PATH_MAX];
858 if (GetPath(resolved_path, sizeof(resolved_path)))
861 error = file.Open(resolved_path, File::eOpenOptionRead);
865 size_t length = SIZE_MAX;
866 const bool null_terminate = true;
867 error = file.Read (length, offset, null_terminate, data_sp);
872 error.SetErrorString("invalid file specification");
880 FileSpec::ReadFileLines (STLStringArray &lines)
884 if (GetPath(path, sizeof(path)))
886 std::ifstream file_stream (path);
891 while (getline (file_stream, line))
892 lines.push_back (line);
898 FileSpec::EnumerateDirectoryResult
899 FileSpec::EnumerateDirectory
901 const char *dir_path,
902 bool find_directories,
905 EnumerateDirectoryCallbackType callback,
909 if (dir_path && dir_path[0])
911 lldb_utility::CleanUp <DIR *, int> dir_path_dir (opendir(dir_path), NULL, closedir);
912 if (dir_path_dir.is_valid())
914 long path_max = fpathconf (dirfd (dir_path_dir.get()), _PC_NAME_MAX);
915 #if defined (__APPLE_) && defined (__DARWIN_MAXPATHLEN)
916 if (path_max < __DARWIN_MAXPATHLEN)
917 path_max = __DARWIN_MAXPATHLEN;
919 struct dirent *buf, *dp;
920 buf = (struct dirent *) malloc (offsetof (struct dirent, d_name) + path_max + 1);
922 while (buf && readdir_r(dir_path_dir.get(), buf, &dp) == 0 && dp)
924 // Only search directories
925 if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN)
927 size_t len = strlen(dp->d_name);
929 if (len == 1 && dp->d_name[0] == '.')
932 if (len == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')
936 bool call_callback = false;
937 FileSpec::FileType file_type = eFileTypeUnknown;
942 case DT_UNKNOWN: file_type = eFileTypeUnknown; call_callback = true; break;
943 case DT_FIFO: file_type = eFileTypePipe; call_callback = find_other; break;
944 case DT_CHR: file_type = eFileTypeOther; call_callback = find_other; break;
945 case DT_DIR: file_type = eFileTypeDirectory; call_callback = find_directories; break;
946 case DT_BLK: file_type = eFileTypeOther; call_callback = find_other; break;
947 case DT_REG: file_type = eFileTypeRegular; call_callback = find_files; break;
948 case DT_LNK: file_type = eFileTypeSymbolicLink; call_callback = find_other; break;
949 case DT_SOCK: file_type = eFileTypeSocket; call_callback = find_other; break;
950 #if !defined(__OpenBSD__)
951 case DT_WHT: file_type = eFileTypeOther; call_callback = find_other; break;
957 char child_path[PATH_MAX];
958 const int child_path_len = ::snprintf (child_path, sizeof(child_path), "%s/%s", dir_path, dp->d_name);
959 if (child_path_len < (int)(sizeof(child_path) - 1))
961 // Don't resolve the file type or path
962 FileSpec child_path_spec (child_path, false);
964 EnumerateDirectoryResult result = callback (callback_baton, file_type, child_path_spec);
968 case eEnumerateDirectoryResultNext:
969 // Enumerate next entry in the current directory. We just
970 // exit this switch and will continue enumerating the
971 // current directory as we currently are...
974 case eEnumerateDirectoryResultEnter: // Recurse into the current entry if it is a directory or symlink, or next if not
975 if (FileSpec::EnumerateDirectory (child_path,
980 callback_baton) == eEnumerateDirectoryResultQuit)
982 // The subdirectory returned Quit, which means to
983 // stop all directory enumerations at all levels.
986 return eEnumerateDirectoryResultQuit;
990 case eEnumerateDirectoryResultExit: // Exit from the current directory at the current level.
991 // Exit from this directory level and tell parent to
995 return eEnumerateDirectoryResultNext;
997 case eEnumerateDirectoryResultQuit: // Stop directory enumerations at any level
1000 return eEnumerateDirectoryResultQuit;
1011 // By default when exiting a directory, we tell the parent enumeration
1012 // to continue enumerating.
1013 return eEnumerateDirectoryResultNext;
1016 //------------------------------------------------------------------
1017 /// Returns true if the filespec represents an implementation source
1018 /// file (files with a ".c", ".cpp", ".m", ".mm" (many more)
1022 /// \b true if the filespec represents an implementation source
1023 /// file, \b false otherwise.
1024 //------------------------------------------------------------------
1026 FileSpec::IsSourceImplementationFile () const
1028 ConstString extension (GetFileNameExtension());
1031 static RegularExpression g_source_file_regex ("^(c|m|mm|cpp|c\\+\\+|cxx|cc|cp|s|asm|f|f77|f90|f95|f03|for|ftn|fpp|ada|adb|ads)$",
1032 REG_EXTENDED | REG_ICASE);
1033 return g_source_file_regex.Execute (extension.GetCString());
1039 FileSpec::IsRelativeToCurrentWorkingDirectory () const
1041 const char *directory = m_directory.GetCString();
1042 if (directory && directory[0])
1044 // If the path doesn't start with '/' or '~', return true
1045 switch (directory[0])
1054 else if (m_filename)
1056 // No directory, just a basename, return true