bug 2273
Allan CORNET [Mon, 3 Nov 2008 07:56:17 +0000 (08:56 +0100)]
12 files changed:
scilab/CHANGES_5.1
scilab/modules/completion/src/c/LibScilab_Import.def
scilab/modules/completion/src/c/getfilesdictionary.c
scilab/modules/core/sci_gateway/c/sci_chdir.c
scilab/modules/core/sci_gateway/c/sci_getcwd.c
scilab/modules/core/src/c/scicurdir.c
scilab/modules/core/src/c/scicurdir.h
scilab/modules/core/tests/nonreg_tests/bug_2273.tst [new file with mode: 0644]
scilab/modules/fileio/LibScilab_Import.def
scilab/modules/fileio/sci_gateway/c/sci_findfiles.c
scilab/modules/io/sci_gateway/c/sci_get_absolute_file_path.c
scilab/modules/io/src/c/LibScilab_Import.def

index b990be8..3359170 100644 (file)
@@ -97,3 +97,4 @@ Bug fixes:
 
 * bug 3571 fixed - Only one message displayed when log(0) is computed with ieee(1) mode.
 
+* bug 2273 fixed - chdir didn't manage UNC path on Windows
\ No newline at end of file
index e2fed18..c279c5a 100644 (file)
@@ -16,7 +16,7 @@ com_
 callFunctionFromGateway
 getlibrarieslist
 getlistmacrosfromlibrary
-scigetcwd_
+scigetcwd
 cluni0_
 getVariablesName
 getcommandkeywords
index 2aebda5..18cf5a6 100644 (file)
@@ -13,7 +13,7 @@
 #include <stdio.h> /* sprintf */
 #include "getfilesdictionary.h"
 #include "PATH_MAX.h"
-#include "../../../core/src/c/scicurdir.h" /* C2F(scigetcwd) */
+#include "../../../core/src/c/scicurdir.h" /* scigetcwd */
 #include "findfiles.h" /* findfiles */
 #include "MALLOC.h"
 #include "cluni0.h"
@@ -46,7 +46,7 @@ char **getfilesdictionary(char *somechars,int *sizearray)
                        int lpath = 0;
                        char *currentpath = NULL;
 
-                       C2F(scigetcwd)(&currentpath,&lpath,&ierr);
+                       scigetcwd(&currentpath,&lpath,&ierr);
                        if (currentpath) {strcpy(path,currentpath);}
                }
                else
index 206c662..bafe313 100644 (file)
@@ -43,7 +43,7 @@ int C2F(sci_chdir)(char *fname,unsigned long fname_len)
                }
 
                C2F(cluni0)(shortpath,path,&out_n,(long)strlen(shortpath),PATH_MAX);
-               C2F(scichdir)(path,&ierr);
+               scichdir(path,&ierr);
 
                n1=1;
                CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
index e40bf15..3cb33b9 100644 (file)
@@ -27,7 +27,7 @@ int C2F(sci_getcwd)(char *fname,unsigned long fname_len)
        CheckRhs(0,0);
        CheckLhs(0,1);
 
-       C2F(scigetcwd)(&path,&lpath,&ierr);
+       scigetcwd(&path,&lpath,&ierr);
 
        if (ierr)
        {
index 5a1fd05..9926753 100644 (file)
@@ -14,6 +14,7 @@
 #ifdef _MSC_VER 
        #include <windows.h>
        #include <direct.h>
+       #include <errno.h>
 #else 
        #include <unistd.h>
        #define GETCWD(x,y) getcwd(x,y)
 #include "PATH_MAX.h"
 static char cur_dir[PATH_MAX];
 /*--------------------------------------------------------------------------*/
-/* checks if it is a UNC path */
-static BOOL isUNCpath(char *path);
-/*--------------------------------------------------------------------------*/
-int C2F(scichdir)(char *path,int *err)
+int scichdir(char *path,int *err)
 {
        *err=0;
        if (path == (char*) NULL) 
@@ -38,26 +36,33 @@ int C2F(scichdir)(char *path,int *err)
                return (0);
        }
 
-        if (isUNCpath(path))
-        {
-           if ( getWarningMode() ) sciprint(_("Can't go to directory %s.\n"), path); 
-               *err = 1;
-               return (0);
-        }
-
 #ifndef _MSC_VER
        if (chdir(path) == -1) 
-#else
-       if (SetCurrentDirectory(path) == 0)
-#endif
        {
                if ( getWarningMode() ) sciprint(_("Can't go to directory %s.\n"), path); 
-           *err=1;
+               *err=1;
        } 
+#else
+       if ( _chdir(path) )
+       {
+               switch (errno)
+               {
+               case ENOENT:
+                       if ( getWarningMode() ) sciprint(_("Can't go to directory %s.\n"), path); 
+                       break;
+               case EINVAL:
+                       if ( getWarningMode() ) sciprint(_("Invalid buffer.\n")); 
+                       break;
+               default:
+                       if ( getWarningMode() ) sciprint(_("Unknown error.\n")); 
+               }
+               *err = 1;
+       }
+#endif
        return 0;
 }
 /*--------------------------------------------------------------------------*/
-int C2F(scigetcwd)(char **path,int *lpath,int *err)
+int scigetcwd(char **path,int *lpath,int *err)
 {
 #ifndef _MSC_VER
        if (GETCWD(cur_dir, PATH_MAX) == (char*) 0)
@@ -80,12 +85,3 @@ int C2F(scigetcwd)(char **path,int *lpath,int *err)
     return 0;
 }
 /*--------------------------------------------------------------------------*/
-static BOOL isUNCpath(char *path)
-{
-       if ( (path) && (strncmp(path,"\\\\",2) == 0) )
-       {
-               return TRUE;
-       }
-       return FALSE;
-}
-/*--------------------------------------------------------------------------*/
index c1fb22f..34b40b4 100644 (file)
@@ -18,7 +18,7 @@
  * @param path : the path where Scilab should go
  * @param[out] err : the error code
  */
-int C2F(scichdir)(char *path,int *err);
+int scichdir(char *path,int *err);
 
 /**
  * Get scilab current directory 
@@ -26,7 +26,7 @@ int C2F(scichdir)(char *path,int *err);
  * @param[out] lpath : the length of the char * path
  * @param[out] err : the error code
  */
-int C2F(scigetcwd)(char **path,int *lpath,int *err);
+int scigetcwd(char **path,int *lpath,int *err);
 
 #endif /* __SCICURDIR_H__ */
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_2273.tst b/scilab/modules/core/tests/nonreg_tests/bug_2273.tst
new file mode 100644 (file)
index 0000000..fae39f0
--- /dev/null
@@ -0,0 +1,24 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- Non-regression test for bug 2273 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=2273
+//
+// <-- Short Description -->
+// Scilab didn't manage UNC path on Windows
+
+// <-- INTERACTIVE TEST -->
+
+// creates a UNC path example \\MON-PC\TEST-UNC-PATH
+// launch scilab from this UNC path
+cd '\\MON-PC\TEST-UNC-PATH'
+pwd
+cd SCI
+cd WSCI
+chdir '\\MON-PC\TEST-UNC-PATH'
\ No newline at end of file
index ab88429..131777c 100644 (file)
@@ -27,4 +27,4 @@ getrhsvar_
 stack_
 getScilabMode
 iop_
-scigetcwd_
\ No newline at end of file
+scigetcwd
\ No newline at end of file
index 8a49c20..ae8ff67 100644 (file)
@@ -16,7 +16,7 @@
 #include "stack-c.h"
 #include "MALLOC.h"
 #include "localization.h"
-#include "../../../core/src/c/scicurdir.h" /* C2F(scigetcwd) */
+#include "../../../core/src/c/scicurdir.h" /* scigetcwd */
 #include "Scierror.h"
 #include "cluni0.h"
 #include "PATH_MAX.h"
@@ -46,7 +46,7 @@ int C2F(sci_findfiles)(char *fname,unsigned long fname_len)
                        int ierr=0;
                        int lpath=0;
 
-                       C2F(scigetcwd)(&path,&lpath,&ierr);
+                       scigetcwd(&path,&lpath,&ierr);
                        needtofreepath = TRUE;
 
                        if (ierr)
index 105b9d9..f9f9ed6 100644 (file)
@@ -118,7 +118,7 @@ int C2F(sci_get_absolute_file_path)(char *fname,unsigned long fname_len)
                                                sciprint(_("%s: The file %s not found. current directory returned.\n"),fname,filename);
                                        }
 
-                                       C2F(scigetcwd)(&path,&lpath,&ierr);
+                                       scigetcwd(&path,&lpath,&ierr);
                                        if (ierr) /* Problem to get current directory */
                                        {
                                                m1=0; n1=0; l1=0; /* returns a empty string */
index b6c6317..d1b9dcc 100644 (file)
@@ -22,7 +22,7 @@ EXPORTS
  iop_
  GetFile
  getTMPDIR
- scigetcwd_
+ scigetcwd
  vartype_
  callFunctionFromGateway
  freeArrayOfString