www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000149

When Created: 05/13/1997 12:33:45
Against DJGPP version: 2.01
By whom: hberger@rzaix340.rz.uni-leipzig.de
Abstract: _rename removes file if newname=oldname (libc)
_rename() will remove the file, if newname=oldname. this function should
either report an error or don't touch the file at all.

Note added: 04/15/1999 11:00:23
By whom: eliz@is.elta.co.il
This problem doesn't happen on LFN systems (Windows 9X), because
the code in that case opens OLD and tries to remove it (actually it
tries to remove NEW, but they are the same) while OLD is still open.
And Windows 9X doesn't allow such crimes against humanity.

This is corrected in WIP and will be in v2.03.  Here's the patch:

*** src/libc/ansi/stdio/_rename.c.~1~     Sun Jul 12 18:29:22 1998        
--- src/libc/ansi/stdio/_rename.c Thu Apr 15 18:35:44 1999                
***************                                                                 
*** 7,12 ****                                                                   
--- 7,13 ----                                                                   
  #include <errno.h>                                                            
  #include <unistd.h>                                                           
  #include <fcntl.h>                                                            
+ #include <sys/stat.h>                                                         
  #include <io.h>                                                               
  #include <dos.h>                                                              
  #include <go32.h>                                                             
***************                                                                 
*** 19,28 ****                                                                  
    int olen    = strlen(old) + 1;                                              
    int i;                                                                      
    int use_lfn = _USE_LFN;                                                     
!   char tempfile[FILENAME_MAX];                                                
    const char *orig = old;                                                     
    int lfn_fd = -1;                                                            
                                                                                
    r.x.dx = __tb_offset;                                                       
    r.x.di = __tb_offset + olen;                                                
    r.x.ds = r.x.es = __tb_segment;                                             
--- 20,34 ----                                                                  
    int olen    = strlen(old) + 1;                                              
    int i;                                                                      
    int use_lfn = _USE_LFN;                                                     
!   char tempfile[FILENAME_MAX], tempfile1[FILENAME_MAX];                       
    const char *orig = old;                                                     
    int lfn_fd = -1;                                                            
                                                                                
+   /* If OLD and NEW are the same file, do nothing.  */                        
+   if (__file_exists(new)                                                      
+       && strcmp(_truename(old, tempfile), _truename(new, tempfile1)) == 0)    
+     return 0;                                                                 
+                                                                               
    r.x.dx = __tb_offset;                                                       
    r.x.di = __tb_offset + olen;                                                
    r.x.ds = r.x.es = __tb_segment;

Solution added: 04/22/1999 09:00:01
By whom: eliz@is.elta.co.il
Upgrade to v2.03 or apply the patch I put into my note.

Fixed in version on 04/22/1999 09:00:31
By whom: eliz@is.elta.co.il



  webmaster     delorie software   privacy  
  Copyright © 2010   by DJ Delorie     Updated Jul 2010