Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!stevec From: stevec@Apple.COM (Steve Christensen) Newsgroups: comp.sys.mac.programmer Subject: Re: Yikes: Using both resource & data forks of a file Message-ID: <51644@apple.Apple.COM> Date: 17 Apr 91 22:54:07 GMT References: <280B842C.16551@orion.oac.uci.edu> Organization: Apple Computer Inc., Cupertino, CA Lines: 33 bdugan@teri.bio.uci.edu (Bill Dugan) writes: >I'm creating a document file with "Create", writing data to the file's >data fork, and closing the file. Everything's great. But then I >want to put some resources in the file. I am trying "OpenRFPerm" with >write permission enabled, and it doesn't work; calling ResError() reveals >an EOF, which leads me to believe there's no resource fork, despite >IM's claim that Create will set up both forks of the file created. > >My pathetic theory is that a newly created file, when closed, will not >get set up with a resource fork if no data has been written to that >fork. But since the resource fork & data fork can (supposedly) be treated >separately, I don't see why I should have to nest my open & close calls >just to make sure it all gets written out correctly, and I haven't tried >this anyway. Can anyone point me in a general direction? Create will initialize both forks to be zero length. Adding to the data fork is done by making Write calls. To actually create the resource fork, i.e., set it up so you can add resources to it, you need to call CreateResFile before calling OpenResFile/OpenRFPerm. The reason it's done that way (I presume), is so that you don't have to carry around a few hundred extra bytes in the resource fork if all you wanted to do was put something in the data fork. Note that there are separate access paths to the resource and data forks of a file (if both are open), so you can close one fork without affecting the other... steve -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steve Christensen Never hit a man with glasses. stevec@apple.com Hit him with a baseball bat.