Skip to content

Commit 7fa3720

Browse files
author
rblazek
committed
+putEnv
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13001 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3da5e17 commit 7fa3720

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

src/providers/grass/qgsgrass.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,15 @@ void GRASS_EXPORT QgsGrass::init( void )
188188
}
189189

190190
QgsDebugMsg( QString( "Valid GRASS gisBase is: %1" ).arg( gisBase ) );
191-
QString gisBaseEnv = "GISBASE=" + gisBase;
192-
/* _Correct_ putenv() implementation is not making copy! */
193-
char *gisBaseEnvChar = new char[gisBaseEnv.toUtf8().length()+1];
194-
strcpy( gisBaseEnvChar, gisBaseEnv.toUtf8().constData() );
195-
putenv( gisBaseEnvChar );
191+
putEnv ( "GISBASE", gisBase );
196192

197193
// Add path to GRASS modules
198194
#ifdef WIN32
199195
QString sep = ";";
200196
#else
201197
QString sep = ":";
202198
#endif
203-
QString path = "PATH=" + gisBase + "/bin";
199+
QString path = gisBase + "/bin";
204200
path.append( sep + gisBase + "/scripts" );
205201
path.append( sep + QgsApplication::pkgDataPath() + "/grass/scripts/" );
206202

@@ -223,18 +219,14 @@ void GRASS_EXPORT QgsGrass::init( void )
223219
path.append( sep + p );
224220

225221
QgsDebugMsg( QString( "set PATH: %1" ).arg( path ) );
226-
char *pathEnvChar = new char[path.toUtf8().length()+1];
227-
strcpy( pathEnvChar, path.toUtf8().constData() );
228-
putenv( pathEnvChar );
222+
putEnv ( "PATH", path );
229223

230224
// Set PYTHONPATH
231-
QString pythonpath = "PYTHONPATH=" + gisBase + "/etc/python";
225+
QString pythonpath = gisBase + "/etc/python";
232226
QString pp = getenv( "PATH" );
233227
pythonpath.append( sep + pp );
234228
QgsDebugMsg( QString( "set PYTHONPATH: %1" ).arg( pythonpath ) );
235-
char *pythonpathEnvChar = new char[pythonpath.toUtf8().length()+1];
236-
strcpy( pythonpathEnvChar, pythonpath.toUtf8().constData() );
237-
putenv( pythonpathEnvChar );
229+
putEnv ( "PYTHONPATH", pythonpath );
238230

239231
// Set GRASS_PAGER if not set, it is necessary for some
240232
// modules printing to terminal, e.g. g.list
@@ -273,10 +265,7 @@ void GRASS_EXPORT QgsGrass::init( void )
273265

274266
if ( pager.length() > 0 )
275267
{
276-
pager.prepend( "GRASS_PAGER=" );
277-
char *pagerEnvChar = new char[pager.length()+1];
278-
strcpy( pagerEnvChar, pager.toUtf8().constData() );
279-
putenv( pagerEnvChar );
268+
putEnv ( "GRASS_PAGER", pager );
280269
}
281270
}
282271

@@ -558,13 +547,10 @@ QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, Q
558547
// Set GISRC environment variable
559548

560549
/* _Correct_ putenv() implementation is not making copy! */
561-
QString gisrcEnv = "GISRC=" + mGisrc;
562-
char *gisrcEnvChar = new char[gisrcEnv.toUtf8().length()+1];
563-
strcpy( gisrcEnvChar, gisrcEnv.toLocal8Bit().constData() );
564-
putenv( gisrcEnvChar );
550+
putEnv ( "GISRC", mGisrc );
565551

566552
// Reinitialize GRASS
567-
G__setenv(( char * ) "GISRC", gisrcEnv.toUtf8().data() );
553+
G__setenv(( char * ) "GISRC", mGisrc.toUtf8().data() );
568554
#if defined(WIN32)
569555
G__setenv(( char * ) "GISDBASE", shortPath( gisdbase ).toLocal8Bit().data() );
570556
#else
@@ -1258,3 +1244,11 @@ QString GRASS_EXPORT QgsGrass::gisrcFilePath()
12581244
return mGisrc;
12591245
}
12601246

1247+
void GRASS_EXPORT QgsGrass::putEnv( QString name, QString value )
1248+
{
1249+
QString env = name + "=" + value;
1250+
/* _Correct_ putenv() implementation is not making copy! */
1251+
char *envChar = new char[env.toUtf8().length()+1];
1252+
strcpy( envChar, env.toUtf8().constData() );
1253+
putenv( envChar );
1254+
}

src/providers/grass/qgsgrass.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ class QgsGrass
187187
static GRASS_EXPORT int versionRelease();
188188
static GRASS_EXPORT QString versionString();
189189

190+
// set environment variable
191+
static GRASS_EXPORT void putEnv (QString name, QString value);
192+
190193
#if defined(WIN32)
191194
static GRASS_EXPORT QString shortPath( const QString &path );
192195
#endif

0 commit comments

Comments
 (0)