update C2F(getenvc)
[scilab.git] / scilab / modules / io / src / c / getenvc.c
1 /*-----------------------------------------------------------------------------------*/
2 /* INRIA 2006 */
3 /* Scilab */
4 /*-----------------------------------------------------------------------------------*/ 
5 #if _MSC_VER
6         #include <Windows.h> /* GetEnvironmentVariable */
7 #else
8         #include <stdlib.h> /* getenv */
9 #endif
10 #include <string.h> /* strlen */
11 #include "machine.h"
12 #include "sciprint.h"
13 /*-----------------------------------------------------------------------------------*/
14 void C2F(getenvc)(int *ierr,char *var,char *buf,int *buflen,int *iflag)
15 {
16         #if _MSC_VER
17         if (GetEnvironmentVariable(var,buf,(DWORD)buflen)==0)
18         {
19                 if ( *iflag == 1 ) sciprint("You must define the environment variable %s\r\n",var);
20                 *ierr=1;
21         }
22         else
23         {
24                 *buflen = strlen(buf);
25                 *ierr=0;
26         }
27         #else
28         char *local;
29         if ( (local=getenv(var)) == 0)
30         {
31                 if ( *iflag == 1 ) sciprint("You must define the environment variable %s\r\n",var);
32                 *ierr=1;
33         }
34         else 
35         {
36                 strncpy(buf,local,*buflen);
37                 *buflen = strlen(buf);
38         }
39         #endif
40 }
41 /*-----------------------------------------------------------------------------------*/
42