home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume19 / rkive / part01 / rename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-29  |  1.0 KB  |  43 lines

  1. /*    
  2. **
  3. ** This software is Copyright (c) 1989 by Kent Landfield.
  4. **
  5. ** Permission is hereby granted to copy, distribute or otherwise 
  6. ** use any part of this package as long as you do not try to make 
  7. ** money from it or pretend that you wrote it.  This copyright 
  8. ** notice must be maintained in any copy made.
  9. **
  10. **
  11. **  History:
  12. **    Creation: Tue Feb 21 08:52:35 CST 1989 due to necessity.
  13. **                                                               
  14. */
  15. #ifndef lint
  16. static char SID[] = "@(#)rename.c    1.1 6/1/89";
  17. #endif
  18.  
  19. #include <stdio.h>
  20.  
  21. extern FILE *errfp;
  22.  
  23. /*
  24. **    rename(sfn, dfn)
  25. **    rename char *sfn to char *dfn
  26. */
  27.  
  28. int rename(sfn, dfn)
  29. char *sfn;        /* source file name      */
  30. char *dfn;        /* destination file name */
  31. {
  32.     int rcd;
  33.  
  34.     (void) unlink(dfn);       /* remove the destination file */
  35.  
  36.     if ((rcd = link(sfn, dfn)) == -1) 
  37.         (void) fprintf(errfp, "Can't link %s to %s\n", sfn, dfn);
  38.     else if ((rcd = unlink(sfn)) == -1) 
  39.         (void) fprintf(errfp, "Can't unlink %s\n", sfn);
  40.     return(rcd);
  41. }
  42.  
  43.