home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / share / fileshar / fileshar.pas next >
Pascal/Delphi Source File  |  1988-04-16  |  3KB  |  85 lines

  1. {************************************************************************
  2.  
  3.   FILESHAR - A unit to allow files to be flagged as sharable
  4.   Version 1.0 4/16/88
  5.   by Richard S. Sadowsky   CIS: 74017,1670
  6.  
  7.   This unit requires that SHARE.EXE or a network operating system be
  8.   loaded when these routines are used.  Without SHARE.EXE or equivelent,
  9.   the SHARE bit has no meaning, rendering these routines useless.
  10.   See the file NFLAG.PAS for a sample usage of this unit.
  11.  
  12.   This unit is known to be compatable with Novell's Advanced
  13.   NetWare, and is compatable with ANY other network that uses
  14.   the DOS 3 standard of setting the high bit to signify a
  15.   "sharable" file.
  16.  
  17.   This unit was extracted from a soon to be released commercial
  18.   package of Turbo Pascal 4 networking tools.  Send EASYPLEX to
  19.   74017,1670 for more information.
  20.  
  21.   These routines are provided as is by the author, and donated to
  22.   the public domain.  Feel free to post suggestions and enhancements
  23.   regarding this unit in Borland's BPROGA DL16 - Turbo Pascal and
  24.   Networks.
  25.  
  26. ************************************************************************}
  27.  
  28. unit FileShar;
  29.  
  30. interface
  31.  
  32. uses DOS; { needed to get and set file attributes }
  33.  
  34. const
  35.   _SHAREABLE       = $80;  { corresponds to the SHARE bit of the file att }
  36.  
  37. function FileIsSharable(Path : String; var FAttr : Word; var ErrCode : Word)
  38.                        : Boolean;
  39. { Return TRUE if file is flagged as shareable, return file attrib in FAttr }
  40. { return DOS error in ErrCode }
  41.  
  42. function MakeFileSharable(Path : String) : Word;
  43. { make a file sharable (SHARE bit of file attribute is set) }
  44.  
  45.  
  46. {**************************************************************************}
  47. implementation
  48. {**************************************************************************}
  49.  
  50. function FileIsSharable(Path : String; var FAttr : Word; var ErrCode : Word)
  51.                        : Boolean;
  52.  
  53. var
  54.   F                : File;
  55.  
  56. begin
  57.   Assign(F,Path);
  58.   GetFAttr(F,FAttr);    { use DOS unit to get the file attribute }
  59.   ErrCode := DOSError;  { pass any error info to calling routine }
  60.   FileIsSharable := (FAttr and _SHAREABLE) <> 0   { see if SHARE }
  61.                                                   { bit set.     }
  62. end;
  63.  
  64. function MakeFileSharable(Path : String) : Word;
  65.  
  66. var
  67.   F                : File;
  68.   Attr             : Word;
  69.   ErrCode          : Word;
  70.   Share            : Boolean;
  71.  
  72. begin
  73.   { first, see if the file is already sharable (and that it exists), }
  74.   { if it exists and is NOT already flagged to sharable, the SHARE   }
  75.   { bit is set by ORing $80 with the file's attribute }
  76.   Share := FileIsSharable(Path,Attr,ErrCode);  { is it sharable? }
  77.   if (ErrCode = 0) and (not Share) then begin
  78.     Assign(F,Path);
  79.     SetFAttr(F,Attr or _SHAREABLE); { OR existing at with SHARE bit }
  80.     ErrCode := DOSError;
  81.   end;
  82.   MakeFileSharable := ErrCode;
  83. end;
  84. end. { of Unit FileShar }
  85.