setenvc.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /* Allan CORNET INRIA 2005 */
00003 /*-----------------------------------------------------------------------------------*/
00004 #include "machine.h"
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 #include <string.h>
00008 #include "setenvc.h"
00009 #include "MALLOC.h" /* MALLOC */
00010 
00011 #ifdef _MSC_VER
00012 #define putenv _putenv
00013 static char *env=NULL;
00014 #endif
00015 
00016 int UpdateEnvVar=0;
00017 /*-----------------------------------------------------------------------------------*/
00018 extern int setenvtcl(char *string,char *value);
00019 /*-----------------------------------------------------------------------------------*/
00020 int setenvc(char *string,char *value)
00021 {
00022   int ret=0;
00023   char* env;
00024 
00025 #ifdef LINUX
00026   if ( setenv(string,value,1) ) ret=FALSE;
00027   else 
00028     {
00029       ret=TRUE;
00030       UpdateEnvVar=1;
00031     }
00032 #else /* others HP Solaris WIN32*/
00033   env=(char*)MALLOC((strlen(string)+strlen(value)+2)*sizeof(char));
00034   sprintf(env,"%s=%s",string,value);
00035   if ( putenv(env) ) ret=FALSE;
00036   else 
00037     {
00038       setenvtcl(string,value);
00039       ret=TRUE;
00040       UpdateEnvVar=1;
00041     }
00042 #ifdef _MSC_VER
00043   if (env)
00044     {
00045       FREE(env);
00046       env=NULL;
00047     }
00048 #endif
00049 #endif
00050 
00051   return ret;
00052 }
00053 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:58 2007 for Scilab [trunk] by  doxygen 1.5.1