home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 52 / af052sub.adf / newlist.lha / NewList / Misc / MakeLink.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  2KB  |  65 lines

  1. /*     MakeLink  (or NewLink ;-)  
  2.  *        by
  3.  *    Phil Dietz -- NCEMRSoft
  4.  *
  5.  *    USAGE:    MakeLink <link name> <file name> [hard | soft]
  6.  *
  7.  *    EXAMPLE:  MakeLink  df1:link  df1:source/NewList hard
  8.  *              MakeLink  df1:link  df1:source/NewList soft
  9.  *
  10.  *    SUMMARY:  Makes both hard AND soft links which Commodore's
  11.  *              MakeLink fails to do.  Files and dirs are supported.
  12.  *
  13.  *    TIPS:     Always try to make hard links when possible.  If your
  14.  *              filesystem doesn't like hard-links, you can resort
  15.  *              to softlinks.  Softlinks are more prone to errors.
  16.  *              If you accidently delete the file the soft link points to,
  17.  *              you'll have a file that can only be deleted with
  18.  *              'deletelink'.  HOWEVER, softlinks do offer a bonus.
  19.  *              They may point across filesystems (ie points to dh0:
  20.  *              from df1:!)  They are pretty neat when used right!
  21.  *
  22.  *    NOTES:    Works only under wb2.0 version 37.
  23.  *
  24.  *    COMPILE:  lc -Lt -ccurfist -rr -ms -O -v -b1 MakeLink.c
  25.  *
  26.  *    $VER: MakeLink 1.0
  27.  */
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <dos/dos.h>
  32. #include <dos/dosextens.h>
  33. #include <clib/dos_protos.h>
  34. #include <clib/exec_protos.h>
  35. #include <pragmas/dos_pragmas.h>
  36. #include <pragmas/exec_pragmas.h>
  37.  
  38. extern struct DOSBase *DOSBase;
  39. extern struct SysBase *SysBase;
  40.  
  41. int main(int argc, char **argv)
  42.    {
  43.    BPTR lock1;
  44.  
  45.    if (!(struct DosLibrary *)OpenLibrary("dos.library", 37)) exit(1);
  46.  
  47.    if (argc<4) 
  48.       {
  49.       PutStr("Usage: MakeLink <link name> <file name> [hard | soft]\n");
  50.       exit(1);
  51.       }
  52.    if (*argv[3]=='h')                     /* Do hard-link stuff */
  53.       {
  54.       lock1=Lock(argv[2],SHARED_LOCK);    /* Fetch needed lock  */
  55.       if (lock1)
  56.          {
  57.          if (!(MakeLink(argv[1],lock1,FALSE))) PutStr("Hard link failed.\n");
  58.          UnLock(lock1);
  59.          }
  60.          else Printf("Couldn't lock %s.\n",argv[2]);
  61.       }
  62.    else /* do soft-link stuff instead */
  63.         if (!(MakeLink(argv[1],(CPTR)argv[2],TRUE))) PutStr("Soft link failed.\n");
  64.    }
  65.