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