From d65ae4249bf709d0e4062ef2825bef28ff77492a Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
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/general/gri_fft.cc           | 13 ++---
 gnuradio-core/src/lib/runtime/Makefile.am          |  6 +--
 gnuradio-core/src/lib/runtime/gr_preferences.cc    | 15 ++----
 gnuradio-core/src/lib/runtime/gr_sys_paths.cc      | 55 ++++++++++++++++++++++
 gnuradio-core/src/lib/runtime/gr_sys_paths.h       | 31 ++++++++++++
 gnuradio-core/src/lib/runtime/gr_tmp_path.cc       | 52 --------------------
 gnuradio-core/src/lib/runtime/gr_tmp_path.h        | 31 ------------
 .../lib/runtime/gr_vmcircbuf_createfilemapping.cc  |  3 +-
 .../src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc  |  4 +-
 .../src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc   |  4 +-
 10 files changed, 101 insertions(+), 113 deletions(-)
 create mode 100644 gnuradio-core/src/lib/runtime/gr_sys_paths.cc
 create mode 100644 gnuradio-core/src/lib/runtime/gr_sys_paths.h
 delete mode 100644 gnuradio-core/src/lib/runtime/gr_tmp_path.cc
 delete mode 100644 gnuradio-core/src/lib/runtime/gr_tmp_path.h

(limited to 'gnuradio-core')

diff --git a/gnuradio-core/src/lib/general/gri_fft.cc b/gnuradio-core/src/lib/general/gri_fft.cc
index 37be06f09b..f20b15ca0a 100644
--- a/gnuradio-core/src/lib/general/gri_fft.cc
+++ b/gnuradio-core/src/lib/general/gri_fft.cc
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2003,2008 Free Software Foundation, Inc.
+ * Copyright 2003,2008,2011 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -21,6 +21,7 @@
  */
 
 #include <gri_fft.h>
+#include <gr_sys_paths.h>
 #include <fftw3.h>
 #include <gr_complex.h>
 #include <stdlib.h>
@@ -33,14 +34,6 @@
 #include <boost/filesystem/path.hpp>
 namespace fs = boost::filesystem;
 
-static std::string get_home_dir(void){
-    #if defined(BOOST_WINDOWS)
-        return getenv ("APPDATA");
-    #else
-        return getenv ("HOME");
-    #endif
-}
-
 boost::mutex &
 gri_fft_planner::mutex()
 {
@@ -53,7 +46,7 @@ static const char *
 wisdom_filename ()
 {
   static fs::path path;
-  path = fs::path(get_home_dir()) / ".gr_fftw_wisdom";
+  path = fs::path(gr_appdata_path()) / ".gr_fftw_wisdom";
   return path.string().c_str();
 }
 
diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am
index 3dd2b42f50..eca92e5264 100644
--- a/gnuradio-core/src/lib/runtime/Makefile.am
+++ b/gnuradio-core/src/lib/runtime/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2003,2004,2007,2008,2009,2010 Free Software Foundation, Inc.
+# Copyright 2003,2004,2007,2008,2009,2010,2011 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -58,7 +58,7 @@ libruntime_la_SOURCES = 			\
 	gr_sync_block.cc			\
 	gr_sync_decimator.cc			\
 	gr_sync_interpolator.cc			\
-	gr_tmp_path.cc				\
+	gr_sys_paths.cc				\
 	gr_top_block.cc				\
 	gr_top_block_impl.cc			\
 	gr_tpb_detail.cc			\
@@ -121,7 +121,7 @@ grinclude_HEADERS = 				\
 	gr_tpb_detail.h				\
 	gr_tpb_thread_body.h			\
 	gr_timer.h				\
-	gr_tmp_path.h				\
+	gr_sys_paths.h				\
 	gr_types.h				\
 	gr_unittests.h				\
 	gr_vmcircbuf.h				\
diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc
index 21934677b6..c2ca047a85 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 <gr_preferences.h>
+#include <gr_sys_paths.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -37,14 +38,6 @@
 #include <boost/filesystem/path.hpp>
 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";
diff --git a/gnuradio-core/src/lib/runtime/gr_sys_paths.cc b/gnuradio-core/src/lib/runtime/gr_sys_paths.cc
new file mode 100644
index 0000000000..9d10a3ccdd
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_sys_paths.cc
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2011 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gr_sys_paths.h>
+#include <cstdlib> //getenv
+#include <cstdio>  //P_tmpdir (maybe)
+
+const char *gr_tmp_path(){
+    const char *path;
+
+    //first case, try TMP environment variable
+    path = getenv("TMP");
+    if (path) return path;
+
+    //second case, try P_tmpdir when its defined
+    #ifdef P_tmpdir
+    if (P_tmpdir) return P_tmpdir;
+    #endif /*P_tmpdir*/
+
+    //fall-through case, nothing worked
+    return "/tmp";
+}
+
+const char *gr_appdata_path(){
+    const char *path;
+
+    //first case, try HOME environment variable (unix)
+    path = getenv("HOME");
+    if (path) return path;
+
+    //second case, try APPDATA environment variable (windows)
+    path = getenv("APPDATA");
+    if (path) return path;
+
+    //fall-through case, nothing worked
+    return gr_tmp_path();
+}
diff --git a/gnuradio-core/src/lib/runtime/gr_sys_paths.h b/gnuradio-core/src/lib/runtime/gr_sys_paths.h
new file mode 100644
index 0000000000..aa82497752
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_sys_paths.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2011 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _GR_SYS_PATHS_H_
+#define _GR_SYS_PATHS_H_
+
+//! directory to create temporary files
+const char *gr_tmp_path();
+
+//! directory to store application data
+const char *gr_appdata_path();
+
+#endif /* _GR_SYS_PATHS_H_ */
diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc b/gnuradio-core/src/lib/runtime/gr_tmp_path.cc
deleted file mode 100644
index 1f0c830cdd..0000000000
--- a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2003 Free Software Foundation, Inc.
- * 
- * This file is part of GNU Radio
- * 
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- * 
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#include <gr_tmp_path.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-const char *
-gr_tmp_path ()
-{
-  static char *pp = 0;
-
-  if (pp)
-    return pp;
-
-  char *s = getenv ("TMP");
-  if (s){
-    pp = strdup (s);
-    return pp;
-  }
-
-#ifdef P_tmpdir
-  if (P_tmpdir){
-    pp = strdup (P_tmpdir);
-    return pp;
-  }
-#endif
-
-  pp = strdup ("/tmp");
-  return pp;
-}
-
diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.h b/gnuradio-core/src/lib/runtime/gr_tmp_path.h
deleted file mode 100644
index 3d02043c7c..0000000000
--- a/gnuradio-core/src/lib/runtime/gr_tmp_path.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2003 Free Software Foundation, Inc.
- * 
- * This file is part of GNU Radio
- * 
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- * 
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef _GR_TMP_PATH_H_
-#define _GR_TMP_PATH_H_
-
-/*!
- * \brief return directory portion of pathname used for temporary files.
- */
-const char *gr_tmp_path ();
-
-#endif /* _GR_TMP_PATH_H_ */
diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc
index 65fe0c4880..42c459484b 100644
--- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc
+++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2003,2005 Free Software Foundation, Inc.
+ * Copyright 2003,2005,2011 Free Software Foundation, Inc.
  *
  * This file is part of GNU Radio
  *
@@ -36,7 +36,6 @@
 #include <errno.h>
 #include <stdio.h>
 #include <gr_pagesize.h>
-#include <gr_tmp_path.h>
 #include <gr_vmcircbuf_createfilemapping.h>
 
 #ifdef HAVE_CREATEFILEMAPPING
diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc
index 3017036ef5..4f7ae39cd6 100644
--- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc
+++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2003 Free Software Foundation, Inc.
+ * Copyright 2003,2011 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -37,7 +37,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <gr_pagesize.h>
-#include <gr_tmp_path.h>
+#include <gr_sys_paths.h>
 
 
 gr_vmcircbuf_mmap_shm_open::gr_vmcircbuf_mmap_shm_open (int size)
diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc
index faae4b396e..ee8b0c485c 100644
--- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc
+++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2003 Free Software Foundation, Inc.
+ * Copyright 2003,2011 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -39,7 +39,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <gr_pagesize.h>
-#include <gr_tmp_path.h>
+#include <gr_sys_paths.h>
 
 gr_vmcircbuf_mmap_tmpfile::gr_vmcircbuf_mmap_tmpfile (int size)
   : gr_vmcircbuf (size)
-- 
cgit v1.2.3