/* 
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *         (C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */
 
#include <qstringlist.h>
#include <qstring.h>

#include "environment.h"

extern char **environ;

QString Environment::getEnvValue(const QString & v) {
	return getEnvPair(v).section('=', 1, 1);
}

QString Environment::getEnvPair(const QString & v) {
	uint slen = v.length() + 1;

	for(uint n = 0; environ[n] != NULL; ++n)
		if(!strncmp((v + '=').latin1(), environ[n], slen))
			return environ[n];
			
	return "";
}

QStringList Environment::getCurrentEnv() {
	QStringList lst;

	for(uint n = 0; environ[n] != NULL; ++n)
		lst << environ[n];
		
	return lst;
}
