summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Criswell <criswell@uiuc.edu>2003-09-02 21:09:30 +0000
committerJohn Criswell <criswell@uiuc.edu>2003-09-02 21:09:30 +0000
commit66622be46acfdebdfb82f1f6b988912ec8b61754 (patch)
treed7f96d414c70c1c75fdea3792220375a679ef6b6
parent9adeccc552d6f28bdc503a8c1ffe13ea6ea6d73d (diff)
downloadllvm-66622be46acfdebdfb82f1f6b988912ec8b61754.tar.gz
llvm-66622be46acfdebdfb82f1f6b988912ec8b61754.tar.bz2
llvm-66622be46acfdebdfb82f1f6b988912ec8b61754.tar.xz
Added the MakeFileReadable() method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8327 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/Support/FileUtilities.h17
-rw-r--r--include/llvm/Support/FileUtilities.h17
-rw-r--r--lib/Support/FileUtilities.cpp54
-rw-r--r--support/lib/Support/FileUtilities.cpp54
4 files changed, 142 insertions, 0 deletions
diff --git a/include/Support/FileUtilities.h b/include/Support/FileUtilities.h
index 47704946c8..3bba3fec73 100644
--- a/include/Support/FileUtilities.h
+++ b/include/Support/FileUtilities.h
@@ -51,4 +51,21 @@ std::string getUniqueFilename(const std::string &FilenameBase);
/// In case of failure, the file's access attributes are unspecified.
///
bool MakeFileExecutable (const std::string & Filename);
+
+///
+/// Method: MakeFileReadable()
+///
+/// Description:
+/// This method turns on whatever access attributes are needed to make the
+/// specified file readable.
+///
+/// Return value:
+/// True - The operation succeeded.
+/// False - The operation failed.
+///
+/// Notes:
+/// In case of failure, the file's access attributes are unspecified.
+///
+bool MakeFileReadable (const std::string & Filename);
+
#endif
diff --git a/include/llvm/Support/FileUtilities.h b/include/llvm/Support/FileUtilities.h
index 47704946c8..3bba3fec73 100644
--- a/include/llvm/Support/FileUtilities.h
+++ b/include/llvm/Support/FileUtilities.h
@@ -51,4 +51,21 @@ std::string getUniqueFilename(const std::string &FilenameBase);
/// In case of failure, the file's access attributes are unspecified.
///
bool MakeFileExecutable (const std::string & Filename);
+
+///
+/// Method: MakeFileReadable()
+///
+/// Description:
+/// This method turns on whatever access attributes are needed to make the
+/// specified file readable.
+///
+/// Return value:
+/// True - The operation succeeded.
+/// False - The operation failed.
+///
+/// Notes:
+/// In case of failure, the file's access attributes are unspecified.
+///
+bool MakeFileReadable (const std::string & Filename);
+
#endif
diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp
index 16c41bc7b9..7c8142a4a6 100644
--- a/lib/Support/FileUtilities.cpp
+++ b/lib/Support/FileUtilities.cpp
@@ -147,3 +147,57 @@ MakeFileExecutable (const std::string & Filename)
return true;
}
+///
+/// Method: MakeFileReadable ()
+///
+/// Description:
+/// This method makes the specified filename readable by giving it
+/// read permission. It respects the umask value of the process, and it
+/// does not enable any unnecessary access bits.
+///
+/// Algorithm:
+/// o Get file's current permissions.
+/// o Get the process's current umask.
+/// o Take the set of all read bits and disable those found in the umask.
+/// o Add the remaining permissions to the file's permissions.
+///
+bool
+MakeFileReadable (const std::string & Filename)
+{
+ // Permissions masking value of the user
+ mode_t mask;
+
+ // Permissions currently enabled on the file
+ struct stat fstat;
+
+ //
+ // Grab the umask value from the operating system. We want to use it when
+ // changing the file's permissions.
+ //
+ // Note:
+ // Umask() is one of those annoying system calls. You have to call it
+ // to get the current value and then set it back.
+ //
+ mask = umask (0x777);
+ umask (mask);
+
+ //
+ // Go fetch the file's current permission bits. We want to *add* execute
+ // access to the file.
+ //
+ if ((stat (Filename.c_str(), &fstat)) == -1)
+ {
+ return false;
+ }
+
+ //
+ // Make the file executable...
+ //
+ if ((chmod(Filename.c_str(), (fstat.st_mode | (0444 & ~mask)))) == -1)
+ {
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/support/lib/Support/FileUtilities.cpp b/support/lib/Support/FileUtilities.cpp
index 16c41bc7b9..7c8142a4a6 100644
--- a/support/lib/Support/FileUtilities.cpp
+++ b/support/lib/Support/FileUtilities.cpp
@@ -147,3 +147,57 @@ MakeFileExecutable (const std::string & Filename)
return true;
}
+///
+/// Method: MakeFileReadable ()
+///
+/// Description:
+/// This method makes the specified filename readable by giving it
+/// read permission. It respects the umask value of the process, and it
+/// does not enable any unnecessary access bits.
+///
+/// Algorithm:
+/// o Get file's current permissions.
+/// o Get the process's current umask.
+/// o Take the set of all read bits and disable those found in the umask.
+/// o Add the remaining permissions to the file's permissions.
+///
+bool
+MakeFileReadable (const std::string & Filename)
+{
+ // Permissions masking value of the user
+ mode_t mask;
+
+ // Permissions currently enabled on the file
+ struct stat fstat;
+
+ //
+ // Grab the umask value from the operating system. We want to use it when
+ // changing the file's permissions.
+ //
+ // Note:
+ // Umask() is one of those annoying system calls. You have to call it
+ // to get the current value and then set it back.
+ //
+ mask = umask (0x777);
+ umask (mask);
+
+ //
+ // Go fetch the file's current permission bits. We want to *add* execute
+ // access to the file.
+ //
+ if ((stat (Filename.c_str(), &fstat)) == -1)
+ {
+ return false;
+ }
+
+ //
+ // Make the file executable...
+ //
+ if ((chmod(Filename.c_str(), (fstat.st_mode | (0444 & ~mask)))) == -1)
+ {
+ return false;
+ }
+
+ return true;
+}
+