unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "MIYASHITA Hisashi" <himi@meadowy.org>
Cc: eggert@twinsun.com,  emacs-devel@gnu.org,  knagano@sodan.org
Subject: Re: init_buffer PWD fix
Date: Thu, 25 Apr 2002 02:13:30 +0900	[thread overview]
Message-ID: <uhem1t3yd.fsf@MILCH.meadowy.org> (raw)
In-Reply-To: <8296-Wed24Apr2002190326+0300-eliz@is.elta.co.il> (Eli Zaretskii's message of "Wed, 24 Apr 2002 19:03:26 +0300")

"Eli Zaretskii" <eliz@is.elta.co.il> 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 is
    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 standard,
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 systems
                             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);
  else 
#else
   {
#ifdef HAVE_GETCWD 
     if (getcwd (buf, MAXPATHLEN+1) == 0)
       fatal ("`getcwd' failed: %s\n", strerror (errno));
#else
    else if (getwd (buf) == 0)
      fatal ("`getwd' failed: %s\n", buf);
#endif
  }
#endif

from himi

  reply	other threads:[~2002-04-24 17:13 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-21 20:15 init_buffer PWD fix Keiichiro Nagano
2002-04-21 23:00 ` Keiichiro Nagano
2002-04-22  6:18 ` Paul Eggert
2002-04-22  7:20   ` Keiichiro Nagano
2002-04-22 11:15     ` Eli Zaretskii
2002-04-22 21:16     ` Jason Rumney
2002-04-22  7:53   ` Eli Zaretskii
2002-04-22  7:01     ` Paul Eggert
2002-04-22  8:10       ` Eli Zaretskii
2002-04-22  7:22         ` Paul Eggert
2002-04-22 11:14           ` Eli Zaretskii
2002-04-22 23:21             ` Paul Eggert
2002-04-23  6:05               ` Eli Zaretskii
2002-04-22 21:21         ` Jason Rumney
2002-04-23  5:56           ` Eli Zaretskii
2002-04-23  6:14   ` MIYASHITA Hisashi
2002-04-23 11:00     ` Eli Zaretskii
2002-04-24 17:55       ` Richard Stallman
2002-04-24 18:14         ` MIYASHITA Hisashi
2002-04-23 17:45     ` Paul Eggert
2002-04-24  6:52       ` MIYASHITA Hisashi
2002-04-24  7:13         ` Paul Eggert
2002-04-24  7:45           ` MIYASHITA Hisashi
2002-04-24 11:12             ` Eli Zaretskii
2002-04-24 10:30               ` MIYASHITA Hisashi
2002-04-24 16:03                 ` Eli Zaretskii
2002-04-24 17:13                   ` MIYASHITA Hisashi [this message]
2002-04-24 18:10                     ` Eli Zaretskii
2002-04-24 18:25                       ` MIYASHITA Hisashi
2002-04-24 19:19                     ` Paul Eggert
2002-04-24 19:41                       ` MIYASHITA Hisashi
2002-04-24 19:59                         ` MIYASHITA Hisashi
2002-04-24 20:21                         ` Paul Eggert
2002-04-24 20:41                           ` MIYASHITA Hisashi
2002-04-24 21:01                             ` Paul Eggert
2002-04-24 21:23                               ` MIYASHITA Hisashi
2002-04-24 21:35                                 ` MIYASHITA Hisashi
2002-04-25 22:52                                 ` Stefan Monnier
2002-04-25  3:42                             ` Eli Zaretskii
2002-04-24 16:47                 ` Paul Eggert
2002-04-24 17:55                   ` MIYASHITA Hisashi
2002-04-24 10:38               ` MIYASHITA Hisashi
2002-04-24 16:08                 ` Eli Zaretskii
2002-04-24 16:10                 ` Eli Zaretskii
2002-04-24  7:55           ` MIYASHITA Hisashi
2002-04-24 11:07           ` Eli Zaretskii
2002-04-24 11:05         ` Eli Zaretskii
2002-04-24 10:31           ` MIYASHITA Hisashi
2002-04-24 16:05             ` Eli Zaretskii
2002-04-22  7:03 ` Eli Zaretskii
2002-04-22  6:49   ` Keiichiro Nagano
2002-04-22  8:01     ` Eli Zaretskii
2002-04-22  8:26       ` Keiichiro Nagano
2002-04-22 11:19         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=uhem1t3yd.fsf@MILCH.meadowy.org \
    --to=himi@meadowy.org \
    --cc=eggert@twinsun.com \
    --cc=emacs-devel@gnu.org \
    --cc=knagano@sodan.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).