home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.2 / 7.2.294 < prev    next >
Encoding:
Internet Message Format  |  2009-11-16  |  8.8 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.2.294
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.2.294
  11. Problem:    When using TEMPDIRS dir name could get too long.
  12. Solution:   Overwrite tail instead of appending each time.  Use mkdtemp() when
  13.         available. (James Vega)
  14. Files:        src/auto/configure, src/config.h.in, src/configure.in, src/fileio.c
  15.  
  16.  
  17. *** ../vim-7.2.293/src/auto/configure    2009-09-11 13:44:33.000000000 +0200
  18. --- src/auto/configure    2009-11-17 12:03:15.000000000 +0100
  19. ***************
  20. *** 14019,14027 ****
  21.   
  22.   
  23.   
  24.   for ac_func in bcmp fchdir fchown fseeko fsync ftello getcwd getpseudotty \
  25.       getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
  26. !     memset nanosleep opendir putenv qsort readlink select setenv \
  27.       setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
  28.       sigvec strcasecmp strerror strftime stricmp strncasecmp \
  29.       strnicmp strpbrk strtol tgetent towlower towupper iswupper \
  30. --- 14019,14028 ----
  31.   
  32.   
  33.   
  34.   for ac_func in bcmp fchdir fchown fseeko fsync ftello getcwd getpseudotty \
  35.       getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
  36. !     memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
  37.       setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
  38.       sigvec strcasecmp strerror strftime stricmp strncasecmp \
  39.       strnicmp strpbrk strtol tgetent towlower towupper iswupper \
  40. *** ../vim-7.2.293/src/config.h.in    2009-05-21 23:25:38.000000000 +0200
  41. --- src/config.h.in    2009-11-11 17:40:21.000000000 +0100
  42. ***************
  43. *** 157,162 ****
  44. --- 157,163 ----
  45.   #undef HAVE_LSTAT
  46.   #undef HAVE_MEMCMP
  47.   #undef HAVE_MEMSET
  48. + #undef HAVE_MKDTEMP
  49.   #undef HAVE_NANOSLEEP
  50.   #undef HAVE_OPENDIR
  51.   #undef HAVE_FLOAT_FUNCS
  52. *** ../vim-7.2.293/src/configure.in    2009-09-11 13:44:33.000000000 +0200
  53. --- src/configure.in    2009-11-11 17:40:21.000000000 +0100
  54. ***************
  55. *** 2635,2641 ****
  56.   dnl Check for functions in one big call, to reduce the size of configure
  57.   AC_CHECK_FUNCS(bcmp fchdir fchown fseeko fsync ftello getcwd getpseudotty \
  58.       getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
  59. !     memset nanosleep opendir putenv qsort readlink select setenv \
  60.       setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
  61.       sigvec strcasecmp strerror strftime stricmp strncasecmp \
  62.       strnicmp strpbrk strtol tgetent towlower towupper iswupper \
  63. --- 2635,2641 ----
  64.   dnl Check for functions in one big call, to reduce the size of configure
  65.   AC_CHECK_FUNCS(bcmp fchdir fchown fseeko fsync ftello getcwd getpseudotty \
  66.       getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
  67. !     memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
  68.       setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
  69.       sigvec strcasecmp strerror strftime stricmp strncasecmp \
  70.       strnicmp strpbrk strtol tgetent towlower towupper iswupper \
  71. *** ../vim-7.2.293/src/fileio.c    2009-09-11 17:24:01.000000000 +0200
  72. --- src/fileio.c    2009-11-11 18:01:22.000000000 +0100
  73. ***************
  74. *** 146,151 ****
  75. --- 146,152 ----
  76.   # endif
  77.   #endif
  78.   static int move_lines __ARGS((buf_T *frombuf, buf_T *tobuf));
  79. + static void vim_settempdir __ARGS((char_u *tempdir));
  80.   #ifdef FEAT_AUTOCMD
  81.   static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name");
  82.   #endif
  83. ***************
  84. *** 6987,6992 ****
  85. --- 6988,7020 ----
  86.   #endif
  87.   
  88.   /*
  89. +  * Directory "tempdir" was created.  Expand this name to a full path and put
  90. +  * it in "vim_tempdir".  This avoids that using ":cd" would confuse us.
  91. +  * "tempdir" must be no longer than MAXPATHL.
  92. +  */
  93. +     static void
  94. + vim_settempdir(tempdir)
  95. +     char_u    *tempdir;
  96. + {
  97. +     char_u    *buf;
  98. +     buf = alloc((unsigned)MAXPATHL + 2);
  99. +     if (buf != NULL)
  100. +     {
  101. +     if (vim_FullName(tempdir, buf, MAXPATHL, FALSE) == FAIL)
  102. +         STRCPY(buf, tempdir);
  103. + # ifdef __EMX__
  104. +     if (vim_strchr(buf, '/') != NULL)
  105. +         STRCAT(buf, "/");
  106. +     else
  107. + # endif
  108. +         add_pathsep(buf);
  109. +     vim_tempdir = vim_strsave(buf);
  110. +     vim_free(buf);
  111. +     }
  112. + }
  113. + /*
  114.    * vim_tempname(): Return a unique name that can be used for a temp file.
  115.    *
  116.    * The temp file is NOT created.
  117. ***************
  118. *** 7007,7014 ****
  119.   #ifdef TEMPDIRNAMES
  120.       static char    *(tempdirs[]) = {TEMPDIRNAMES};
  121.       int        i;
  122. -     long    nr;
  123. -     long    off;
  124.   # ifndef EEXIST
  125.       struct stat    st;
  126.   # endif
  127. --- 7035,7040 ----
  128. ***************
  129. *** 7027,7032 ****
  130. --- 7053,7064 ----
  131.        */
  132.       for (i = 0; i < (int)(sizeof(tempdirs) / sizeof(char *)); ++i)
  133.       {
  134. +         size_t    itmplen;
  135. + # ifndef HAVE_MKDTEMP
  136. +         long    nr;
  137. +         long    off;
  138. + # endif
  139.           /* expand $TMP, leave room for "/v1100000/999999999" */
  140.           expand_env((char_u *)tempdirs[i], itmp, TEMPNAMELEN - 20);
  141.           if (mch_isdir(itmp))        /* directory exists */
  142. ***************
  143. *** 7040,7046 ****
  144. --- 7072,7085 ----
  145.           else
  146.   # endif
  147.               add_pathsep(itmp);
  148. +         itmplen = STRLEN(itmp);
  149.   
  150. + # ifdef HAVE_MKDTEMP
  151. +         /* Leave room for filename */
  152. +         STRCAT(itmp, "vXXXXXX");
  153. +         if (mkdtemp((char *)itmp) != NULL)
  154. +             vim_settempdir(itmp);
  155. + # else
  156.           /* Get an arbitrary number of up to 6 digits.  When it's
  157.            * unlikely that it already exists it will be faster,
  158.            * otherwise it doesn't matter.  The use of mkdir() avoids any
  159. ***************
  160. *** 7052,7110 ****
  161.           for (off = 0; off < 10000L; ++off)
  162.           {
  163.               int        r;
  164. ! #if defined(UNIX) || defined(VMS)
  165.               mode_t    umask_save;
  166. ! #endif
  167.   
  168. !             sprintf((char *)itmp + STRLEN(itmp), "v%ld", nr + off);
  169. ! # ifndef EEXIST
  170.               /* If mkdir() does not set errno to EEXIST, check for
  171.                * existing file here.  There is a race condition then,
  172.                * although it's fail-safe. */
  173.               if (mch_stat((char *)itmp, &st) >= 0)
  174.               continue;
  175. ! # endif
  176. ! #if defined(UNIX) || defined(VMS)
  177.               /* Make sure the umask doesn't remove the executable bit.
  178.                * "repl" has been reported to use "177". */
  179.               umask_save = umask(077);
  180. ! #endif
  181.               r = vim_mkdir(itmp, 0700);
  182. ! #if defined(UNIX) || defined(VMS)
  183.               (void)umask(umask_save);
  184. ! #endif
  185.               if (r == 0)
  186.               {
  187. !             char_u    *buf;
  188. !             /* Directory was created, use this name.
  189. !              * Expand to full path; When using the current
  190. !              * directory a ":cd" would confuse us. */
  191. !             buf = alloc((unsigned)MAXPATHL + 1);
  192. !             if (buf != NULL)
  193. !             {
  194. !                 if (vim_FullName(itmp, buf, MAXPATHL, FALSE)
  195. !                                       == FAIL)
  196. !                 STRCPY(buf, itmp);
  197. ! # ifdef __EMX__
  198. !                 if (vim_strchr(buf, '/') != NULL)
  199. !                 STRCAT(buf, "/");
  200. !                 else
  201. ! # endif
  202. !                 add_pathsep(buf);
  203. !                 vim_tempdir = vim_strsave(buf);
  204. !                 vim_free(buf);
  205. !             }
  206.               break;
  207.               }
  208. ! # ifdef EEXIST
  209.               /* If the mkdir() didn't fail because the file/dir exists,
  210.                * we probably can't create any dir here, try another
  211.                * place. */
  212.               if (errno != EEXIST)
  213. ! # endif
  214.               break;
  215.           }
  216.           if (vim_tempdir != NULL)
  217.               break;
  218.           }
  219. --- 7091,7131 ----
  220.           for (off = 0; off < 10000L; ++off)
  221.           {
  222.               int        r;
  223. ! #  if defined(UNIX) || defined(VMS)
  224.               mode_t    umask_save;
  225. ! #  endif
  226.   
  227. !             sprintf((char *)itmp + itmplen, "v%ld", nr + off);
  228. ! #  ifndef EEXIST
  229.               /* If mkdir() does not set errno to EEXIST, check for
  230.                * existing file here.  There is a race condition then,
  231.                * although it's fail-safe. */
  232.               if (mch_stat((char *)itmp, &st) >= 0)
  233.               continue;
  234. ! #  endif
  235. ! #  if defined(UNIX) || defined(VMS)
  236.               /* Make sure the umask doesn't remove the executable bit.
  237.                * "repl" has been reported to use "177". */
  238.               umask_save = umask(077);
  239. ! #  endif
  240.               r = vim_mkdir(itmp, 0700);
  241. ! #  if defined(UNIX) || defined(VMS)
  242.               (void)umask(umask_save);
  243. ! #  endif
  244.               if (r == 0)
  245.               {
  246. !             vim_settempdir(itmp);
  247.               break;
  248.               }
  249. ! #  ifdef EEXIST
  250.               /* If the mkdir() didn't fail because the file/dir exists,
  251.                * we probably can't create any dir here, try another
  252.                * place. */
  253.               if (errno != EEXIST)
  254. ! #  endif
  255.               break;
  256.           }
  257. + # endif /* HAVE_MKDTEMP */
  258.           if (vim_tempdir != NULL)
  259.               break;
  260.           }
  261. *** ../vim-7.2.293/src/version.c    2009-11-11 17:30:05.000000000 +0100
  262. --- src/version.c    2009-11-17 11:54:49.000000000 +0100
  263. ***************
  264. *** 683,684 ****
  265. --- 683,686 ----
  266.   {   /* Add new patch number below this line */
  267. + /**/
  268. +     294,
  269.   /**/
  270.  
  271. -- 
  272. ARTHUR:       Now stand aside worthy adversary.
  273. BLACK KNIGHT: (Glancing at his shoulder) 'Tis but a scratch.
  274. ARTHUR:       A scratch?  Your arm's off.
  275.                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
  276.  
  277.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  278. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  279. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  280.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  281.