From 05cc02cec03507c47846a668c92e6dcc4ba2e71e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 18 Jan 2011 01:00:15 -0800 Subject: cleanup mkdir usage with boost filesystem: Replaced copy/pasted code and MKDIR_TAKES_ONE_ARG #ifdefs with portable boost filesystem path and directory creation. Gets the correct home directory on windows systems: APPDATA. Replaces large amounts of copypasta with single lines of code. Removes MKDIR_TAKES_ONE_ARG configuration checks from m4 files. Adds boost filesystem and system library as build dependencies. --- gnuradio-core/src/lib/runtime/gr_preferences.cc | 39 ++++++++++++------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'gnuradio-core/src/lib/runtime/gr_preferences.cc') diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index 5f7412248..21934677b 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -33,12 +33,17 @@ #include #include - -#ifdef MKDIR_TAKES_ONE_ARG -#define gr_mkdir(pathname, mode) mkdir(pathname) -#else -#define gr_mkdir(pathname, mode) mkdir((pathname), (mode)) -#endif +#include +#include +namespace fs = boost::filesystem; + +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 * -- cgit From d65ae4249bf709d0e4062ef2825bef28ff77492a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 22 Jan 2011 22:47:08 -0800 Subject: created gr_sys_paths.h to house functions for getting system paths gr_sys_paths.h has gr_tmp_path() and gr_appdata_path() this replaces gr_tmp_path.h --- gnuradio-core/src/lib/runtime/gr_preferences.cc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'gnuradio-core/src/lib/runtime/gr_preferences.cc') diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index 21934677b..c2ca047a8 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 * @@ -25,6 +25,7 @@ #endif #include +#include #include #include #include @@ -37,14 +38,6 @@ #include namespace fs = boost::filesystem; -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: * the key is the filename; the value is the file contents. @@ -54,14 +47,14 @@ static const char * pathname (const char *key) { static fs::path path; - path = fs::path(get_home_dir()) / ".gnuradio" / "prefs" / key; + path = fs::path(gr_appdata_path()) / ".gnuradio" / "prefs" / key; return path.string().c_str(); } static void ensure_dir_path () { - fs::path path = fs::path(get_home_dir()) / ".gnuradio"; + fs::path path = fs::path(gr_appdata_path()) / ".gnuradio"; if (!fs::is_directory(path)) fs::create_directory(path); path = path / "prefs"; -- cgit