From 7527fbccc28a051142a53dd21ca7fe8e7fae2613 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Mon, 26 Jan 2004 14:55:57 -0500 Subject: [PATCH] ENH: Add code for setting and getting permissions --- Source/cmSystemTools.cxx | 36 ++++++++++++++++++++++++++++++++++++ Source/cmSystemTools.h | 6 +++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 28b378b7cf..7478d71c93 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -42,6 +42,8 @@ #include #endif +#include + bool cmSystemTools::s_RunCommandHideConsole = false; bool cmSystemTools::s_DisableRunCommandOutput = false; @@ -1205,3 +1207,37 @@ bool cmSystemTools::PutEnv(const char* value) localEnvironment.push_back(envVar); return ret == 0; } + +bool cmSystemTools::GetPermissions(const char* file, mode_t& mode) +{ + if ( !file ) + { + return false; + } + + struct stat st; + if ( stat(file, &st) < 0 ) + { + return false; + } + mode = st.st_mode; + return true; +} + +bool cmSystemTools::SetPermissions(const char* file, mode_t mode) +{ + if ( !file ) + { + return false; + } + if ( !cmSystemTools::FileExists(file) ) + { + return false; + } + if ( chmod(file, mode) < 0 ) + { + return false; + } + + return true; +} diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index a8bbc8be76..9099844505 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -259,7 +259,11 @@ public: /** put a string into the environment of the form var=value */ static bool PutEnv(const char* value); - + + ///! Get permissions of the file + static bool GetPermissions(const char* file, mode_t& mode); + static bool SetPermissions(const char* file, mode_t mode); + private: static bool s_ForceUnixPaths; static bool s_RunCommandHideConsole;