| Last change
 on this file since 2393 was             2, checked in by bird, 23 years ago | 
        
          | 
Initial revision
 | 
        
          | 
              
Property                 cvs2svn:cvs-rev
 set to                 1.1
Property                 svn:eol-style
 set to                 native
Property                 svn:executable
 set to                 * | 
        
          | File size:
            621 bytes | 
      
      
| Line |  | 
|---|
| 1 | /* rename -- rename a file | 
|---|
| 2 | This function is in the public domain. */ | 
|---|
| 3 |  | 
|---|
| 4 | /* | 
|---|
| 5 |  | 
|---|
| 6 | @deftypefn Supplemental int rename (const char *@var{old}, const char *@var{new}) | 
|---|
| 7 |  | 
|---|
| 8 | Renames a file from @var{old} to @var{new}.  If @var{new} already | 
|---|
| 9 | exists, it is removed. | 
|---|
| 10 |  | 
|---|
| 11 | @end deftypefn | 
|---|
| 12 |  | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | #ifdef HAVE_CONFIG_H | 
|---|
| 16 | #include "config.h" | 
|---|
| 17 | #endif | 
|---|
| 18 | #include <errno.h> | 
|---|
| 19 | #ifdef HAVE_UNISTD_H | 
|---|
| 20 | #include <unistd.h> | 
|---|
| 21 | #endif | 
|---|
| 22 |  | 
|---|
| 23 | int | 
|---|
| 24 | rename (zfrom, zto) | 
|---|
| 25 | char *zfrom; | 
|---|
| 26 | char *zto; | 
|---|
| 27 | { | 
|---|
| 28 | if (link (zfrom, zto) < 0) | 
|---|
| 29 | { | 
|---|
| 30 | if (errno != EEXIST) | 
|---|
| 31 | return -1; | 
|---|
| 32 | if (unlink (zto) < 0 | 
|---|
| 33 | || link (zfrom, zto) < 0) | 
|---|
| 34 | return -1; | 
|---|
| 35 | } | 
|---|
| 36 | return unlink (zfrom); | 
|---|
| 37 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.