diff options
| author | John Criswell <criswell@uiuc.edu> | 2003-09-02 21:09:30 +0000 |
|---|---|---|
| committer | John Criswell <criswell@uiuc.edu> | 2003-09-02 21:09:30 +0000 |
| commit | b83a22bd828d15908baa8350fd2dc330c8b2f24f (patch) | |
| tree | 794e21de1fe701cf38e0b62af173312d173e760e /llvm/lib/Support | |
| parent | 44375ca7d67a9536b28ae10f4533894cec72488d (diff) | |
| download | bcm5719-llvm-b83a22bd828d15908baa8350fd2dc330c8b2f24f.tar.gz bcm5719-llvm-b83a22bd828d15908baa8350fd2dc330c8b2f24f.zip | |
Added the MakeFileReadable() method.
llvm-svn: 8327
Diffstat (limited to 'llvm/lib/Support')
| -rw-r--r-- | llvm/lib/Support/FileUtilities.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/llvm/lib/Support/FileUtilities.cpp b/llvm/lib/Support/FileUtilities.cpp index 16c41bc7b9e..7c8142a4a66 100644 --- a/llvm/lib/Support/FileUtilities.cpp +++ b/llvm/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; +} + |

