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: Mon, 01 Aug 2005 15:38:27 +0200 Message-ID: <87mzo1zsj0.fsf@gmail.com> References: <87fytzj6a7.fsf@gmail.com> <87pst2h35e.fsf@gmail.com> <87r7dhxenv.fsf@gmail.com> <87irys9pqy.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 1122905607 1283 80.91.229.2 (1 Aug 2005 14:13:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 1 Aug 2005 14:13:27 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 01 16:13:22 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Dzb1q-0005Zs-RV for ged-emacs-devel@m.gmane.org; Mon, 01 Aug 2005 16:12:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dzb4V-0000i4-7f for ged-emacs-devel@m.gmane.org; Mon, 01 Aug 2005 10:15:15 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DzaxV-0005VV-3U for emacs-devel@gnu.org; Mon, 01 Aug 2005 10:08:01 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DzaxS-0005Tx-Uc for emacs-devel@gnu.org; Mon, 01 Aug 2005 10:07:59 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DzauV-0003ji-ID for emacs-devel@gnu.org; Mon, 01 Aug 2005 10:04:55 -0400 Original-Received: from [64.233.170.194] (helo=rproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Dzah4-0003Og-7m for emacs-devel@gnu.org; Mon, 01 Aug 2005 09:51:02 -0400 Original-Received: by rproxy.gmail.com with SMTP id y7so1482931rne for ; Mon, 01 Aug 2005 06:38:30 -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=gpV8Moetx0asq2H76yHIS5iUeVx8mQiicBQmPtrG2aWe3ItbPCsx4HogtcQX//fPvlWPi1JxO2raHkIoa+TG4UtOxtdl991FTo6ZKKyBzPJV0I00zJR3VmfwIXXvFvxEPzzogrYb0yvuom+ZYII57+hmsfaUEcFq7Oj/vN1e8a8= Original-Received: by 10.38.75.18 with SMTP id x18mr2528766rna; Mon, 01 Aug 2005 06:38:30 -0700 (PDT) Original-Received: from steel ([80.181.159.241]) by mx.gmail.com with ESMTP id k23sm4306228rnb.2005.08.01.06.38.28; Mon, 01 Aug 2005 06:38:30 -0700 (PDT) Original-Received: from gscrivano by steel with local (Exim 4.52) id 1DzaUu-0003YU-2l; Mon, 01 Aug 2005 15:38:28 +0200 Original-To: rms@gnu.org In-Reply-To: (Richard M. Stallman's message of "Sun, 31 Jul 2005 20:46:08 -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:41401 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:41401 "Richard M. Stallman" writes: > 1. I'd rather put this in sysdep.c and avoid the hassle of > two new files. Done. > 2. It could be called get_current_dir_name, > and defined only when the system does not define it. > That would simplify things. Done. > 3. I'd rather not include this: > > +#ifdef MAXPATHLEN > + buf = (char *) malloc (MAXPATHLEN + 1); > + if (!buf) > + return NULL; > + if (getcwd (buf, MAXPATHLEN + 1) == NULL) > + return NULL; > +#else Done. Giuseppe Scrivano This is the new patch, please let me know if you have other comments or suggestions: --- 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/sysdep.c.old 2005-07-27 13:54:24.000000000 +0200 +++ src/sysdep.c 2005-08-01 15:28:44.000000000 +0200 @@ -258,6 +258,81 @@ SIGMASKTYPE sigprocmask_set; + +#ifndef HAVE_CURRENT_DIR_NAME + +/* Return the current working directory. Returns NULL on errors. + Any other returned value must be freed with free. This is used + only when get_current_dir_name s not yet defined on the system. */ +char* +get_current_dir_name () +{ + char *buf; + char *pwd; + struct stat dotstat, pwdstat; + /* 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 + && (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 +#ifdef MAXPATHLEN + && strlen (pwd) < MAXPATHLEN +#endif + ) + { + buf = (char *) malloc (strlen (pwd) + 1); + if (!buf) + return NULL; + strcpy (buf, pwd); + } +#ifdef HAVE_GETCWD + else + { + size_t buf_size = 1024; + buf = (char *) malloc (buf_size); + if (!buf) + return NULL; + for (;;) + { + if (getcwd (buf, buf_size) == buf) + break; + if (errno != ERANGE) + { + int tmp_errno = errno; + free (buf); + errno = tmp_errno; + return NULL; + } + buf_size *= 2; + buf = (char *) realloc (buf, buf_size); + if (!buf) + return NULL; + } +#endif + } +#else + else + { + buf = (char *) malloc (MAXPATHLEN + 1); + if (!buf) + return NULL; + if (getwd (buf) == NULL) + { + int tmp_errno = errno; + free (buf); + errno = tmp_errno; + return NULL; + } + } +#endif + return buf; +} +#endif + /* Specify a different file descriptor for further input operations. */ --- src/buffer.c.old 2005-07-28 19:14:42.000000000 +0200 +++ src/buffer.c 2005-08-01 15:13:38.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 @@ -53,6 +49,8 @@ #include "keymap.h" #include "frame.h" +extern char * get_current_dir_name (); + struct buffer *current_buffer; /* the current buffer */ /* First buffer in chain of all buffers (in reverse order of creation). @@ -5114,7 +5112,6 @@ void init_buffer () { - char buf[MAXPATHLEN + 1]; char *pwd; struct stat dotstat, pwdstat; Lisp_Object temp; @@ -5137,37 +5134,23 @@ if (NILP (buffer_defaults.enable_multibyte_characters)) Fset_buffer_multibyte (Qnil); - /* 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 - && (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)); -#else - else if (getwd (buf) == 0) - fatal ("`getwd' failed: %s\n", buf); -#endif + pwd = get_current_dir_name (); + + if(!pwd) + fatal ("`get_cwd' failed: %s\n", strerror (errno)); #ifndef VMS /* Maybe this should really use some standard subroutine whose definition is filename syntax dependent. */ - rc = strlen (buf); - if (!(IS_DIRECTORY_SEP (buf[rc - 1]))) + rc = strlen (pwd); + if (!(IS_DIRECTORY_SEP (pwd[rc - 1]))) { - buf[rc] = DIRECTORY_SEP; - buf[rc + 1] = '\0'; + pwd[rc] = DIRECTORY_SEP; + pwd[rc + 1] = '\0'; } #endif /* not VMS */ - current_buffer->directory = make_unibyte_string (buf, strlen (buf)); + current_buffer->directory = make_unibyte_string (pwd, strlen (pwd)); if (! NILP (buffer_defaults.enable_multibyte_characters)) /* At this momemnt, we still don't know how to decode the direcotry name. So, we keep the bytes in multibyte form so @@ -5189,6 +5172,8 @@ temp = get_minibuffer (0); XBUFFER (temp)->directory = current_buffer->directory; + + free (pwd); } /* initialize the buffer routines */ --- src/xsmfns.c.old 2005-07-28 19:51:24.000000000 +0200 +++ src/xsmfns.c 2005-08-01 15:13:46.000000000 +0200 @@ -52,10 +52,7 @@ #include "termopts.h" #include "xterm.h" -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif /* not MAXPATHLEN */ - +extern char * get_current_dir_name (); /* The user login name. */ @@ -205,7 +202,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 +256,9 @@ 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) -#else - if (getwd (cwd) != 0) -#endif + cwd = get_current_dir_name (); + + if (cwd) { props[props_idx] = &prop_ptr[props_idx]; props[props_idx]->name = SmCurrentDirectory; @@ -281,6 +275,9 @@ xfree (smid_opt); + if (cwd) + free (cwd); + /* See if we maybe shall interact with the user. */ if (interactStyle != SmInteractStyleAny || ! shutdown