Karsten Hopp 2490e8
To: vim-dev@vim.org
Karsten Hopp 2490e8
Subject: Patch 7.2.294
Karsten Hopp 2490e8
Fcc: outbox
Karsten Hopp 2490e8
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 2490e8
Mime-Version: 1.0
Karsten Hopp 2490e8
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 2490e8
Content-Transfer-Encoding: 8bit
Karsten Hopp 2490e8
------------
Karsten Hopp 2490e8
Karsten Hopp 2490e8
Patch 7.2.294
Karsten Hopp 2490e8
Problem:    When using TEMPDIRS dir name could get too long.
Karsten Hopp 2490e8
Solution:   Overwrite tail instead of appending each time.  Use mkdtemp() when
Karsten Hopp 2490e8
	    available. (James Vega)
Karsten Hopp 2490e8
Files:	    src/auto/configure, src/config.h.in, src/configure.in, src/fileio.c
Karsten Hopp 2490e8
Karsten Hopp 2490e8
Karsten Hopp 2490e8
*** ../vim-7.2.293/src/auto/configure	2009-09-11 13:44:33.000000000 +0200
Karsten Hopp 2490e8
--- src/auto/configure	2009-11-17 12:03:15.000000000 +0100
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 14019,14027 ****
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
  for ac_func in bcmp fchdir fchown fseeko fsync ftello getcwd getpseudotty \
Karsten Hopp 2490e8
  	getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
Karsten Hopp 2490e8
! 	memset nanosleep opendir putenv qsort readlink select setenv \
Karsten Hopp 2490e8
  	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
Karsten Hopp 2490e8
  	sigvec strcasecmp strerror strftime stricmp strncasecmp \
Karsten Hopp 2490e8
  	strnicmp strpbrk strtol tgetent towlower towupper iswupper \
Karsten Hopp 2490e8
--- 14019,14028 ----
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
+ 
Karsten Hopp 2490e8
  for ac_func in bcmp fchdir fchown fseeko fsync ftello getcwd getpseudotty \
Karsten Hopp 2490e8
  	getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
Karsten Hopp 2490e8
! 	memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
Karsten Hopp 2490e8
  	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
Karsten Hopp 2490e8
  	sigvec strcasecmp strerror strftime stricmp strncasecmp \
Karsten Hopp 2490e8
  	strnicmp strpbrk strtol tgetent towlower towupper iswupper \
Karsten Hopp 2490e8
*** ../vim-7.2.293/src/config.h.in	2009-05-21 23:25:38.000000000 +0200
Karsten Hopp 2490e8
--- src/config.h.in	2009-11-11 17:40:21.000000000 +0100
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 157,162 ****
Karsten Hopp 2490e8
--- 157,163 ----
Karsten Hopp 2490e8
  #undef HAVE_LSTAT
Karsten Hopp 2490e8
  #undef HAVE_MEMCMP
Karsten Hopp 2490e8
  #undef HAVE_MEMSET
Karsten Hopp 2490e8
+ #undef HAVE_MKDTEMP
Karsten Hopp 2490e8
  #undef HAVE_NANOSLEEP
Karsten Hopp 2490e8
  #undef HAVE_OPENDIR
Karsten Hopp 2490e8
  #undef HAVE_FLOAT_FUNCS
Karsten Hopp 2490e8
*** ../vim-7.2.293/src/configure.in	2009-09-11 13:44:33.000000000 +0200
Karsten Hopp 2490e8
--- src/configure.in	2009-11-11 17:40:21.000000000 +0100
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 2635,2641 ****
Karsten Hopp 2490e8
  dnl Check for functions in one big call, to reduce the size of configure
Karsten Hopp 2490e8
  AC_CHECK_FUNCS(bcmp fchdir fchown fseeko fsync ftello getcwd getpseudotty \
Karsten Hopp 2490e8
  	getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
Karsten Hopp 2490e8
! 	memset nanosleep opendir putenv qsort readlink select setenv \
Karsten Hopp 2490e8
  	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
Karsten Hopp 2490e8
  	sigvec strcasecmp strerror strftime stricmp strncasecmp \
Karsten Hopp 2490e8
  	strnicmp strpbrk strtol tgetent towlower towupper iswupper \
Karsten Hopp 2490e8
--- 2635,2641 ----
Karsten Hopp 2490e8
  dnl Check for functions in one big call, to reduce the size of configure
Karsten Hopp 2490e8
  AC_CHECK_FUNCS(bcmp fchdir fchown fseeko fsync ftello getcwd getpseudotty \
Karsten Hopp 2490e8
  	getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
Karsten Hopp 2490e8
! 	memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
Karsten Hopp 2490e8
  	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
Karsten Hopp 2490e8
  	sigvec strcasecmp strerror strftime stricmp strncasecmp \
Karsten Hopp 2490e8
  	strnicmp strpbrk strtol tgetent towlower towupper iswupper \
Karsten Hopp 2490e8
*** ../vim-7.2.293/src/fileio.c	2009-09-11 17:24:01.000000000 +0200
Karsten Hopp 2490e8
--- src/fileio.c	2009-11-11 18:01:22.000000000 +0100
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 146,151 ****
Karsten Hopp 2490e8
--- 146,152 ----
Karsten Hopp 2490e8
  # endif
Karsten Hopp 2490e8
  #endif
Karsten Hopp 2490e8
  static int move_lines __ARGS((buf_T *frombuf, buf_T *tobuf));
Karsten Hopp 2490e8
+ static void vim_settempdir __ARGS((char_u *tempdir));
Karsten Hopp 2490e8
  #ifdef FEAT_AUTOCMD
Karsten Hopp 2490e8
  static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name");
Karsten Hopp 2490e8
  #endif
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 6987,6992 ****
Karsten Hopp 2490e8
--- 6988,7020 ----
Karsten Hopp 2490e8
  #endif
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
  /*
Karsten Hopp 2490e8
+  * Directory "tempdir" was created.  Expand this name to a full path and put
Karsten Hopp 2490e8
+  * it in "vim_tempdir".  This avoids that using ":cd" would confuse us.
Karsten Hopp 2490e8
+  * "tempdir" must be no longer than MAXPATHL.
Karsten Hopp 2490e8
+  */
Karsten Hopp 2490e8
+     static void
Karsten Hopp 2490e8
+ vim_settempdir(tempdir)
Karsten Hopp 2490e8
+     char_u	*tempdir;
Karsten Hopp 2490e8
+ {
Karsten Hopp 2490e8
+     char_u	*buf;
Karsten Hopp 2490e8
+ 
Karsten Hopp 2490e8
+     buf = alloc((unsigned)MAXPATHL + 2);
Karsten Hopp 2490e8
+     if (buf != NULL)
Karsten Hopp 2490e8
+     {
Karsten Hopp 2490e8
+ 	if (vim_FullName(tempdir, buf, MAXPATHL, FALSE) == FAIL)
Karsten Hopp 2490e8
+ 	    STRCPY(buf, tempdir);
Karsten Hopp 2490e8
+ # ifdef __EMX__
Karsten Hopp 2490e8
+ 	if (vim_strchr(buf, '/') != NULL)
Karsten Hopp 2490e8
+ 	    STRCAT(buf, "/");
Karsten Hopp 2490e8
+ 	else
Karsten Hopp 2490e8
+ # endif
Karsten Hopp 2490e8
+ 	    add_pathsep(buf);
Karsten Hopp 2490e8
+ 	vim_tempdir = vim_strsave(buf);
Karsten Hopp 2490e8
+ 	vim_free(buf);
Karsten Hopp 2490e8
+     }
Karsten Hopp 2490e8
+ }
Karsten Hopp 2490e8
+ 
Karsten Hopp 2490e8
+ /*
Karsten Hopp 2490e8
   * vim_tempname(): Return a unique name that can be used for a temp file.
Karsten Hopp 2490e8
   *
Karsten Hopp 2490e8
   * The temp file is NOT created.
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 7007,7014 ****
Karsten Hopp 2490e8
  #ifdef TEMPDIRNAMES
Karsten Hopp 2490e8
      static char	*(tempdirs[]) = {TEMPDIRNAMES};
Karsten Hopp 2490e8
      int		i;
Karsten Hopp 2490e8
-     long	nr;
Karsten Hopp 2490e8
-     long	off;
Karsten Hopp 2490e8
  # ifndef EEXIST
Karsten Hopp 2490e8
      struct stat	st;
Karsten Hopp 2490e8
  # endif
Karsten Hopp 2490e8
--- 7035,7040 ----
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 7027,7032 ****
Karsten Hopp 2490e8
--- 7053,7064 ----
Karsten Hopp 2490e8
  	 */
Karsten Hopp 2490e8
  	for (i = 0; i < (int)(sizeof(tempdirs) / sizeof(char *)); ++i)
Karsten Hopp 2490e8
  	{
Karsten Hopp 2490e8
+ 	    size_t	itmplen;
Karsten Hopp 2490e8
+ # ifndef HAVE_MKDTEMP
Karsten Hopp 2490e8
+ 	    long	nr;
Karsten Hopp 2490e8
+ 	    long	off;
Karsten Hopp 2490e8
+ # endif
Karsten Hopp 2490e8
+ 
Karsten Hopp 2490e8
  	    /* expand $TMP, leave room for "/v1100000/999999999" */
Karsten Hopp 2490e8
  	    expand_env((char_u *)tempdirs[i], itmp, TEMPNAMELEN - 20);
Karsten Hopp 2490e8
  	    if (mch_isdir(itmp))		/* directory exists */
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 7040,7046 ****
Karsten Hopp 2490e8
--- 7072,7085 ----
Karsten Hopp 2490e8
  		else
Karsten Hopp 2490e8
  # endif
Karsten Hopp 2490e8
  		    add_pathsep(itmp);
Karsten Hopp 2490e8
+ 		itmplen = STRLEN(itmp);
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
+ # ifdef HAVE_MKDTEMP
Karsten Hopp 2490e8
+ 		/* Leave room for filename */
Karsten Hopp 2490e8
+ 		STRCAT(itmp, "vXXXXXX");
Karsten Hopp 2490e8
+ 		if (mkdtemp((char *)itmp) != NULL)
Karsten Hopp 2490e8
+ 		    vim_settempdir(itmp);
Karsten Hopp 2490e8
+ # else
Karsten Hopp 2490e8
  		/* Get an arbitrary number of up to 6 digits.  When it's
Karsten Hopp 2490e8
  		 * unlikely that it already exists it will be faster,
Karsten Hopp 2490e8
  		 * otherwise it doesn't matter.  The use of mkdir() avoids any
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 7052,7110 ****
Karsten Hopp 2490e8
  		for (off = 0; off < 10000L; ++off)
Karsten Hopp 2490e8
  		{
Karsten Hopp 2490e8
  		    int		r;
Karsten Hopp 2490e8
! #if defined(UNIX) || defined(VMS)
Karsten Hopp 2490e8
  		    mode_t	umask_save;
Karsten Hopp 2490e8
! #endif
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
! 		    sprintf((char *)itmp + STRLEN(itmp), "v%ld", nr + off);
Karsten Hopp 2490e8
! # ifndef EEXIST
Karsten Hopp 2490e8
  		    /* If mkdir() does not set errno to EEXIST, check for
Karsten Hopp 2490e8
  		     * existing file here.  There is a race condition then,
Karsten Hopp 2490e8
  		     * although it's fail-safe. */
Karsten Hopp 2490e8
  		    if (mch_stat((char *)itmp, &st) >= 0)
Karsten Hopp 2490e8
  			continue;
Karsten Hopp 2490e8
! # endif
Karsten Hopp 2490e8
! #if defined(UNIX) || defined(VMS)
Karsten Hopp 2490e8
  		    /* Make sure the umask doesn't remove the executable bit.
Karsten Hopp 2490e8
  		     * "repl" has been reported to use "177". */
Karsten Hopp 2490e8
  		    umask_save = umask(077);
Karsten Hopp 2490e8
! #endif
Karsten Hopp 2490e8
  		    r = vim_mkdir(itmp, 0700);
Karsten Hopp 2490e8
! #if defined(UNIX) || defined(VMS)
Karsten Hopp 2490e8
  		    (void)umask(umask_save);
Karsten Hopp 2490e8
! #endif
Karsten Hopp 2490e8
  		    if (r == 0)
Karsten Hopp 2490e8
  		    {
Karsten Hopp 2490e8
! 			char_u	*buf;
Karsten Hopp 2490e8
! 
Karsten Hopp 2490e8
! 			/* Directory was created, use this name.
Karsten Hopp 2490e8
! 			 * Expand to full path; When using the current
Karsten Hopp 2490e8
! 			 * directory a ":cd" would confuse us. */
Karsten Hopp 2490e8
! 			buf = alloc((unsigned)MAXPATHL + 1);
Karsten Hopp 2490e8
! 			if (buf != NULL)
Karsten Hopp 2490e8
! 			{
Karsten Hopp 2490e8
! 			    if (vim_FullName(itmp, buf, MAXPATHL, FALSE)
Karsten Hopp 2490e8
! 								      == FAIL)
Karsten Hopp 2490e8
! 				STRCPY(buf, itmp);
Karsten Hopp 2490e8
! # ifdef __EMX__
Karsten Hopp 2490e8
! 			    if (vim_strchr(buf, '/') != NULL)
Karsten Hopp 2490e8
! 				STRCAT(buf, "/");
Karsten Hopp 2490e8
! 			    else
Karsten Hopp 2490e8
! # endif
Karsten Hopp 2490e8
! 				add_pathsep(buf);
Karsten Hopp 2490e8
! 			    vim_tempdir = vim_strsave(buf);
Karsten Hopp 2490e8
! 			    vim_free(buf);
Karsten Hopp 2490e8
! 			}
Karsten Hopp 2490e8
  			break;
Karsten Hopp 2490e8
  		    }
Karsten Hopp 2490e8
! # ifdef EEXIST
Karsten Hopp 2490e8
  		    /* If the mkdir() didn't fail because the file/dir exists,
Karsten Hopp 2490e8
  		     * we probably can't create any dir here, try another
Karsten Hopp 2490e8
  		     * place. */
Karsten Hopp 2490e8
  		    if (errno != EEXIST)
Karsten Hopp 2490e8
! # endif
Karsten Hopp 2490e8
  			break;
Karsten Hopp 2490e8
  		}
Karsten Hopp 2490e8
  		if (vim_tempdir != NULL)
Karsten Hopp 2490e8
  		    break;
Karsten Hopp 2490e8
  	    }
Karsten Hopp 2490e8
--- 7091,7131 ----
Karsten Hopp 2490e8
  		for (off = 0; off < 10000L; ++off)
Karsten Hopp 2490e8
  		{
Karsten Hopp 2490e8
  		    int		r;
Karsten Hopp 2490e8
! #  if defined(UNIX) || defined(VMS)
Karsten Hopp 2490e8
  		    mode_t	umask_save;
Karsten Hopp 2490e8
! #  endif
Karsten Hopp 2490e8
  
Karsten Hopp 2490e8
! 		    sprintf((char *)itmp + itmplen, "v%ld", nr + off);
Karsten Hopp 2490e8
! #  ifndef EEXIST
Karsten Hopp 2490e8
  		    /* If mkdir() does not set errno to EEXIST, check for
Karsten Hopp 2490e8
  		     * existing file here.  There is a race condition then,
Karsten Hopp 2490e8
  		     * although it's fail-safe. */
Karsten Hopp 2490e8
  		    if (mch_stat((char *)itmp, &st) >= 0)
Karsten Hopp 2490e8
  			continue;
Karsten Hopp 2490e8
! #  endif
Karsten Hopp 2490e8
! #  if defined(UNIX) || defined(VMS)
Karsten Hopp 2490e8
  		    /* Make sure the umask doesn't remove the executable bit.
Karsten Hopp 2490e8
  		     * "repl" has been reported to use "177". */
Karsten Hopp 2490e8
  		    umask_save = umask(077);
Karsten Hopp 2490e8
! #  endif
Karsten Hopp 2490e8
  		    r = vim_mkdir(itmp, 0700);
Karsten Hopp 2490e8
! #  if defined(UNIX) || defined(VMS)
Karsten Hopp 2490e8
  		    (void)umask(umask_save);
Karsten Hopp 2490e8
! #  endif
Karsten Hopp 2490e8
  		    if (r == 0)
Karsten Hopp 2490e8
  		    {
Karsten Hopp 2490e8
! 			vim_settempdir(itmp);
Karsten Hopp 2490e8
  			break;
Karsten Hopp 2490e8
  		    }
Karsten Hopp 2490e8
! #  ifdef EEXIST
Karsten Hopp 2490e8
  		    /* If the mkdir() didn't fail because the file/dir exists,
Karsten Hopp 2490e8
  		     * we probably can't create any dir here, try another
Karsten Hopp 2490e8
  		     * place. */
Karsten Hopp 2490e8
  		    if (errno != EEXIST)
Karsten Hopp 2490e8
! #  endif
Karsten Hopp 2490e8
  			break;
Karsten Hopp 2490e8
  		}
Karsten Hopp 2490e8
+ # endif /* HAVE_MKDTEMP */
Karsten Hopp 2490e8
  		if (vim_tempdir != NULL)
Karsten Hopp 2490e8
  		    break;
Karsten Hopp 2490e8
  	    }
Karsten Hopp 2490e8
*** ../vim-7.2.293/src/version.c	2009-11-11 17:30:05.000000000 +0100
Karsten Hopp 2490e8
--- src/version.c	2009-11-17 11:54:49.000000000 +0100
Karsten Hopp 2490e8
***************
Karsten Hopp 2490e8
*** 683,684 ****
Karsten Hopp 2490e8
--- 683,686 ----
Karsten Hopp 2490e8
  {   /* Add new patch number below this line */
Karsten Hopp 2490e8
+ /**/
Karsten Hopp 2490e8
+     294,
Karsten Hopp 2490e8
  /**/
Karsten Hopp 2490e8
Karsten Hopp 2490e8
-- 
Karsten Hopp 2490e8
ARTHUR:       Now stand aside worthy adversary.
Karsten Hopp 2490e8
BLACK KNIGHT: (Glancing at his shoulder) 'Tis but a scratch.
Karsten Hopp 2490e8
ARTHUR:       A scratch?  Your arm's off.
Karsten Hopp 2490e8
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 2490e8
Karsten Hopp 2490e8
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 2490e8
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 2490e8
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 2490e8
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///