root/trunk/texinfo/texinfo-4.8a-tempfile_fix-1.patch

Revision 1685, 2.2 kB (checked in by matthew, 2 years ago)

Add patches for the latest version of Texinfo

  • texinfo-4.8/util/texindex.c

    old new  
    9999/* Directory to use for temporary files.  On Unix, it ends with a slash.  */ 
    100100char *tempdir; 
    101101 
     102/* Basename for temp files inside of tempdir.  */ 
     103char *tempbase; 
     104 
    102105/* Number of last temporary file.  */ 
    103106int tempcount; 
    104107 
     
    153156main (int argc, char **argv) 
    154157{ 
    155158  int i; 
     159  char template[]="txidxXXXXXX"; 
    156160 
    157161  tempcount = 0; 
    158162  last_deleted_tempcount = 0; 
     
    190194 
    191195  decode_command (argc, argv); 
    192196 
     197  /* XXX mkstemp not appropriate, as we need to have somewhat predictable 
     198   * names. But race condition was fixed, see maketempname.  
     199   */ 
     200  tempbase = mktemp (template); 
     201 
    193202  /* Process input files completely, one by one.  */ 
    194203 
    195204  for (i = 0; i < num_infiles; i++) 
     
    389398static char * 
    390399maketempname (int count) 
    391400{ 
    392   static char *tempbase = NULL; 
    393401  char tempsuffix[10]; 
    394  
    395   if (!tempbase) 
    396     { 
    397       int fd; 
    398       tempbase = concat (tempdir, "txidxXXXXXX"); 
    399  
    400       fd = mkstemp (tempbase); 
    401       if (fd == -1) 
    402         pfatal_with_name (tempbase); 
    403     } 
     402  char *name, *tmp_name; 
     403  int fd; 
    404404 
    405405  sprintf (tempsuffix, ".%d", count); 
    406   return concat (tempbase, tempsuffix); 
     406  tmp_name = concat (tempdir, tempbase); 
     407  name = concat (tmp_name, tempsuffix); 
     408  free(tmp_name); 
     409 
     410  fd = open (name, O_CREAT|O_EXCL|O_WRONLY, 0600); 
     411  if (fd == -1) 
     412    pfatal_with_name (name); 
     413 
     414  close(fd); 
     415  return name; 
    407416} 
    408417 
    409418 
Note: See TracBrowser for help on using the browser.