From: Giuseppe Scrivano <gscrivano@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: emacs & MAXPATHLEN
Date: Sat, 30 Jul 2005 19:18:29 +0200 [thread overview]
Message-ID: <87irys9pqy.fsf@gmail.com> (raw)
In-Reply-To: <E1Dyt5N-0004CW-N5@fencepost.gnu.org> (Richard M. Stallman's message of "Sat, 30 Jul 2005 11:17:13 -0400")
"Richard M. Stallman" <rms@gnu.org> writes:
> Could you make a single subroutine and call it from both
> buffer.c and xsmfns.c?
I created two new files: cwd.h and cwd.c with the routine. This new patch uses them. Now src/Makefile.in is modified too:
--- 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/Makefile.in.old 2005-07-30 18:28:12.000000000 +0200
+++ src/Makefile.in 2005-07-30 18:15:26.000000000 +0200
@@ -587,7 +587,7 @@
alloc.o data.o doc.o editfns.o callint.o \
eval.o floatfns.o fns.o print.o lread.o \
abbrev.o syntax.o UNEXEC bytecode.o \
- process.o callproc.o \
+ process.o cwd.o callproc.o \
region-cache.o sound.o atimer.o \
doprnt.o strftime.o intervals.o textprop.o composite.o md5.o \
$(MSDOS_OBJ) $(MAC_OBJ) $(CYGWIN_OBJ)
@@ -1078,6 +1078,7 @@
cm.o: cm.c cm.h termhooks.h $(config_h)
cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \
msdos.h dispextern.h keyboard.h keymap.h
+cwd.o: cwd.c cwd.h $(config_h)
pre-crt0.o: pre-crt0.c
ecrt0.o: ecrt0.c $(config_h)
CRT0_COMPILE ${srcdir}/ecrt0.c
--- src/cwd.h.old 1970-01-01 01:00:00.000000000 +0100
+++ src/cwd.h 2005-07-30 18:06:43.000000000 +0200
@@ -0,0 +1,24 @@
+/* Header file for the curret working directory routine.
+ Copyright (C) 1985, 1986, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
+ 2003, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+
+
+extern char * get_cwd ();
--- src/cwd.c.old 1970-01-01 01:00:00.000000000 +0100
+++ src/cwd.c 2005-07-30 19:04:03.000000000 +0200
@@ -0,0 +1,125 @@
+/* Get current working directory routine for GNU Emacs.
+ Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 98, 99,
+ 2000, 01, 02, 03, 04, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "lisp.h"
+
+#ifndef USE_CRT_DLL
+extern int errno;
+#endif
+
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/* Return the current working directory. Returns NULL on errors.
+ Any other returned value must be freed with free. */
+char*
+get_cwd ()
+{
+ 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_CURRENT_DIR_NAME
+ else
+ {
+ buf = get_current_dir_name ();
+ if (!buf)
+ return NULL;
+ }
+#elif HAVE_GETCWD
+ else
+ {
+#ifdef MAXPATHLEN
+ buf = (char *) malloc (MAXPATHLEN + 1);
+ if (!buf)
+ return NULL;
+ if (getcwd (buf, MAXPATHLEN + 1) == NULL)
+ return NULL;
+#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;
+}
--- src/buffer.c.old 2005-07-28 19:14:42.000000000 +0200
+++ src/buffer.c 2005-07-30 18:42:20.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 <unistd.h>
@@ -52,6 +48,7 @@
#include "keyboard.h"
#include "keymap.h"
#include "frame.h"
+#include "cwd.h"
struct buffer *current_buffer; /* the current buffer */
@@ -5114,7 +5111,6 @@
void
init_buffer ()
{
- char buf[MAXPATHLEN + 1];
char *pwd;
struct stat dotstat, pwdstat;
Lisp_Object temp;
@@ -5137,37 +5133,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_cwd ();
+
+ 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 +5171,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-07-30 19:11:29.000000000 +0200
@@ -51,11 +51,7 @@
#include "termhooks.h"
#include "termopts.h"
#include "xterm.h"
-
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 1024
-#endif /* not MAXPATHLEN */
-
+#include "cwd.h"
/* The user login name. */
@@ -205,7 +201,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 +255,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_cwd ();
+
+ if (cwd)
{
props[props_idx] = &prop_ptr[props_idx];
props[props_idx]->name = SmCurrentDirectory;
@@ -281,6 +274,9 @@
xfree (smid_opt);
+ if (cwd)
+ free (cwd);
+
/* See if we maybe shall interact with the user. */
if (interactStyle != SmInteractStyleAny
|| ! shutdown
next prev parent reply other threads:[~2005-07-30 17:18 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-28 15:32 emacs & MAXPATHLEN Giuseppe Scrivano
2005-07-29 0:11 ` Richard M. Stallman
2005-07-29 0:22 ` Giuseppe Scrivano
2005-07-29 13:29 ` Alfred M. Szmidt
2005-07-29 13:54 ` Richard M. Stallman
2005-07-29 18:30 ` Giuseppe Scrivano
2005-07-30 1:31 ` Giuseppe Scrivano
2005-07-30 10:56 ` Eli Zaretskii
2005-07-30 11:27 ` Jan D.
2005-07-30 11:53 ` Alfred M. Szmidt
2005-07-30 14:28 ` Eli Zaretskii
2005-07-30 14:46 ` Alfred M. Szmidt
2005-07-30 17:35 ` Andreas Schwab
2005-07-30 18:06 ` Eli Zaretskii
2005-07-30 18:18 ` Jan D.
2005-07-30 19:11 ` Andreas Schwab
2005-08-01 0:46 ` Richard M. Stallman
2005-08-01 8:58 ` Andreas Schwab
2005-08-01 16:46 ` Richard M. Stallman
2005-08-01 18:03 ` David Kastrup
2005-08-03 13:33 ` Richard M. Stallman
2005-08-03 14:09 ` David Kastrup
2005-08-03 23:11 ` Richard M. Stallman
2005-08-04 6:30 ` David Kastrup
2005-08-04 10:44 ` Sascha Wilde
2005-08-04 11:13 ` David Kastrup
2005-08-04 14:25 ` Sascha Wilde
2005-08-04 14:38 ` David Kastrup
2005-08-04 17:57 ` Alfred M. Szmidt
2005-08-04 18:11 ` Juanma Barranquero
2005-08-04 18:41 ` David Kastrup
2005-08-04 18:46 ` Juanma Barranquero
2005-08-04 19:07 ` Markus Gritsch
2005-08-01 18:52 ` Andreas Schwab
2005-08-02 17:44 ` Richard M. Stallman
2005-07-30 23:44 ` Richard M. Stallman
2005-07-31 0:05 ` Giuseppe Scrivano
2005-07-30 11:49 ` Alfred M. Szmidt
2005-07-30 12:23 ` Jan D.
2005-07-30 12:50 ` Alfred M. Szmidt
2005-07-30 12:58 ` Giuseppe Scrivano
2005-07-30 13:11 ` Andreas Schwab
2005-07-30 13:38 ` Giuseppe Scrivano
2005-07-30 12:52 ` Giuseppe Scrivano
2005-07-30 15:17 ` Richard M. Stallman
2005-07-30 17:18 ` Giuseppe Scrivano [this message]
2005-08-01 0:46 ` Richard M. Stallman
2005-08-01 13:38 ` Giuseppe Scrivano
2005-07-29 13:54 ` Eli Zaretskii
2005-07-30 3:34 ` Richard M. Stallman
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87irys9pqy.fsf@gmail.com \
--to=gscrivano@gmail.com \
--cc=emacs-devel@gnu.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.