From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#12945: Assume POSIX 1003.1-1988 or later for unistd.h. Date: Tue, 20 Nov 2012 09:38:31 -0800 Message-ID: <50ABC017.7060802@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1353433208 32650 80.91.229.3 (20 Nov 2012 17:40:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 20 Nov 2012 17:40:08 +0000 (UTC) To: 12945@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Nov 20 18:40:17 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Taro1-0001WH-00 for geb-bug-gnu-emacs@m.gmane.org; Tue, 20 Nov 2012 18:40:17 +0100 Original-Received: from localhost ([::1]:46057 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tarnq-0003id-KP for geb-bug-gnu-emacs@m.gmane.org; Tue, 20 Nov 2012 12:40:06 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:58495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tarnj-0003g7-Ql for bug-gnu-emacs@gnu.org; Tue, 20 Nov 2012 12:40:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tarnc-0003gA-Vq for bug-gnu-emacs@gnu.org; Tue, 20 Nov 2012 12:39:59 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46937) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tarnc-0003fy-RY for bug-gnu-emacs@gnu.org; Tue, 20 Nov 2012 12:39:52 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Tarok-0007Ai-Pe for bug-gnu-emacs@gnu.org; Tue, 20 Nov 2012 12:41:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 20 Nov 2012 17:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 12945 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.135343321527511 (code B ref -1); Tue, 20 Nov 2012 17:41:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Nov 2012 17:40:15 +0000 Original-Received: from localhost ([127.0.0.1]:57188 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tarnx-00079d-90 for submit@debbugs.gnu.org; Tue, 20 Nov 2012 12:40:14 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:47727) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tarnt-00079V-5z for submit@debbugs.gnu.org; Tue, 20 Nov 2012 12:40:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tarma-0003Dr-Q5 for submit@debbugs.gnu.org; Tue, 20 Nov 2012 12:38:59 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:55308) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tarma-0003Dm-MB for submit@debbugs.gnu.org; Tue, 20 Nov 2012 12:38:48 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:39213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TarmT-0003Qs-SF for bug-gnu-emacs@gnu.org; Tue, 20 Nov 2012 12:38:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TarmM-0003AE-Q2 for bug-gnu-emacs@gnu.org; Tue, 20 Nov 2012 12:38:41 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:37247) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TarmM-00039y-By; Tue, 20 Nov 2012 12:38:34 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 8672D39E8105; Tue, 20 Nov 2012 09:38:33 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jjo+XunsKbf7; Tue, 20 Nov 2012 09:38:32 -0800 (PST) Original-Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id D9A1539E8106; Tue, 20 Nov 2012 09:38:31 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121029 Thunderbird/16.0.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:67216 Archived-At: Here's a patch that I plan to install to simplify Emacs based on assuming that the underyling system supports POSIX 1003.1-1988 or later with respect to unistd.h. This is universal these days on GNUish hosts, and I don't forsee any problems with Microsoft hosts. I'm CC:ing this to Eli, though, to give him a heads-up just in case. It may help in a later patch to simplify the Microsoft side by removing getwd and standardizing on getcwd, since that's what POSIX did back in 1988, but that's an issue that's independent of this patch. === modified file 'ChangeLog' --- ChangeLog 2012-11-20 08:29:04 +0000 +++ ChangeLog 2012-11-20 17:33:00 +0000 @@ -1,5 +1,8 @@ 2012-11-20 Paul Eggert + Assume POSIX 1003.1-1988 or later for unistd.h. + * configure.ac: Do not check for getcwd or getwd. + Improve static checking of integer overflow and stack smashing. * configure.ac (WARN_CFLAGS): Add -Wstack-protector if using GCC 4.7.2 or later on a platform with === modified file 'admin/CPP-DEFINES' --- admin/CPP-DEFINES 2012-11-17 22:12:47 +0000 +++ admin/CPP-DEFINES 2012-11-20 17:33:00 +0000 @@ -86,7 +86,6 @@ AMPERSAND_FULL_NAME BROKEN_DATAGRAM_SOCKETS BROKEN_FIONREAD -BROKEN_GETWD BROKEN_GET_CURRENT_DIR_NAME BROKEN_NON_BLOCKING_CONNECT BROKEN_PTY_READ_AFTER_EAGAIN @@ -161,7 +160,6 @@ HAVE_GAI_STRERROR HAVE_GCONF HAVE_GETADDRINFO -HAVE_GETCWD HAVE_GETDELIM HAVE_GETGRENT HAVE_GETHOSTNAME @@ -178,7 +176,6 @@ HAVE_GETRUSAGE HAVE_GETSOCKNAME HAVE_GETTIMEOFDAY -HAVE_GETWD HAVE_GET_CURRENT_DIR_NAME HAVE_GHOSTSCRIPT HAVE_GIF @@ -304,7 +301,6 @@ HAVE_SIGNED_WCHAR_T HAVE_SIGNED_WINT_T HAVE_SIGSET_T -HAVE_SIZE_T HAVE_SNPRINTF HAVE_SOCKETS HAVE_SOUND @@ -369,7 +365,6 @@ HAVE_TOUCHLOCK HAVE_TZNAME HAVE_TZSET -HAVE_UNISTD_H HAVE_UNSIGNED_LONG_LONG_INT HAVE_UTIL_H HAVE_UTIMENSAT === modified file 'admin/ChangeLog' --- admin/ChangeLog 2012-11-17 22:12:47 +0000 +++ admin/ChangeLog 2012-11-20 17:33:00 +0000 @@ -1,3 +1,9 @@ +2012-11-20 Paul Eggert + + Assume POSIX 1003.1-1988 or later for unistd.h. + * CPP-DEFINES (BROKEN_GETWD, HAVE_GETCWD, HAVE_GETWD, HAVE_SIZE_T) + (HAVE_UNISTD_H): Remove. + 2012-11-17 Paul Eggert Assume POSIX 1003.1-1988 or later for fcntl.h (Bug#12881). === modified file 'configure.ac' --- configure.ac 2012-11-20 08:29:04 +0000 +++ configure.ac 2012-11-20 17:33:00 +0000 @@ -2889,7 +2889,7 @@ closedir getrusage get_current_dir_name \ lrand48 \ select getpagesize setlocale \ -utimes getrlimit setrlimit getcwd shutdown getaddrinfo \ +utimes getrlimit setrlimit shutdown getaddrinfo \ strsignal setitimer \ sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ gai_strerror mkstemp getline getdelim fsync sync \ @@ -2898,14 +2898,6 @@ touchlock \ cfmakeraw cfsetspeed copysign __executable_start) -dnl getwd appears to be buggy on SVR4.2, so we don't use it. -if test $opsys = unixware; then - dnl In case some other test ends up checking for getwd. - AC_DEFINE(BROKEN_GETWD, 1, [Define if getwd should not be used.]) -else - AC_CHECK_FUNCS(getwd) -fi - ## Eric Backus says, HP-UX 9.x on HP 700 machines ## has a broken `rint' in some library versions including math library ## version number A.09.05. === modified file 'lib-src/ChangeLog' --- lib-src/ChangeLog 2012-11-20 08:31:19 +0000 +++ lib-src/ChangeLog 2012-11-20 17:33:00 +0000 @@ -1,5 +1,15 @@ 2012-11-20 Paul Eggert + Assume POSIX 1003.1-1988 or later for unistd.h. + * emacsclient.c (getcwd): Remove decl. + (get_current_dir_name): Assume getcwd exists. + * etags.c (HAVE_GETCWD): Remove. + (getcwd): Remove decl. + (NO_LONG_OPTIONS): Remove this. All uses removed. + Emacs always has GNU getopt. + (etags_getcwd): Assume getcwd exists. + * movemail.c (F_OK, X_OK, W_OK, R_OK): Remove. + * emacsclient.c (handle_sigcont, handle_sigtstp): Use raise (sig) rather than kill (getpid (), sig), as it's simpler and safer. === modified file 'lib-src/emacsclient.c' --- lib-src/emacsclient.c 2012-11-20 08:31:19 +0000 +++ lib-src/emacsclient.c 2012-11-20 17:33:00 +0000 @@ -88,10 +88,7 @@ -char *getenv (const char *), *getwd (char *); -#ifdef HAVE_GETCWD -char *(getcwd) (char *, size_t); -#endif +char *getenv (const char *); #ifndef VERSION #define VERSION "unspecified" @@ -223,7 +220,7 @@ char *buf; const char *pwd; struct stat dotstat, pwdstat; - /* If PWD is accurate, use it instead of calling getwd. PWD is + /* If PWD is accurate, use it instead of calling getcwd. 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 = egetenv ("PWD")) != 0 @@ -240,7 +237,6 @@ buf = (char *) xmalloc (strlen (pwd) + 1); strcpy (buf, pwd); } -#ifdef HAVE_GETCWD else { size_t buf_size = 1024; @@ -267,20 +263,6 @@ } } } -#else - else - { - /* We need MAXPATHLEN here. */ - buf = (char *) xmalloc (MAXPATHLEN + 1); - if (getwd (buf) == NULL) - { - int tmp_errno = errno; - free (buf); - errno = tmp_errno; - return NULL; - } - } -#endif return buf; } #endif @@ -1592,7 +1574,6 @@ cwd = get_current_dir_name (); if (cwd == 0) { - /* getwd puts message in STRING if it fails. */ message (TRUE, "%s: %s\n", progname, "Cannot get current working directory"); fail (); === modified file 'lib-src/etags.c' --- lib-src/etags.c 2012-09-17 00:56:08 +0000 +++ lib-src/etags.c 2012-11-20 17:33:00 +0000 @@ -123,19 +123,9 @@ # undef HAVE_NTGUI # undef DOS_NT # define DOS_NT -# ifndef HAVE_GETCWD -# define HAVE_GETCWD -# endif /* undef HAVE_GETCWD */ -#else /* not WINDOWSNT */ -#endif /* !WINDOWSNT */ +#endif /* WINDOWSNT */ #include -#ifndef HAVE_UNISTD_H -# if defined (HAVE_GETCWD) && !defined (WINDOWSNT) - extern char *getcwd (char *buf, size_t size); -# endif -#endif /* HAVE_UNISTD_H */ - #include #include #include @@ -152,16 +142,7 @@ # define assert(x) ((void) 0) #endif -#ifdef NO_LONG_OPTIONS /* define this if you don't have GNU getopt */ -# define NO_LONG_OPTIONS TRUE -# define getopt_long(argc,argv,optstr,lopts,lind) getopt (argc, argv, optstr) - extern char *optarg; - extern int optind, opterr; -#else -# define NO_LONG_OPTIONS FALSE -# include -#endif /* NO_LONG_OPTIONS */ - +#include #include /* Define CTAGS to make the program "ctags" compatible with the usual one. @@ -869,11 +850,7 @@ printf ("Usage: %s [options] [[regex-option ...] file-name] ...\n\ \n\ These are the options accepted by %s.\n", progname, progname); - if (NO_LONG_OPTIONS) - puts ("WARNING: long option names do not work with this executable,\n\ -as it is not linked with GNU getopt."); - else - puts ("You may use unambiguous abbreviations for the long option names."); + puts ("You may use unambiguous abbreviations for the long option names."); puts (" A - as file name means read names from stdin (one per line).\n\ Absolute names are stored in the output file as they are.\n\ Relative ones are stored relative to the output file's directory.\n"); @@ -1065,9 +1042,9 @@ /* When the optstring begins with a '-' getopt_long does not rearrange the non-options arguments to be at the end, but leaves them alone. */ - optstring = concat (NO_LONG_OPTIONS ? "" : "-", - "ac:Cf:Il:o:r:RSVhH", - (CTAGS) ? "BxdtTuvw" : "Di:"); + optstring = concat ("-ac:Cf:Il:o:r:RSVhH", + (CTAGS) ? "BxdtTuvw" : "Di:", + ""); while ((opt = getopt_long (argc, argv, optstring, longopts, NULL)) != EOF) switch (opt) @@ -6333,8 +6310,8 @@ static void suggest_asking_for_help (void) { - fprintf (stderr, "\tTry `%s %s' for a complete list of options.\n", - progname, NO_LONG_OPTIONS ? "-h" : "--help"); + fprintf (stderr, "\tTry `%s --help' for a complete list of options.\n", + progname); exit (EXIT_FAILURE); } @@ -6372,7 +6349,6 @@ static char * etags_getcwd (void) { -#ifdef HAVE_GETCWD int bufsize = 200; char *path = xnew (bufsize, char); @@ -6387,34 +6363,6 @@ canonicalize_filename (path); return path; - -#else /* not HAVE_GETCWD */ -#if MSDOS - - char *p, path[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */ - - getwd (path); - - for (p = path; *p != '\0'; p++) - if (*p == '\\') - *p = '/'; - else - *p = lowcase (*p); - - return strdup (path); -#else /* not MSDOS */ - linebuffer path; - FILE *pipe; - - linebuffer_init (&path); - pipe = (FILE *) popen ("pwd 2>/dev/null", "r"); - if (pipe == NULL || readline_internal (&path, pipe) == 0) - pfatal ("pwd"); - pclose (pipe); - - return path.buffer; -#endif /* not MSDOS */ -#endif /* not HAVE_GETCWD */ } /* Return a newly allocated string containing the file name of FILE === modified file 'lib-src/movemail.c' --- lib-src/movemail.c 2012-11-17 22:12:47 +0000 +++ lib-src/movemail.c 2012-11-20 17:33:00 +0000 @@ -96,13 +96,6 @@ #include #endif /* WINDOWSNT */ -#ifndef F_OK -#define F_OK 0 -#define X_OK 1 -#define W_OK 2 -#define R_OK 4 -#endif - #ifdef WINDOWSNT #include #endif === modified file 'src/ChangeLog' --- src/ChangeLog 2012-11-20 11:41:57 +0000 +++ src/ChangeLog 2012-11-20 17:33:00 +0000 @@ -1,5 +1,10 @@ 2012-11-20 Paul Eggert + Assume POSIX 1003.1-1988 or later for unistd.h. + * alloc.c: Assume unistd.h exists. + * sysdep.c (get_current_dir_name): Assume getcwd exists. + (getwd) [USG]: Remove; no longer needed. + * eval.c (interactive_p): Remove no-longer-used decl. 2012-11-20 Dmitry Antipov === modified file 'src/alloc.c' --- src/alloc.c 2012-11-12 01:09:34 +0000 +++ src/alloc.c 2012-11-20 17:33:00 +0000 @@ -63,10 +63,6 @@ #endif #include -#ifndef HAVE_UNISTD_H -extern void *sbrk (); -#endif - #include #ifdef USE_GTK === modified file 'src/sysdep.c' --- src/sysdep.c 2012-11-17 22:12:47 +0000 +++ src/sysdep.c 2012-11-20 17:33:00 +0000 @@ -134,12 +134,12 @@ get_current_dir_name (void) { char *buf; - char *pwd; + char *pwd = getenv ("PWD"); struct stat dotstat, pwdstat; - /* If PWD is accurate, use it instead of calling getwd. PWD is + /* If PWD is accurate, use it instead of calling getcwd. 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 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1]))) && stat (pwd, &pwdstat) == 0 && stat (".", &dotstat) == 0 @@ -155,7 +155,6 @@ return NULL; strcpy (buf, pwd); } -#ifdef HAVE_GETCWD else { size_t buf_size = 1024; @@ -179,22 +178,6 @@ return NULL; } } -#else - else - { - /* We need MAXPATHLEN here. */ - buf = 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 @@ -2238,60 +2221,6 @@ &emacs_norealloc_allocator, careadlinkatcwd); } -#ifdef USG -/* - * All of the following are for USG. - * - * On USG systems the system calls are INTERRUPTIBLE by signals - * that the user program has elected to catch. Thus the system call - * must be retried in these cases. To handle this without massive - * changes in the source code, we remap the standard system call names - * to names for our own functions in sysdep.c that do the system call - * with retries. Actually, for portability reasons, it is good - * programming practice, as this example shows, to limit all actual - * system calls to a single occurrence in the source. Sure, this - * adds an extra level of function call overhead but it is almost - * always negligible. Fred Fish, Unisoft Systems Inc. - */ - -/* - * Warning, this function may not duplicate 4.2 action properly - * under error conditions. - */ - -#if !defined (HAVE_GETWD) || defined (BROKEN_GETWD) - -#ifndef MAXPATHLEN -/* In 4.1, param.h fails to define this. */ -#define MAXPATHLEN 1024 -#endif - -char * -getwd (char *pathname) -{ - char *npath, *spath; - extern char *getcwd (char *, size_t); - - block_input (); /* getcwd uses malloc */ - spath = npath = getcwd ((char *) 0, MAXPATHLEN); - if (spath == 0) - { - unblock_input (); - return spath; - } - /* On Altos 3068, getcwd can return @hostname/dir, so discard - up to first slash. Should be harmless on other systems. */ - while (*npath && *npath != '/') - npath++; - strcpy (pathname, npath); - free (spath); /* getcwd uses malloc */ - unblock_input (); - return pathname; -} - -#endif /* !defined (HAVE_GETWD) || defined (BROKEN_GETWD) */ -#endif /* USG */ - /* Directory routines for systems that don't have them. */ #ifdef HAVE_DIRENT_H