[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Environment variable setters/getters?
From: Angus Leeming <leeming () lyx ! org>
Date: 2005-12-19 13:14:22
Message-ID: do6bhb$g0g$1 () sea ! gmane ! org
[Download RAW message or body]
Are there any K (or Q) wrappers for getenv, setenv/putenv?
([GS]etEnvironmentVariable on Windows). I can't see any but I'm likely
looking in the wrong place ;-)
For info, I attach the implementation I've been using in QDVI
(http://sourceforge.net/projects/qdvi/).
Thoughts? Perhaps it should be turned into a class?
Regards,
Angus
["environment.cpp" (text/x-c++src)]
// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
/**
* \file environment.cpp
* Distributed under the GNU GPL version 2 or (at your option)
* any later version. See accompanying file COPYING or copy at
* http://www.gnu.org/copyleft/gpl.html
*
* \author Angus Leeming
* \author João Luis M. Assirati
* \author Lars Gullik Bjønnes
*/
#include <config.h>
#include "environment.h"
#include "os.h"
#include <QMap>
#include <QString>
#include <QStringList>
#include <cstdlib>
namespace kvs {
QString const getEnv(const QString& envname)
{
const char* const ch = ::getenv(envname.toLocal8Bit());
return !ch ? QString() : ch;
}
bool setEnv(const QString& name, QString const& value)
{
#if defined (HAVE_SETENV)
const int retval = ::setenv(name.toLocal8Bit(), value.local8Bit(), true);
#elif defined (HAVE_PUTENV)
static QMap<QString, QByteArray> varmap;
const QByteArray envstr = QString(name + '=' + value).toLocal8Bit();
const char* const envcstr = envstr;
const int retval = ::putenv(const_cast<char *>(envcstr));
varmap[name] = envstr;
#else
#error No environment-setting function has been defined.
#endif
return retval == 0;
}
QStringList const getEnvPath(const QString& name)
{
#if defined _WIN32
const char path_separator = ';';
#else
const char path_separator = ':';
#endif
return getEnv(name).split(path_separator);
}
} // namespace kvs
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic