home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / uucp-1.04 / unix / rename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-13  |  501 b   |  28 lines

  1. /* rename.c
  2.    Rename a file to a new name (Unix specific implementation).  */
  3.  
  4. #include "uucp.h"
  5.  
  6. #include "sysdep.h"
  7.  
  8. #include <errno.h>
  9.  
  10. /* This implementation will not work on directories, but fortunately
  11.    we never want to rename directories.  */
  12.  
  13. int
  14. rename (zfrom, zto)
  15.      const char *zfrom;
  16.      const char *zto;
  17. {
  18.   if (link (zfrom, zto) < 0)
  19.     {
  20.       if (errno != EEXIST)
  21.     return -1;
  22.       if (unlink (zto) < 0
  23.       || link (zfrom, zto) < 0)
  24.     return -1;
  25.     }
  26.   return unlink (zfrom);
  27. }
  28.