Claw  1.7.3
system_info_unix.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
31 #ifndef __CLAW_SYSTEM_INFO_UNIX_HPP__
32 #define __CLAW_SYSTEM_INFO_UNIXHPP__
33 
34 #include <cstdlib>
35 #include <string>
36 
37 namespace claw
38 {
45  {
46  public:
47  /*------------------------------------------------------------------------*/
51  static std::string get_user_name()
52  {
53  std::string result( get_environment("USER") );
54 
55  if ( result.empty() )
56  result = get_environment("LOGNAME");
57 
58  return result;
59  } // get_user_name()
60 
61  /*------------------------------------------------------------------------*/
65  static std::string get_user_directory()
66  {
67  return get_environment("HOME");
68  } // get_user_directory()
69 
70  /*------------------------------------------------------------------------*/
74  template<typename Sequence>
75  static void get_path( Sequence& path )
76  {
77  //
78  } // get_path()
79 
80  /*------------------------------------------------------------------------*/
84  static std::string get_host_name()
85  {
86  return get_environment("HOSTNAME");
87  } // get_host_name()
88 
89  /*------------------------------------------------------------------------*/
94  static std::string get_temporary_directory()
95  {
96  return get_environment("TMPDIR");
97  } // get_temporary_directory()
98 
99  /*------------------------------------------------------------------------*/
104  static std::string get_environment( const std::string& var )
105  {
106  char* value = getenv( var.c_str() );
107  std::string result;
108 
109  if ( value )
110  result = value;
111 
112  return result;
113  } // get_environment()
114 
115  }; // class system_info
116 } // namespace claw
117 
118 #endif // __CLAW_SYSTEM_INFO_UNIX_HPP__