home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15383 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  3.5 KB

  1. Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!data.nas.nasa.gov!taligent!apple!apple!NewsWatcher!user
  2. From: REEKES@applelink.apple.com (Jim Reekes)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Is a resource fork already open?
  5. Message-ID: <REEKES-110992142814@90.10.20.67>
  6. Date: 11 Sep 92 21:39:07 GMT
  7. References: <39464@imag.imag.fr> <1992Sep8.153520.10687@waikato.ac.nz>
  8. Sender: usenet@Apple.COM
  9. Followup-To: comp.sys.mac.programmer
  10. Organization: Apple Computer, Inc.
  11. Lines: 64
  12.  
  13. In article <1992Sep8.153520.10687@waikato.ac.nz>, ldo@waikato.ac.nz
  14. (Lawrence D'Oliveiro, Waikato University) wrote:
  15. > In article <39464@imag.imag.fr>, cinquin@imag.fr ( Philippe Cinquin) writes:
  16. > > Sorry if this is a stupid question, but how do you know if the resource fork of
  17. > > a file is already open?
  18. > If a file is already open by somebody else, you'll get an error if you try
  19. > opening it in a mode that's incompatible with the other person's open mode.
  20. > But I suspect you're really asking what happens when you open a resource file
  21. > twice from the same application. The answer is, you will get the same file
  22. > refnum back the second time. So how do you tell that this is happened? It can
  23. > be done, without too much low-level messing about.
  24. > The Resource Manager maintains a chain of currently-open resource files.
  25. > It loads the "resource map" structure from each file into memory, and fills
  26. > in a link field to chain all the resource maps together. There are two
  27. > important low-memory globals that are used for this:
  28. >     TopMapHndl -- handle to the first resource map in the chain
  29. >     CurMap -- refnum of the "current" resource file (returned by
  30. >         CurResFile, can be changed with UseResFile to point anywhere
  31. >         along the chain).
  32. >
  33. > **** some stuff deleted ****
  34.  
  35. The best approach to take is to avoid the problem in the first place.
  36.  
  37.  
  38. * Stay away from low memory globals
  39.  
  40. * To determine if a file is already open, use PBGetCatInfo.
  41.  
  42. * To know when it's safe to close a resource file, make sure you're the
  43. only one that opened it.  This can be done by first checking the ioFlAttrib
  44. from PBGetCatInfo *BEFORE* you open the file.  If it's open, then don't
  45. open is again.  Then you'll know that it's safe to close it.
  46.  
  47. * If you call OpenRFPerm with read-only, then you'll always get a new
  48. FCB and map.  This means it's safe to close it.
  49.  
  50. * It's dangerous to have more than one path open to a resource file.
  51. If one user has a read/write path, and a second use has another read-only
  52. path, then the first user can change the file and this means the second
  53. reader is screwed.  The file is corrupted to the 2nd reader's point of
  54. view.
  55.  
  56. * To make things more complicated, and more dangerous, the System file is
  57. always open and always available to everyone.  You'll always find the
  58. System
  59. map in your application's resource chain.  Additionally, any file below
  60. the System will also be in your chain (fonts, suitcases, input methods,
  61. etc.)
  62. These are files you typically never open directly.  Just call GetResource
  63. and assume it's been opened for you.  This is why system resources have
  64. unique numbers and types.
  65.  
  66. -----------------------------------------------------------------------
  67. Jim Reekes, Polterzeitgeist  |     Macintosh Toolbox Engineering
  68.                              |          Sound Manager Expert
  69. Apple Computer, Inc.         | RAll opinions expressed are mine, and do
  70. 20525 Mariani Ave. MS: 81-KS |   not necessarily represent those of my
  71. Cupertino, CA 95014          |       employer, Apple Computer Inc.S
  72.