Fix some valgrind issues
[scilab.git] / scilab / modules / fileio / sci_gateway / c / sci_filesep.c
index 5d705d5..0a7c417 100644 (file)
@@ -1,31 +1,44 @@
-/*-----------------------------------------------------------------------------------*/
-/* INRIA 2007 */
-/* Allan CORNET */
-/*-----------------------------------------------------------------------------------*/
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2007 - INRIA - Allan CORNET
+ * ...
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+/*--------------------------------------------------------------------------*/
+#include <string.h>
 #include "gw_fileio.h"
 #include "stack-c.h"
 #include "MALLOC.h"
 #include "Scierror.h"
-/*-----------------------------------------------------------------------------------*/
-int C2F(sci_filesep) _PARAMS((char *fname,unsigned long fname_len))
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+/*--------------------------------------------------------------------------*/
+int sci_filesep(char *fname, unsigned long fname_len)
 {
-       static int n1,m1;
-       char *separator=NULL;
+    int n1, m1;
+    char *separator;
 
-       CheckRhs(0,0);
-       CheckLhs(1,1);
+    CheckRhs(0, 0);
+    CheckLhs(1, 1);
 
-       separator=(char*)MALLOC(sizeof(char)*(strlen(DIR_SEPARATOR)+1));
-       if (separator) strcpy(separator,DIR_SEPARATOR);
+    /* Pass as reference as it will always be copied into the stack */
+    separator = DIR_SEPARATOR;
 
-       n1 = 1;
-       CreateVarFromPtr(Rhs+1, "c",(m1=(int)strlen(separator), &m1),&n1,&separator);
-       LhsVar(1)=Rhs+1;
-       C2F(putlhsvar)();
+    n1 = 1;
+    m1 = (int) strlen(separator);
+    CreateVarFromPtr(Rhs + 1, STRING_DATATYPE, &m1, &n1, &separator);
+    LhsVar(1) = Rhs + 1;
 
-       if (separator) {FREE(separator);separator=NULL;}
+    PutLhsVar();
 
-       return 0;
+    return 0;
 }
-/*-----------------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/