[comp.sys.mac.programmer] Is this file open?

emerson@griffin.uvm.edu (Tree) (08/23/90)

Greetings and Salutations,

Is there a way to tell if a file returned from SFGetFile is already open?

Thanks.

Tom

+----------------------------------------------------------------------+
| The three most dangerous things in the   |                           |
| world are a programmer with a soldering  | Tom Emerson               |
| iron, a hardware guy with a software     | emerson@griffin.uvm.edu   |
| patch, and a user with an idea.          |                           |
+----------------------------------------------------------------------+

tim@efi.com (Tim Maroney) (08/23/90)

In article <1628@uvm-gen.UUCP> emerson@griffin.uvm.edu (Tree) writes:
>Is there a way to tell if a file returned from SFGetFile is already open?

Yes.  The usual way assumes that all you care about is whether it's
already open in your application; just walk your application's window
list (presumably, you have some internal data structure for your window
list, but if not, you can always walk the system window list starting
at FrontWindow) and see if it's there.  If you want to see if anyone
has it open in any way at all, call PBGetFInfo or PBHGetFInfo on it and
see if the ioRefNum field is positive; if so, it's the refNum that the
file is open under.

stevec@Apple.COM (Steve Christensen) (08/23/90)

In article <1627@uvm-gen.UUCP> root@griffin.uvm.edu (Charles Root) writes:

>Is there a way to tell if a file returned from SFGetFile is already open?

Yes, call either PBGetFInfo or PBHGetFInfo and then check out the ioFlAttrib
field.  The relevant bits in this byte are as follows:

	bit	meaning
	 2	set if the resource fork is open
	 3	set if the data fork is open
	 7	set if either fork is open

This is described in detail in Inside Mac volume 4, File Manager chapter.
If you don't want to deal with open files at all, you can do this check
in a file filter (that you pass a pointer to SFGetFile).  That way, open
files won't even show up in the list...

steve

-- 
____________________________________________________________________

  Steve Christensen             Internet:   stevec@goofy.apple.com
  Apple Computer, Inc.          AppleLink:  STEVEC
  20525 Mariani Ave, MS 81-CS   CompuServe: 76174,1712
  Cupertino, CA  95014

  "You just contradicted me."  "No I didn't."
____________________________________________________________________