home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / zoo141_c.lzh / OPTIONS.C < prev    next >
C/C++ Source or Header  |  1987-02-07  |  2KB  |  59 lines

  1. /* options.c */
  2. /*
  3. Copyright (C) 1986 Rahul Dhesi -- All rights reserved
  4. */
  5. /*
  6. Here we define routines specific to only a few systems.  Routines are
  7. selected based on defined symbols.  Routines specific to only one
  8. system are in machine.c for the appropriate system.
  9. */
  10.  
  11. #include "options.h"
  12. #include <stdio.h>
  13. #include "various.h"
  14. #include "zoo.h"
  15. #include "zoofns.h"
  16. #include "errors.i"
  17.  
  18. #ifdef REN_LINK         
  19. /* rename using link() followed by unlink() */
  20. /* 
  21. The following code assumes that if unlink() returns nonzero, then the
  22. attempt to unlink failed.  If unlink() ever returns nonzero after actually
  23. unlinking the file, then the file being renamed will be lost!!!  Test this 
  24. thoroughly.  It is assumed that link() and unlink() return zero if no
  25. error else nonzero.
  26. */
  27. int chname (newname, oldname)
  28. char *newname, *oldname;
  29. {
  30.    int status;
  31.    if (link (oldname, newname) == 0) { /* if we can create new name */
  32.       status = unlink (oldname);          /*   unlink old one */
  33.       if (status != 0) {                  /*   if unlink of old name failed */
  34.          unlink (newname);                /*     cancel new link */
  35.          return (-1);                     /*     return error */
  36.       } else
  37.          return (0);
  38.    }
  39.    else                    /* couldn't create new link */
  40.       return (-1);
  41. }
  42. #else
  43. /* else not REN_LINK */
  44.  
  45. int chname (newname, oldname)
  46. char *newname, *oldname;
  47. {
  48. #ifdef REN_NORM
  49.    if (rename(newname, oldname) != 0)     /* normal order */
  50. #else
  51.    if (rename(oldname, newname) != 0)     /* reverse order */
  52. #endif
  53.       return (-1);
  54.    else
  55.       return (0);
  56. }
  57. #endif /* end of not REN_LINK */
  58.  
  59.