3eadf83629618339377638dc351c8c9ee768ee12
[scilab.git] / scilab / modules / fileio / sci_gateway / c / sci_fullpath.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2007 - INRIA - Allan CORNET
4  * ...
5  * 
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
11  *
12  */
13 /*--------------------------------------------------------------------------*/
14 #ifndef _MSC_VER
15 #include <sys/param.h>
16 #endif
17 #include <stdlib.h>
18 #include "gw_fileio.h"
19 #include "stack-c.h"
20 #include "MALLOC.h"
21 #include "machine.h"
22 #include "Scierror.h"
23 #include "localization.h"
24 /*--------------------------------------------------------------------------*/
25 #ifndef _MSC_VER
26 #define _fullpath(a,r,l)        realpath(r,a)
27 #endif
28 /*--------------------------------------------------------------------------*/
29 int C2F(sci_fullpath)(char *fname,unsigned long fname_len)
30 {
31         Rhs=Max(Rhs,0);
32         CheckRhs(1,1) ;
33         CheckLhs(0,1) ;
34
35         if (GetType(1) == sci_strings)
36         {
37                 static int l1,n1,m1;
38                 char *relPath=NULL;
39                 char fullpath[PATH_MAX*4];
40                 
41                 GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
42                 relPath=cstk(l1);
43
44                 if( _fullpath( fullpath, relPath, PATH_MAX*4 ) != NULL )
45                 {
46                         char *Output=NULL;
47                         Output=(char*)MALLOC((strlen(fullpath)+1)*sizeof(char));
48                         strcpy(Output,fullpath);
49
50                         n1=1;
51                         CreateVarFromPtr( Rhs+1,STRING_DATATYPE,(m1=(int)strlen(Output), &m1),&n1,&Output);
52                         LhsVar(1) = Rhs+1;
53                         C2F(putlhsvar)();       
54
55                         if (Output) {FREE(Output);Output=NULL;}
56                 }
57                 else
58                 {
59                         Scierror(999,_("%s: Wrong value for first input argument: '%s' is an invalid path.\n"),fname,relPath);
60                 }
61         }
62         else
63         {
64                 Scierror(999,_("%s: Wrong type for first input argument: String expected.\n"),fname);
65         }
66
67         return 0;
68 }
69 /*--------------------------------------------------------------------------*/
70