[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: init_buffer PWD fix

From: 宮下 尚:HIMI
Subject: Re: init_buffer PWD fix
Date: Thu, 25 Apr 2002 02:13:30 +0900
User-agent: T-gnus/6.15.4 (based on Oort Gnus v0.04) (revision 11) SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/21.1 (i386-msvc-nt5.1.2600) MULE/5.0 (SAKAKI) Meadow/1.99 Alpha1 (AWOFUCHI)

"Eli Zaretskii" <address@hidden> writes:

>> Furthermore, in this view, I think that we MUST NOT use "PWD"
>> environment variable to obtain the current directory because it's
>> never standardized.
> Do you know of some Windows application that uses PWD in an
> incompatible fashion?  I use Windows for quite some time, and have
> never seen such a beast.  The only applications that use PWD are
> ported Unix and GNU tools, and they all use it in a consistent manner.

Almost all of the Windows application do not care about "PWD".  
I can imagin many bad situations.  Suppose the following
situation as an example.

(1) sh or tcsh set "PWD" and the current directory to "c:/PROGRA~1" (this name 
    the short name of "c:/Program Files"), and then invokes a program.

(2) the invoked program set the current directory to "c:/Program Files"
    by SetCurrentDirectory().

(3) then it invokes Emacs.

I confirmed that by invoking tcsh.exe -> cmd.exe -> emacs.exe.

In this case, Emacs set the default directory to "c:/PROGRA~1", which is clearly
different from the expected value.  On the other hand, accoding to POSIX 
it's imperative that "PWD" be appropriately set by shell.  And convensionally,
"PWD" is often used to refer current directory on many UNIX systems.  Therefore
Such problem seldom occurs.  Thus, I can agree on the current code on many
UNIX systems.  And surely it's convenient.
(But I remember that some old shells (old bash or tcsh) did not set "PWD"
 environment variable on UNIX. ;-)

On Windows, however, it's not only useless but also harmful, I think.

The above case is an example to affirm relying on "PWD" by obscure convension
is maybe harmful.  Furthermore, the original code is not easy to understand and
seems very platform dependent.  I don't think the follwing change makes
the matters worse.

#if !defined(WINDOWSNT)   /* I think this condition will include more non-POSIX 
                             in the future. */
  if ((pwd = getenv ("PWD")) != 0
      && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1])))
      && stat (pwd, &pwdstat) == 0
      && stat (".", &dotstat) == 0
      && dotstat.st_ino == pwdstat.st_ino
      && dotstat.st_dev == pwdstat.st_dev
      && strlen (pwd) < MAXPATHLEN)
    strcpy (buf, pwd);
     if (getcwd (buf, MAXPATHLEN+1) == 0)
       fatal ("`getcwd' failed: %s\n", strerror (errno));
    else if (getwd (buf) == 0)
      fatal ("`getwd' failed: %s\n", buf);

from himi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]