From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Giuseppe Scrivano Newsgroups: gmane.emacs.devel Subject: Re: emacs & MAXPATHLEN Date: Sat, 30 Jul 2005 03:31:48 +0200 Message-ID: <87r7dhxenv.fsf@gmail.com> References: <87fytzj6a7.fsf@gmail.com> <87pst2h35e.fsf@gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1122687240 28058 80.91.229.2 (30 Jul 2005 01:34:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 30 Jul 2005 01:34:00 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jul 30 03:33:52 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DygEV-0006xY-M3 for ged-emacs-devel@m.gmane.org; Sat, 30 Jul 2005 03:33:48 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DygH2-0006ZF-10 for ged-emacs-devel@m.gmane.org; Fri, 29 Jul 2005 21:36:24 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DygGI-0006Nb-Ci for emacs-devel@gnu.org; Fri, 29 Jul 2005 21:35:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DygGH-0006NH-0V for emacs-devel@gnu.org; Fri, 29 Jul 2005 21:35:37 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DygGG-0006N6-G6 for emacs-devel@gnu.org; Fri, 29 Jul 2005 21:35:36 -0400 Original-Received: from [64.233.170.199] (helo=rproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DygO4-0002qw-68 for emacs-devel@gnu.org; Fri, 29 Jul 2005 21:43:40 -0400 Original-Received: by rproxy.gmail.com with SMTP id c16so1180358rne for ; Fri, 29 Jul 2005 18:31:43 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:to:cc:subject:references:from:date:in-reply-to:message-id:user-agent:mime-version:content-type; b=tzOUskRm8FkDUkmJ4ngHrlK70CAGIX9VBQkY1uw4TUb9pioDDy4cFZcPFP/BMfCI/wdslQnfGlbKlH4qxpF9z7M037gKVaHXQuEtFLNAkDionxyrJGH8UzBOo078nEhEUuO+/lnz/CrACt3SVF7pdvWlfDQ9MR0E2N1zLyLoFXo= Original-Received: by 10.38.12.25 with SMTP id 25mr451249rnl; Fri, 29 Jul 2005 18:31:43 -0700 (PDT) Original-Received: from steel ([80.181.159.241]) by mx.gmail.com with ESMTP id c3sm5220626rne.2005.07.29.18.31.42; Fri, 29 Jul 2005 18:31:43 -0700 (PDT) Original-Received: from gscrivano by steel with local (Exim 4.52) id 1DygCa-0000Bt-TT; Sat, 30 Jul 2005 03:31:49 +0200 Original-To: rms@gnu.org In-Reply-To: (Richard M. Stallman's message of "Fri, 29 Jul 2005 09:54:05 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:41326 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:41326 This new patch should fix the problem both with get_current_dir_name and getcwd. I think a compilation error when getwd is used without a MAXPATHLEN is nice to have. The buffer used with getcwd is duplicated ever time it is too small. configure.in was modified to check for the get_current_dir_name function too. I hope I am following GCS now. Giuseppe Scivano --- configure.in.old 2005-07-29 18:14:02.000000000 +0200 +++ configure.in 2005-07-29 18:19:26.000000000 +0200 @@ -2414,7 +2414,7 @@ AC_CHECK_HEADERS(maillock.h) AC_CHECK_FUNCS(gethostname getdomainname dup2 \ -rename closedir mkdir rmdir sysinfo getrusage \ +rename closedir mkdir rmdir sysinfo getrusage get_current_dir_name \ random lrand48 bcopy bcmp logb frexp fmod rint cbrt ftime res_init setsid \ strerror fpathconf select mktime euidaccess getpagesize tzset setlocale \ utimes setrlimit setpgid getcwd getwd shutdown getaddrinfo \ --- src/buffer.c.old 2005-07-28 19:14:42.000000000 +0200 +++ src/buffer.c 2005-07-30 03:20:36.000000000 +0200 @@ -31,10 +31,6 @@ extern int errno; #endif -#ifndef MAXPATHLEN -/* in 4.1 [probably SunOS? -stef] , param.h fails to define this. */ -#define MAXPATHLEN 1024 -#endif /* not MAXPATHLEN */ #ifdef HAVE_UNISTD_H #include @@ -5114,7 +5110,7 @@ void init_buffer () { - char buf[MAXPATHLEN + 1]; + char *buf; char *pwd; struct stat dotstat, pwdstat; Lisp_Object temp; @@ -5140,20 +5136,64 @@ /* If PWD is accurate, use it instead of calling getwd. PWD is sometimes a nicer name, and using it may avoid a fatal error if a parent directory is searchable but not readable. */ - if ((pwd = getenv ("PWD")) != 0 + 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); -#ifdef HAVE_GETCWD - else if (getcwd (buf, MAXPATHLEN+1) == 0) - fatal ("`getcwd' failed: %s\n", strerror (errno)); +#ifdef MAXPATHLEN + && strlen (pwd) < MAXPATHLEN +#endif + ) + { + buf = xmalloc (strlen (pwd) + 1); + strcpy (buf, pwd); + } +#ifdef HAVE_CURRENT_DIR_NAME + else + { + buf = get_current_dir_name (); + if(!buf) + fatal ("`get_current_dir_name' failed in init_buffer\n"); + } +#elif HAVE_GETCWD + else + { +#ifdef MAXPATHLEN + buf = xmalloc (MAXPATHLEN + 1); + if(getcwd (buf, MAXPATHLEN + 1) == 0) + fatal ("`getwd' failed: %s\n", buf); +#else + { + int buf_size = 2; + buf = xmalloc (buf_size); + for(;;) + { + if(getcwd (buf, buf_size) == 0) + { + if(errno == ERANGE) + { + buf_size *= 2; + buf = xrealloc (buf, buf_size); + } + else + fatal ("`getcwd' failed: %s\n", strerror (errno)); + } + else + break; + } + + } +#endif + } #else - else if (getwd (buf) == 0) - fatal ("`getwd' failed: %s\n", buf); + else + { + buf = xmalloc (MAXPATHLEN + 1); + if(getwd (buf) == 0) + fatal ("`getwd' failed: %s\n", buf); + } #endif #ifndef VMS @@ -5189,6 +5229,12 @@ temp = get_minibuffer (0); XBUFFER (temp)->directory = current_buffer->directory; + +#ifdef HAVE_CURRENT_DIR_NAME + free (buf); +#else + xfree (buf); +#endif } /* initialize the buffer routines */ --- src/xsmfns.c.old 2005-07-28 19:51:24.000000000 +0200 +++ src/xsmfns.c 2005-07-30 03:29:19.000000000 +0200 @@ -45,6 +45,8 @@ #include #include +#include + #include "systime.h" #include "sysselect.h" #include "lisp.h" @@ -52,10 +54,6 @@ #include "termopts.h" #include "xterm.h" -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif /* not MAXPATHLEN */ - /* The user login name. */ @@ -205,7 +203,7 @@ int val_idx = 0; int props_idx = 0; - char cwd[MAXPATHLEN+1]; + char *cwd = NULL; char *smid_opt; /* How to start a new instance of Emacs. */ @@ -259,12 +257,42 @@ props[props_idx]->vals[0].value = SDATA (Vuser_login_name); ++props_idx; - /* The current directory property, not mandatory. */ -#ifdef HAVE_GETCWD - if (getcwd (cwd, MAXPATHLEN+1) != 0) +#ifdef HAVE_GET_CURRENT_DIR_NAME + cwd = get_current_dir_name (); +#elif HAVE_GETCWD + { + int cwd_size = 2; + cwd = xmalloc (cwd_size); + for(;;) + { + if(getcwd (cwd, cwd_size) == 0) + { + if(errno == ERANGE) + { + cwd_size *= 2; + cwd = xrealloc (cwd, cwd_size); + } + else + { + xfree (cwd); + cwd = NULL; + } + } + else + break; + } + + } #else - if (getwd (cwd) != 0) + cwd = xmalloc (MAXPATHLEN + 1); + if(getwd (cwd) == 0) + { + xfree (cwd); + cwd = NULL; + } #endif + + if(!cwd) { props[props_idx] = &prop_ptr[props_idx]; props[props_idx]->name = SmCurrentDirectory; @@ -281,6 +309,13 @@ xfree (smid_opt); + if(cwd) +#ifdef HAVE_CURRENT_DIR_NAME + free (cwd); +#else + xfree (cwd); +#endif + /* See if we maybe shall interact with the user. */ if (interactStyle != SmInteractStyleAny || ! shutdown