Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c125b495c30d8bc5da4d31afd9cca0f6662476c2
Ticket: 218213ffffffffffffffffffffffffffffffffff
Windows pathname bug with \\nethost\dir names
User & Date: nobody on 2000-10-26 00:54:35
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 2531 Bug
    Version: 8.0.3
    SubmitDate: '1999-08-12'
    LastModified: '1999-12-03'
    Severity: MED
    Status: Closed
    Submitter: techsupp
    ChangedBy: hobbs
    OS: Windows 95
    OSVersion: original release (not OSR2)
    Machine: X86
    FixedDate: '2000-10-25'
    ClosedDate: '1999-12-03'
    
    
    Name:
    
    James Bonfield
    
    
    
    Extensions:
    
    Home made extensions...
    
    
    
    CustomShell:
    
    None.
    
    
    
    Comments:
    
    This fix removes the / to \ filename conversion. As the code itself
    
        documented,
    
        this conversion is necessary for some system interfaces. Which?
    
        I suspect this is old code dealing with the Win32s version, which is now
    
        dead
    
        and burried.
    
        Our Win95 machine (first release - not OSR2) works fine with forward
    
        slashes. Indeed as we have seen it works better with forward slashes
    
        than with backward slashes! Windows 98 has the same system bug, although
    
        it's been fixed in NT.
    
        
    
        I realise that this is not a Tcl bug. The Tcl open code internally
    
        appears to
    
        use different windows interfaces, which do not get stumped by this bug.
    
        However
    
        the bug makes it hard to add existing code onto a Tcl interpreter. (It's
    
        not
    
        always practical to rewrite masses of old code to use the Tcl channel
    
        functions.)
    
        
    
        This same code is in tcl8.2b1, so I expect the problem also arises
    
        there. Indeed
    
        the patch above was made against that release.
    
    
    
    ReproducibleScript:
    
    Changing the current working directory to a directory with
    
        //hostname/dir
    
        syntax will then cause the Windows open() system call to return errors.
    
        This
    
        is a Windows bug, but it is only triggered when using \\hostname\dir
    
        notation.
    
        Unfortunately the Tcl library automatically converts / into \.
    
        
    
        Eg:
    
        % cd c:
    
        % trace_type //arran/jkb/a.scf
    
        SCF
    
        % cd //arran/jkb
    
        % trace_type //arran/jkb/a.scf
    
        UNK
    
        %
    
        
    
        Here, trace_type is our own function, which calls open() directly. The
    
        current
    
        working directory has a direct impact on whether this works, even though
    
        we
    
        specify a full pathname!
    
        
    
        The following C program demonstrates the problem.
    
        
    
        /* --------------------------------------------------------- */
    
        #include "windows.h"
    
        #include "direct.h"
    
        #include <io.h>
    
        #include <fcntl.h>
    
        #include <sys/types.h>
    
        #include <sys/stat.h>
    
        
    
        main(int argc,char *argv[])
    
        {
    
            int drv;
    
            char buf[100];
    
            int fd;
    
        
    
            if(argc < 1){
    
                printf("No directory specified\n");
    
                return 1;
    
            }
    
        
    
            drv=_getdrive();
    
            printf("drive before is %d\n",drv);
    
            printf("changing to dir \"%s\"\n",argv[1]);
    
            SetCurrentDirectory(argv[1]);
    
            GetCurrentDirectory(100,buf);
    
            printf("drive is set to: %s\n",buf);
    
        
    
            drv=_getdrive();
    
            printf("drive after is %d\n",drv);
    
        
    
            //       _chdrive(3);
    
            fd = _open("//arran/jkb/a.scf", O_RDONLY);
    
            if( fd > 0 )
    
                printf("open succeeded\n");
    
            else
    
                printf("open failed, errno=%d",errno);
    
            _read(fd,buf,100);
    
            printf("got %s\n",buf);
    
        
    
            return 0;
    
        }
    
        /* ----------------------------------------------------------- */
    
        
    
        Compiling this up on Win95 as drv.exe, we can try:
    
        
    
        c:\> drv //arran/jkb
    
        drive before is 3
    
        changing dir to "//arran/jkb"
    
        drive is set to: C:\\arran\jkb
    
        drive after is 3
    
        open succeeded
    
        got filecontents
    
        
    
        c:\> drv \\arran\jkb
    
        drive before is 3
    
        changing dir to "\\arran\jkb"
    
        drive is set to: \\arran\jkb
    
        drive after is 0
    
        open failed, errno=2
    
        
    
        An alternative fix is for us to directly call _chdrive(3); before the
    
        open if
    
        (and only if) the pathname starts with //.
    
    
    
    ObservedBehavior:
    
    Full pathnames given to the C open() function should not be dependent on
    
        your current working directory.
    
    
    
    DesiredBehavior:
    
    Our trace_type function should work fine regardless of directory.
    
    
    
    Patch:
    
    *** tclFileName.c.orig  Fri Aug  6 11:18:12 1999
    
    --- tclFileName.c       Fri Aug  6 11:18:43 1999
    
    ***************
    
    *** 1006,1023 ****
    
            Tcl_JoinPath(1, &name, bufferPtr);
    
          }
    
      
    
    -     /*
    
    -      * Convert forward slashes to backslashes in Windows paths because
    
    -      * some system interfaces don't accept forward slashes.
    
    -      */
    
    - 
    
    -     if (tclPlatform == TCL_PLATFORM_WINDOWS) {
    
    -       for (p = Tcl_DStringValue(bufferPtr); *p != '\0'; p++) {
    
    -           if (*p == '/') {
    
    -               *p = '\\';
    
    -           }
    
    -       }
    
    -     }
    
          return Tcl_DStringValue(bufferPtr);
    
      }
    
      
    
    
    
    --- 1006,1011 ----
    
    
    
    PatchFiles:
    
    tclFileName.c
    
    
    
    
    
    One system interface which still requires \'s is LoadLibrary.
    This user will have to work within the confines set, and perhaps
    a util routine to convert back easily at the C level would be good. 
    -- 12/03/1999 hobbs
    
  4. foundin changed to: "obsolete: 8.0.3"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "37. File System"
  10. title changed to: "Windows pathname bug with \\nethost\dir names"
  11. type changed to: "Bug"