From 5515a1fd092a80abba2ba81d6e4aa8fd214563f8 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Mon, 28 Dec 2009 21:23:17 +0800 Subject: [PATCH] Implement Env util class --- src/Database.cc | 2 +- src/Util.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Database.cc b/src/Database.cc index b955134..7207496 100644 --- a/src/Database.cc +++ b/src/Database.cc @@ -137,7 +137,7 @@ Database::initUserDatabase (const gchar *userdb) m_sql << "INSERT OR IGNORE INTO userdb.desc VALUES " << "('version', '1.2.0');\n" << "INSERT OR IGNORE INTO userdb.desc VALUES " << "('uuid', '" << UUID () << "');\n" << "INSERT OR IGNORE INTO userdb.desc VALUES " << "('hostname', '" << Hostname () << "');\n" - << "INSERT OR IGNORE INTO userdb.desc VALUES " << "('username', '" << getenv ("USERNAME") << "');\n" + << "INSERT OR IGNORE INTO userdb.desc VALUES " << "('username', '" << Env ("USERNAME") << "');\n" << "INSERT OR IGNORE INTO userdb.desc VALUES " << "('create-time', datetime());\n" << "INSERT OR IGNORE INTO userdb.desc VALUES " << "('attach-time', datetime());\n"; diff --git a/src/Util.h b/src/Util.h index aaa0178..836e8f3 100644 --- a/src/Util.h +++ b/src/Util.h @@ -3,6 +3,8 @@ #include #include +#include +#include "String.h" namespace PY { @@ -40,6 +42,18 @@ public: } }; +class Env : public String { +public: + Env (const gchar *name) { + gchar *str; + str = getenv (name); + assign (str != NULL ? str : ""); + } + operator const gchar *(void) const { + return c_str(); + } +}; + class StaticString { public: StaticString (const gchar *str) : m_string (str) {} -- 2.7.4