2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2006 - INRIA
4 * Copyright (C) 2008 - INRIA - Allan CORNET
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
15 #include <string.h> /* strlen */
17 #include <Windows.h> /* GetEnvironmentVariable */
18 #include "strdup_windows.h"
22 #include "localization.h"
24 #include "FileExist.h"
25 /*--------------------------------------------------------------------------*/
27 static void searchenv_others(const char *filename, const char *varname,
30 /*--------------------------------------------------------------------------*/
31 void C2F(getenvc)(int *ierr,char *var,char *buf,int *buflen,int *iflag)
34 if (GetEnvironmentVariable(var,buf,(DWORD)*buflen) == 0)
36 if ( *iflag == 1 ) sciprint(_("Undefined environment variable %s.\n"),var);
41 *buflen = (int)strlen(buf);
46 if ( (local=getenv(var)) == 0)
48 if ( *iflag == 1 ) sciprint(_("Undefined environment variable %s.\n"),var);
53 strncpy(buf,local,*buflen);
54 *buflen = strlen(buf);
59 /*--------------------------------------------------------------------------*/
61 static void searchenv_others(const char *filename,
69 if( filename[0] == DIR_SEPARATOR[0])
71 strcpy(pathname, filename);
78 /* environment Variable not defined. */
87 /* skip PATH_SEPARATOR[0] and empty entries */
88 while( (*cp) && (*cp == PATH_SEPARATOR[0]) )
94 while( (*cp) && (*cp != PATH_SEPARATOR[0]) )
101 if ( concat == pathname )
103 /* filename not found */
108 if( *(concat-1) != DIR_SEPARATOR[0] )
110 /* add directory separator */
111 *concat = DIR_SEPARATOR[0];
115 /* concatate path & filename */
116 strcpy(concat, filename);
119 if(FileExist(pathname))
130 /*--------------------------------------------------------------------------*/
131 char *searchEnv(const char *name,const char *env_var)
134 char fullpath[PATH_MAX];
139 _searchenv(name,env_var,fullpath);
141 searchenv_others(name,env_var,fullpath);
144 if (strlen(fullpath) > 0) buffer = strdup(fullpath);
147 /*--------------------------------------------------------------------------*/