home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / newc_dev / newlist6.lzh / NewList6 / LinkStuff / MakeLink.c < prev    next >
C/C++ Source or Header  |  1991-12-16  |  2KB  |  63 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.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <dos/dos.h>
  30. #include <dos/dosextens.h>
  31. #include <clib/dos_protos.h>
  32. #include <clib/exec_protos.h>
  33. #include <pragmas/dos_pragmas.h>
  34. #include <pragmas/exec_pragmas.h>
  35.  
  36. extern struct DOSBase *DOSBase;
  37. extern struct SysBase *SysBase;
  38.  
  39. int main(int argc, char **argv)
  40.    {
  41.    BPTR lock1;
  42.  
  43.    if (!(struct DosLibrary *)OpenLibrary("dos.library", 37)) exit(1);
  44.  
  45.    if (argc<4) 
  46.       {
  47.       PutStr("Usage: MakeLink <link name> <file name> [hard | soft]\n");
  48.       exit(1);
  49.       }
  50.    if (*argv[3]=='h')                     /* Do hard-link stuff */
  51.       {
  52.       lock1=Lock(argv[2],SHARED_LOCK);    /* Fetch needed lock  */
  53.       if (lock1)
  54.          {
  55.          if (!(MakeLink(argv[1],lock1,FALSE))) PutStr("Hard link failed.\n");
  56.          else UnLock(lock1);
  57.          }
  58.          else Printf("Couldn't lock %s.\n",argv[2]);
  59.       }
  60.    else /* do soft-link stuff instead */
  61.         if (!(MakeLink(argv[1],(CPTR)argv[2],TRUE))) PutStr("Soft link failed.\n");
  62.    }
  63.