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

  1. /*    DeleteLink  (or NewDeleteLink ;-)  
  2.  *        by
  3.  *    Phil Dietz -- NCEMRSoft 1991
  4.  *
  5.  *    USAGE:    DeleteLink <file>
  6.  *
  7.  *    SUMMARY:  Deletes a soft link pointing to an unmounted file
  8.  *              which Commodore's 'delete' SHOULD do, but doesn't.
  9.  *
  10.  *    TIPS:     You know you have a bad soft link when:
  11.  *              NewList6 shows 'link -> :UNKNOWN FILE:
  12.  *          or     "       "   'link -> !some_file
  13.  *
  14.  *              The link is not bad, it's just that you can't delete
  15.  *              the link whenver you want.  That's why deletelink is here.
  16.  *
  17.  *    REQUIREMENTS:  WB2.0 version 37
  18.  *
  19.  *    COMPILE:  lc -Lt -ccurfist -rr -ms -O -v -b1 DeleteLink.c
  20.  *
  21.  *    $VER: DeleteLink 1.0
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <exec/types.h>
  27. #include <clib/exec_protos.h>
  28. #include <pragmas/exec_pragmas.h>
  29. #include <dos/dos.h>
  30. #include <dos/dosextens.h>
  31. #include <clib/dos_protos.h>
  32. #include <pragmas/dos_pragmas.h>
  33.  
  34. extern struct DOSBase *DOSBase;
  35.  
  36. int main(int argc, char **argv)
  37.    {
  38.    struct FileInfoBlock __aligned fib;
  39.    BPTR lock;
  40.  
  41.    if (!(struct DosLibrary *)OpenLibrary("dos.library", 37)) exit(1);
  42.    if (argc<2) 
  43.       {
  44.       PutStr("Usage: DeleteLink <filename>\n");
  45.       exit(1);
  46.       }
  47.    lock=Lock(argv[1], SHARED_LOCK);
  48.    if(lock)
  49.       {
  50.       if(Examine(lock,&fib))
  51.          {
  52.          if(fib.fib_DirEntryType==3) {if (!(DeleteFile(argv[1]))) PutStr("Failed.\n");}
  53.          else PutStr("Not a soft link.\n");
  54.          }
  55.       UnLock(lock);
  56.       }
  57. }
  58.