update C2F(getenvc)
[scilab.git] / scilab / modules / io / src / c / getenvc.c
index 3e5814d..9cbcde6 100644 (file)
@@ -1,28 +1,42 @@
-/* Copyright INRIA/ENPC */
-/* returns setenv defined variable when getenv fails */
-#include <stdio.h>
-#include <string.h>
-#include "core_math.h"
+/*-----------------------------------------------------------------------------------*/
+/* INRIA 2006 */
+/* Scilab */
+/*-----------------------------------------------------------------------------------*/ 
+#if _MSC_VER
+       #include <Windows.h> /* GetEnvironmentVariable */
+#else
+       #include <stdlib.h> /* getenv */
+#endif
+#include <string.h> /* strlen */
 #include "machine.h"
 #include "sciprint.h"
 /*-----------------------------------------------------------------------------------*/
 void C2F(getenvc)(int *ierr,char *var,char *buf,int *buflen,int *iflag)
 {
-  char *getenv(const char *),*local;
-  *ierr=0;
-  if ( (local=getenv(var)) == 0)
-    {
-      if ( *iflag == 1 )
-       sciprint("You must define the environment variable %s\r\n",var);
-      *ierr=1;
-      return;
-    }
-  else 
-    {
-      strncpy(buf,local,*buflen);
-      *buflen = strlen(buf);
-    }
-  return;
+       #if _MSC_VER
+       if (GetEnvironmentVariable(var,buf,(DWORD)buflen)==0)
+       {
+               if ( *iflag == 1 ) sciprint("You must define the environment variable %s\r\n",var);
+               *ierr=1;
+       }
+       else
+       {
+               *buflen = strlen(buf);
+               *ierr=0;
+       }
+       #else
+       char *local;
+       if ( (local=getenv(var)) == 0)
+       {
+               if ( *iflag == 1 ) sciprint("You must define the environment variable %s\r\n",var);
+               *ierr=1;
+       }
+       else 
+       {
+               strncpy(buf,local,*buflen);
+               *buflen = strlen(buf);
+       }
+       #endif
 }
 /*-----------------------------------------------------------------------------------*/