@@ -188,19 +188,15 @@ void GRASS_EXPORT QgsGrass::init( void )
188
188
}
189
189
190
190
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 );
196
192
197
193
// Add path to GRASS modules
198
194
#ifdef WIN32
199
195
QString sep = " ;" ;
200
196
#else
201
197
QString sep = " :" ;
202
198
#endif
203
- QString path = " PATH= " + gisBase + " /bin" ;
199
+ QString path = gisBase + " /bin" ;
204
200
path.append ( sep + gisBase + " /scripts" );
205
201
path.append ( sep + QgsApplication::pkgDataPath () + " /grass/scripts/" );
206
202
@@ -223,18 +219,14 @@ void GRASS_EXPORT QgsGrass::init( void )
223
219
path.append ( sep + p );
224
220
225
221
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 );
229
223
230
224
// Set PYTHONPATH
231
- QString pythonpath = " PYTHONPATH= " + gisBase + " /etc/python" ;
225
+ QString pythonpath = gisBase + " /etc/python" ;
232
226
QString pp = getenv ( " PATH" );
233
227
pythonpath.append ( sep + pp );
234
228
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 );
238
230
239
231
// Set GRASS_PAGER if not set, it is necessary for some
240
232
// modules printing to terminal, e.g. g.list
@@ -273,10 +265,7 @@ void GRASS_EXPORT QgsGrass::init( void )
273
265
274
266
if ( pager.length () > 0 )
275
267
{
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 );
280
269
}
281
270
}
282
271
@@ -558,13 +547,10 @@ QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, Q
558
547
// Set GISRC environment variable
559
548
560
549
/* _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 );
565
551
566
552
// Reinitialize GRASS
567
- G__setenv (( char * ) " GISRC" , gisrcEnv .toUtf8 ().data () );
553
+ G__setenv (( char * ) " GISRC" , mGisrc .toUtf8 ().data () );
568
554
#if defined(WIN32)
569
555
G__setenv (( char * ) " GISDBASE" , shortPath ( gisdbase ).toLocal8Bit ().data () );
570
556
#else
@@ -1258,3 +1244,11 @@ QString GRASS_EXPORT QgsGrass::gisrcFilePath()
1258
1244
return mGisrc ;
1259
1245
}
1260
1246
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
+ }
0 commit comments