From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: MIYASHITA Hisashi(=?ISO-2022-JP?B?GyRCNVwyPBsoQiAbJEI+MBsoQjpISU1J?=) Newsgroups: gmane.emacs.devel Subject: Re: init_buffer PWD fix Date: Thu, 25 Apr 2002 02:13:30 +0900 Sender: emacs-devel-admin@gnu.org Message-ID: References: <8296-Wed24Apr2002190326+0300-eliz@is.elta.co.il> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII X-Trace: main.gmane.org 1019668685 13587 127.0.0.1 (24 Apr 2002 17:18:05 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 24 Apr 2002 17:18:05 +0000 (UTC) Cc: eggert@twinsun.com, emacs-devel@gnu.org, knagano@sodan.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 170QP7-0003X2-00 for ; Wed, 24 Apr 2002 19:18:05 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 170QQs-0008RJ-00 for ; Wed, 24 Apr 2002 19:19:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 170QOz-0001PA-00; Wed, 24 Apr 2002 13:17:57 -0400 Original-Received: from meadow.scphys.kyoto-u.ac.jp ([130.54.54.165]) by fencepost.gnu.org with smtp (Exim 3.34 #1 (Debian)) id 170QKo-00011p-00 for ; Wed, 24 Apr 2002 13:13:39 -0400 Original-Received: (qmail 17332 invoked from network); 24 Apr 2002 17:12:48 -0000 Original-Received: from meadow.meadow.scphys.kyoto-u.ac.jp (HELO MILCH.meadowy.org.meadowy.org) (root@172.16.1.1) by meadow.meadow.scphys.kyoto-u.ac.jp with SMTP; 24 Apr 2002 17:12:48 -0000 Original-To: Eli Zaretskii In-Reply-To: <8296-Wed24Apr2002190326+0300-eliz@is.elta.co.il> (Eli Zaretskii's message of "Wed, 24 Apr 2002 19:03:26 +0300") Original-Lines: 69 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) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:3193 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:3193 "Eli Zaretskii" 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