aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-03-07 05:57:21 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-03-07 05:57:21 +0000
commit53abc9cffc00a96b80f983735cdaec433a91ae63 (patch)
tree901bfa85a5adbf1ac987619f1a6e383da0dedbb0
parent47c420215e8ebd8575b5a2675ebf82536f775926 (diff)
downloadpaludis-53abc9cffc00a96b80f983735cdaec433a91ae63.tar.gz
paludis-53abc9cffc00a96b80f983735cdaec433a91ae63.tar.xz
Move getenv -> system. Add kernel_version() function.
-rw-r--r--paludis/args/args_handler.cc2
-rw-r--r--paludis/default_config.cc2
-rw-r--r--paludis/portage_repository.cc2
-rw-r--r--paludis/qa/metadata_check.cc2
-rw-r--r--paludis/util/files.m42
-rw-r--r--paludis/util/system.cc (renamed from paludis/util/getenv.cc)22
-rw-r--r--paludis/util/system.hh (renamed from paludis/util/getenv.hh)6
-rw-r--r--paludis/util/system_TEST.cc (renamed from paludis/util/getenv_TEST.cc)23
-rw-r--r--src/colour.cc2
9 files changed, 53 insertions, 10 deletions
diff --git a/paludis/args/args_handler.cc b/paludis/args/args_handler.cc
index 59009e3..4e9cf77 100644
--- a/paludis/args/args_handler.cc
+++ b/paludis/args/args_handler.cc
@@ -19,7 +19,7 @@
#include "args.hh"
#include "args_dumper.hh"
-#include <paludis/util/getenv.hh>
+#include <paludis/util/system.hh>
#include <algorithm>
/** \file
diff --git a/paludis/default_config.cc b/paludis/default_config.cc
index 82b54d6..c25612e 100644
--- a/paludis/default_config.cc
+++ b/paludis/default_config.cc
@@ -24,7 +24,7 @@
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/filter_insert_iterator.hh>
#include <paludis/util/fs_entry.hh>
-#include <paludis/util/getenv.hh>
+#include <paludis/util/system.hh>
#include <paludis/util/is_file_with_extension.hh>
#include <paludis/util/iterator_utilities.hh>
#include <paludis/util/stringify.hh>
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index 6faf2b5..cfb9405 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -29,7 +29,7 @@
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/filter_insert_iterator.hh>
#include <paludis/util/fs_entry.hh>
-#include <paludis/util/getenv.hh>
+#include <paludis/util/system.hh>
#include <paludis/util/indirect_iterator.hh>
#include <paludis/util/is_file_with_extension.hh>
#include <paludis/util/log.hh>
diff --git a/paludis/qa/metadata_check.cc b/paludis/qa/metadata_check.cc
index 9a8d6ac..5920760 100644
--- a/paludis/qa/metadata_check.cc
+++ b/paludis/qa/metadata_check.cc
@@ -19,7 +19,7 @@
#include <paludis/qa/metadata_check.hh>
#include <paludis/util/pstream.hh>
-#include <paludis/util/getenv.hh>
+#include <paludis/util/system.hh>
#include <ctime>
#include <fstream>
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index ef390c6..1d033c6 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -21,7 +21,6 @@ add(`dir_iterator', `hh', `cc', `test', `testscript')
add(`exception', `hh', `cc')
add(`filter_insert_iterator', `hh', `cc', `test')
add(`fs_entry', `hh', `cc', `test', `testscript')
-add(`getenv', `hh', `cc', `test')
add(`indirect_iterator', `hh', `cc', `test')
add(`instantiation_policy', `hh', `cc', `test')
add(`is_const', `hh', `cc', `test')
@@ -37,6 +36,7 @@ add(`smart_record', `hh', `cc', `test')
add(`sorted_collection', `hh', `cc')
add(`stringify', `hh', `cc', `test')
add(`strip', `hh', `cc', `test')
+add(`system', `hh', `cc', `test')
add(`tokeniser', `hh', `cc', `test')
add(`transform_insert_iterator', `hh', `cc', `test')
add(`util', `hh')
diff --git a/paludis/util/getenv.cc b/paludis/util/system.cc
index c2c3731..6ccea6c 100644
--- a/paludis/util/getenv.cc
+++ b/paludis/util/system.cc
@@ -17,7 +17,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <paludis/util/getenv.hh>
+#include <paludis/util/system.hh>
+#include <sys/utsname.h>
#include <cstdlib>
using namespace paludis;
@@ -42,3 +43,22 @@ paludis::getenv_or_error(const std::string & key)
throw GetenvError(key);
return e;
}
+
+namespace
+{
+ std::string get_kernel_version()
+ {
+ struct utsname u;
+ if (0 != uname(&u))
+ throw InternalError(PALUDIS_HERE, "uname call failed");
+ return u.release;
+ }
+}
+
+std::string
+paludis::kernel_version()
+{
+ static const std::string result(get_kernel_version());
+ return result;
+}
+
diff --git a/paludis/util/getenv.hh b/paludis/util/system.hh
index a88c337..801a953 100644
--- a/paludis/util/getenv.hh
+++ b/paludis/util/system.hh
@@ -17,8 +17,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef PALUDIS_GUARD_PALUDIS_GETENV_HH
-#define PALUDIS_GUARD_PALUDIS_GETENV_HH 1
+#ifndef PALUDIS_GUARD_PALUDIS_UTIL_SYSTEM_HH
+#define PALUDIS_GUARD_PALUDIS_UTIL_SYSTEM_HH 1
#include <paludis/util/exception.hh>
#include <string>
@@ -50,6 +50,8 @@ namespace paludis
* the variable is not defined.
*/
std::string getenv_or_error(const std::string & key);
+
+ std::string kernel_version();
}
#endif
diff --git a/paludis/util/getenv_TEST.cc b/paludis/util/system_TEST.cc
index 74162c5..4ba4e09 100644
--- a/paludis/util/getenv_TEST.cc
+++ b/paludis/util/system_TEST.cc
@@ -17,7 +17,7 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <paludis/util/getenv.hh>
+#include <paludis/util/system.hh>
#include <test/test_framework.hh>
#include <test/test_runner.hh>
@@ -59,4 +59,25 @@ namespace test_cases
TEST_CHECK_THROWS(getenv_or_error("THEREISNOSUCHVARIABLE"), GetenvError);
}
} test_getenv_or_error;
+
+ /**
+ * \test Test kernel_version.
+ *
+ * \ingroup Test
+ */
+ struct KernelVersionTest : TestCase
+ {
+ KernelVersionTest() : TestCase("kernel version") { }
+
+ void run()
+ {
+ TEST_CHECK(! kernel_version().empty());
+#ifdef linux
+ TEST_CHECK('2' == kernel_version().at(0));
+ TEST_CHECK('.' == kernel_version().at(1));
+#else
+# error You need to write a sanity test for kernel_version() for your platform.
+#endif
+ }
+ } test_kernel_version;
}
diff --git a/src/colour.cc b/src/colour.cc
index 13d8304..ca2a93a 100644
--- a/src/colour.cc
+++ b/src/colour.cc
@@ -19,7 +19,7 @@
#include "colour.hh"
#include <unistd.h>
-#include <paludis/util/getenv.hh>
+#include <paludis/util/system.hh>
bool use_colour()
{