99b86a7
To: vim-dev@vim.org
99b86a7
Subject: patch 7.1.027
99b86a7
Fcc: outbox
99b86a7
From: Bram Moolenaar <Bram@moolenaar.net>
99b86a7
Mime-Version: 1.0
99b86a7
Content-Type: text/plain; charset=ISO-8859-1
99b86a7
Content-Transfer-Encoding: 8bit
99b86a7
------------
99b86a7
99b86a7
Patch 7.1.027
99b86a7
Problem:    On Sun systems opening /dev/fd/N doesn't work, and they are used
99b86a7
	    by process substitutions.
99b86a7
Solution:   Allow opening specific character special files for Sun systems.
99b86a7
	    (Gary Johnson)
99b86a7
Files:	    src/fileio.c, src/os_unix.h
99b86a7
99b86a7
99b86a7
*** ../vim-7.1.026/src/fileio.c	Thu Jun 28 21:57:08 2007
99b86a7
--- src/fileio.c	Mon Jul  9 11:19:50 2007
99b86a7
***************
99b86a7
*** 44,49 ****
99b86a7
--- 44,53 ----
99b86a7
  /* Is there any system that doesn't have access()? */
99b86a7
  #define USE_MCH_ACCESS
99b86a7
  
99b86a7
+ #if defined(sun) && defined(S_ISCHR)
99b86a7
+ # define OPEN_CHR_FILES
99b86a7
+ static int is_dev_fd_file(char_u *fname);
99b86a7
+ #endif
99b86a7
  #ifdef FEAT_MBYTE
99b86a7
  static char_u *next_fenc __ARGS((char_u **pp));
99b86a7
  # ifdef FEAT_EVAL
99b86a7
***************
99b86a7
*** 406,411 ****
99b86a7
--- 410,419 ----
99b86a7
  # ifdef S_ISSOCK
99b86a7
  		      && !S_ISSOCK(perm)	    /* ... or socket */
99b86a7
  # endif
99b86a7
+ # ifdef OPEN_CHR_FILES
99b86a7
+ 		      && !(S_ISCHR(perm) && is_dev_fd_file(fname))
99b86a7
+ 			/* ... or a character special file named /dev/fd/<n> */
99b86a7
+ # endif
99b86a7
  						)
99b86a7
  	{
99b86a7
  	    if (S_ISDIR(perm))
99b86a7
***************
99b86a7
*** 2265,2270 ****
99b86a7
--- 2273,2285 ----
99b86a7
  	    }
99b86a7
  #  endif
99b86a7
  # endif
99b86a7
+ # ifdef OPEN_CHR_FILES
99b86a7
+ 	    if (S_ISCHR(perm))			    /* or character special */
99b86a7
+ 	    {
99b86a7
+ 		STRCAT(IObuff, _("[character special]"));
99b86a7
+ 		c = TRUE;
99b86a7
+ 	    }
99b86a7
+ # endif
99b86a7
  #endif
99b86a7
  	    if (curbuf->b_p_ro)
99b86a7
  	    {
99b86a7
***************
99b86a7
*** 2463,2468 ****
99b86a7
--- 2478,2502 ----
99b86a7
  	return FAIL;
99b86a7
      return OK;
99b86a7
  }
99b86a7
+ 
99b86a7
+ #ifdef OPEN_CHR_FILES
99b86a7
+ /*
99b86a7
+  * Returns TRUE if the file name argument is of the form "/dev/fd/\d\+",
99b86a7
+  * which is the name of files used for process substitution output by
99b86a7
+  * some shells on some operating systems, e.g., bash on SunOS.
99b86a7
+  * Do not accept "/dev/fd/[012]", opening these may hang Vim.
99b86a7
+  */
99b86a7
+     static int
99b86a7
+ is_dev_fd_file(fname)
99b86a7
+     char_u	*fname;
99b86a7
+ {
99b86a7
+     return (STRNCMP(fname, "/dev/fd/", 8) == 0
99b86a7
+ 	    && VIM_ISDIGIT(fname[8])
99b86a7
+ 	    && *skipdigits(fname + 9) == NUL
99b86a7
+ 	    && (fname[9] != NUL
99b86a7
+ 		|| (fname[8] != '0' && fname[8] != '1' && fname[8] != '2')));
99b86a7
+ }
99b86a7
+ #endif
99b86a7
  
99b86a7
  #ifdef FEAT_MBYTE
99b86a7
  
99b86a7
*** ../vim-7.1.026/src/os_unix.h	Thu May 10 19:43:10 2007
99b86a7
--- src/os_unix.h	Sat Jul  7 13:08:56 2007
99b86a7
***************
99b86a7
*** 508,513 ****
99b86a7
--- 508,516 ----
99b86a7
  #if !defined(S_ISFIFO) && defined(S_IFIFO)
99b86a7
  # define	S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
99b86a7
  #endif
99b86a7
+ #if !defined(S_ISCHR) && defined(S_IFCHR)
99b86a7
+ # define	S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
99b86a7
+ #endif
99b86a7
  
99b86a7
  /* Note: Some systems need both string.h and strings.h (Savage).  However,
99b86a7
   * some systems can't handle both, only use string.h in that case. */
99b86a7
*** ../vim-7.1.026/src/version.c	Tue Jul 10 14:02:51 2007
99b86a7
--- src/version.c	Tue Jul 10 17:00:43 2007
99b86a7
***************
99b86a7
*** 668,669 ****
99b86a7
--- 668,671 ----
99b86a7
  {   /* Add new patch number below this line */
99b86a7
+ /**/
99b86a7
+     27,
99b86a7
  /**/
99b86a7
99b86a7
-- 
99b86a7
Every exit is an entrance into something else.
99b86a7
99b86a7
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
99b86a7
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
99b86a7
\\\        download, build and distribute -- http://www.A-A-P.org        ///
99b86a7
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///