Provide Path::isSpecialFile interface for PR5568.
authorEdward O'Callaghan <eocallaghan@auroraux.org>
Tue, 24 Nov 2009 15:19:10 +0000 (15:19 +0000)
committerEdward O'Callaghan <eocallaghan@auroraux.org>
Tue, 24 Nov 2009 15:19:10 +0000 (15:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89765 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/System/Path.h
lib/System/Unix/Path.inc
lib/System/Win32/Path.inc

index 3b73a128fbd1cee8ef8e5695a40423f73c0e48e7..19684d34267954b362e46b6f5ecf8921e7fb43cc 100644 (file)
@@ -380,6 +380,11 @@ namespace sys {
       /// in the file system.
       bool canWrite() const;
 
+      /// This function checks that what we're trying to work only on a regular file or Dir.
+      /// Check for things like /dev/null, any block special file,
+      /// or other things that aren't "regular" files.
+      bool isSpecialFile() const;
+
       /// This function determines if the path name references an executable
       /// file in the file system. This function checks for the existence and
       /// executability (by the current program) of the file.
index 89285b48132f98cf93432aada0138048c8dfb651..d134aaa79b3f3deb404c0bb321dcc1cab63b1dfa 100644 (file)
@@ -335,7 +335,7 @@ getprogpath(char ret[PATH_MAX], const char *bin)
   free(pv);
   return (NULL);
 }
-#endif
+#endif // __FreeBSD__
 
 /// GetMainExecutable - Return the path to the main executable, given the
 /// value of argv[0] from program startup.
@@ -453,6 +453,24 @@ Path::canWrite() const {
   return 0 == access(path.c_str(), W_OK);
 }
 
+bool
+Path::isSpecialFile() const {
+  // Get the status so we can determine if its a file or directory
+  struct stat buf;
+  std::string *ErrStr;
+
+  if (0 != stat(path.c_str(), &buf)) {
+    MakeErrMsg(ErrStr, path + ": can't get status of file");
+    return true;
+  }
+
+  if (S_ISDIR(buf.st_mode) || S_ISREG(buf.st_mode)) {
+    return false;
+  }
+
+  return true;
+}
+
 bool
 Path::canExecute() const {
   if (0 != access(path.c_str(), R_OK | X_OK ))
@@ -723,7 +741,7 @@ Path::createTemporaryFileOnDisk(bool reuse_current, std::string* ErrMsg) {
 
 bool
 Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
-  // Get the status so we can determin if its a file or directory
+  // Get the status so we can determine if its a file or directory
   struct stat buf;
   if (0 != stat(path.c_str(), &buf)) {
     MakeErrMsg(ErrStr, path + ": can't get status of file");
index 573369e97d492b2f2c797a1a954d7e6a820e8197..9adeca241034f7060abe97153f2c7d8b2c0580df 100644 (file)
@@ -357,6 +357,11 @@ Path::canExecute() const {
   return attr != INVALID_FILE_ATTRIBUTES;
 }
 
+bool
+Path::isSpecialFile() const {
+  return false;
+}
+
 std::string
 Path::getLast() const {
   // Find the last slash