Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Alloc.c
#include <Files.h> |
#include <Quickdraw.h> |
#include <Windows.h> |
#include <dialogs.h> |
#include <OSEvents.h> |
#include <StandardFile.h> |
#include <Memory.h> |
#include <StdIO.h> |
#define TRUE 0xFF |
#define FALSE 0 |
main() |
{ |
ParmBlkPtr myRecPtr; |
HParmBlkPtr myVRecPtr; |
OSErr err; |
Point where = {20,20}; |
SFReply reply; |
short refnum; |
char* string; |
InitGraf(&qd.thePort); |
FlushEvents(everyEvent, 0); |
InitWindows(); |
InitDialogs(nil); |
InitCursor(); |
/* does not work version */ |
string = (char*) "\pWhere is junk file"; |
SFGetFile (where, (Str255) string, nil, -1, (SFTypeList) nil, nil, &reply); |
err = FSOpen(reply.fName, reply.vRefNum, &refnum); |
if (err != noErr) |
Debugger(); |
myRecPtr = (ParmBlkPtr) NewPtrClear(sizeof(ParamBlockRec));; |
myRecPtr->ioParam.ioRefNum = refnum; |
myRecPtr->ioParam.ioReqCount = 0x7fffffff; |
err = PBAllocate (myRecPtr, FALSE); |
printf("error = %d, Actual count = %d\n",err, myRecPtr->ioParam.ioActCount); |
err = FSClose(refnum); |
if (err != noErr) |
Debugger(); |
/* The method which works - work around to above bug */ |
string = (char*) "\pWhere is File"; |
SFGetFile (where, (Str255) string, nil, -1, (SFTypeList) nil, nil, &reply); |
err = FSOpen(reply.fName, reply.vRefNum, &refnum); |
if (err != noErr) |
Debugger(); |
myVRecPtr = (HParmBlkPtr) NewPtrClear(sizeof(HParamBlockRec));; |
myVRecPtr->volumeParam.ioVRefNum = reply.vRefNum; |
err = PBHGetVInfo(myVRecPtr, FALSE); |
if (err != noErr) |
Debugger(); |
printf("# of blocks = %d\n Size of blocks = %d\n",myVRecPtr->volumeParam.ioVNmAlBlks, myVRecPtr->volumeParam.ioVAlBlkSiz); |
myRecPtr = (ParmBlkPtr) NewPtrClear(sizeof(ParamBlockRec));; |
myRecPtr->ioParam.ioRefNum = refnum; |
myRecPtr->ioParam.ioReqCount = (myVRecPtr->volumeParam.ioVNmAlBlks) * |
(myVRecPtr->volumeParam.ioVAlBlkSiz); |
err = PBAllocate (myRecPtr, FALSE); |
printf("error = %d, Actual count = %d\n",err, myRecPtr->ioParam.ioActCount); |
err = FSClose(refnum); |
if (err != noErr) |
Debugger(); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14