diff options
author | Tom Rondeau | 2011-01-22 14:54:34 -0500 |
---|---|---|
committer | Tom Rondeau | 2011-01-22 14:54:34 -0500 |
commit | 9880d22f38e0f96116f0d7409ccbbd148c9db53d (patch) | |
tree | deb9d99fb256e5a39d3edf0db2591aa1fb007a7d /gnuradio-core/src/lib/runtime | |
parent | 5ad1695febf1f0ef2055693b3af385470c0f66a5 (diff) | |
parent | ebb0f56da62e9ff16928b32cc525f24c93a99e0b (diff) | |
download | gnuradio-9880d22f38e0f96116f0d7409ccbbd148c9db53d.tar.gz gnuradio-9880d22f38e0f96116f0d7409ccbbd148c9db53d.tar.bz2 gnuradio-9880d22f38e0f96116f0d7409ccbbd148c9db53d.zip |
Merge branch 'mergeme/misc/mkdir_simplification' into next
Diffstat (limited to 'gnuradio-core/src/lib/runtime')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_preferences.cc | 39 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_unittests.h | 40 |
2 files changed, 25 insertions, 54 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index 5f7412248..e9216e4ac 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2003,2010 Free Software Foundation, Inc. + * Copyright 2003,2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -33,12 +33,17 @@ #include <unistd.h> #include <string.h> +#include <boost/filesystem/operations.hpp> +#include <boost/filesystem/path.hpp> +namespace fs = boost::filesystem; -#ifdef MKDIR_TAKES_ONE_ARG -#define gr_mkdir(pathname, mode) mkdir(pathname) -#else -#define gr_mkdir(pathname, mode) mkdir((pathname), (mode)) -#endif +static std::string get_home_dir(void){ + #if defined(BOOST_WINDOWS) + return getenv ("APPDATA"); + #else + return getenv ("HOME"); + #endif +} /* * The simplest thing that could possibly work: @@ -48,27 +53,19 @@ static const char * pathname (const char *key) { - static char buf[200]; - snprintf (buf, sizeof (buf), "%s/.gnuradio/prefs/%s", getenv ("HOME"), key); - return buf; + static fs::path path; + path = fs::path(get_home_dir()) / ".gnuradio" / "prefs" / key; + return path.string().c_str(); } static void ensure_dir_path () { - char path[200]; - struct stat statbuf; - - snprintf (path, sizeof (path), "%s/.gnuradio/prefs", getenv ("HOME")); - if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) - return; - - // blindly try to make it // FIXME make this robust. C++ SUCKS! + fs::path path = fs::path(get_home_dir()) / ".gnuradio"; + if (!fs::is_directory(path)) fs::create_directory(path); - snprintf (path, sizeof (path), "%s/.gnuradio", getenv ("HOME")); - gr_mkdir (path, 0750); - snprintf (path, sizeof (path), "%s/.gnuradio/prefs", getenv ("HOME")); - gr_mkdir (path, 0750); + path = path / "prefs"; + if (!fs::is_directory(path)) fs::create_directory(path); } const char * diff --git a/gnuradio-core/src/lib/runtime/gr_unittests.h b/gnuradio-core/src/lib/runtime/gr_unittests.h index 70aa6f294..59149bb2e 100644 --- a/gnuradio-core/src/lib/runtime/gr_unittests.h +++ b/gnuradio-core/src/lib/runtime/gr_unittests.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -31,37 +31,11 @@ #include <sys/stat.h> #include <unistd.h> +#include <boost/filesystem/operations.hpp> +#include <boost/filesystem/path.hpp> -#ifdef MKDIR_TAKES_ONE_ARG -#define gr_mkdir(pathname, mode) mkdir(pathname) -#else -#define gr_mkdir(pathname, mode) mkdir((pathname), (mode)) -#endif - -/* - * Mostly taken from gr_preferences.cc/h - * The simplest thing that could possibly work: - * the key is the filename; the value is the file contents. - */ - -static void -ensure_unittest_path (const char *path) -{ - struct stat statbuf; - if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) - return; - - // blindly try to make it // FIXME make this robust. C++ SUCKS! - gr_mkdir (path, 0750); +static std::string get_unittest_path(const std::string &filename){ + boost::filesystem::path path = boost::filesystem::current_path() / ".unittests"; + if (!boost::filesystem::is_directory(path)) boost::filesystem::create_directory(path); + return (path / filename).string(); } - -static void -get_unittest_path (const char *filename, char *fullpath, size_t pathsize) -{ - char path[200]; - snprintf (path, sizeof(path), "./.unittests"); - snprintf (fullpath, pathsize, "%s/%s", path, filename); - - ensure_unittest_path(path); -} - |