home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD2.img / d4xx / d473 / cnewssrc / cnews_src.lzh / libamiga / link.c < prev    next >
C/C++ Source or Header  |  1991-01-01  |  1KB  |  63 lines

  1. /*    :ts=4
  2.  *    This is an Amiga version of the Unix link() system call
  3.  *
  4.  *    $Id$
  5.  *
  6.  *    $Log$
  7.  */
  8.  
  9. #include <stdio.h>                    /* For file_i/o stuff */
  10. #include <exec/types.h>
  11. #include <dos/dos.h>
  12. #include <clib/exec_protos.h>        /* For FindTask() */
  13. #include <clib/dos_protos.h>        /* For *Lock*(), MakeLink() */
  14.  
  15. #if INCLUDE_VERSION >= 36
  16. # include <pragma/dos.h>
  17. #endif
  18.  
  19. FILE **Link_a;                        /* The address of art->a_artf  */
  20.  
  21. link(char *from, char *to)
  22. {
  23.     register int ret = 0;
  24. #if INCLUDE_VERSION >= 36
  25.     static short flag;
  26.     BPTR lock;
  27.     fpos_t pos;
  28.  
  29.     if (flag == 0) {
  30.         extern struct DosLibrary *SysBase;
  31.         flag = (short) SysBase->dl_lib.lib_Version;
  32.     }
  33.     if (flag > 35) {
  34.         pos = (fpos_t) -1;
  35.         if (*Link_a) {
  36.             if (!fgetpos(*Link_a, &pos))
  37.                 fclose(*Link_a);
  38.         }
  39.         if (lock = Lock((UBYTE *)from, ACCESS_READ)) {
  40.             if (!MakeLink((UBYTE *)to, lock, LINK_HARD)) {
  41.                 ret = IoErr();
  42. #if 0
  43.                 warning("Couldn't make link (%s) from `%s' to `%s'",
  44.                     strerror(IoErr()), from, to);
  45. #endif
  46.             }
  47.             UnLock(lock);
  48.         } else {
  49.             ret = IoErr();
  50. #if 0
  51.             warning("Couldn't obtain lock (%s) on `%s' during link to `%s'",
  52.                 strerror(IoErr()), from, to);
  53. #endif
  54.         }
  55.         if (pos != (fpos_t) -1) {
  56.             *Link_a = fopen(from, "a+");
  57.             fsetpos(*Link_a, &pos);
  58.         }
  59.     }
  60. #endif /* INCLUDE_VERSION */
  61.     return( ret );
  62. }
  63.