Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* For use with CodeWarrior Standard Console */
- #include <stdio.h>
- #include <Files.h>
- #include <StandardFile.h>
- #include <Types.h>
- enum {
- kBufferSize = 0x8000,
- kMaxLoops = 10
- };
- int main(void) {
- StandardFileReply stdReply;
- FSRef fsRef;
- FSForkIOParam fsForkIOParam;
- HFSUniStr255 dataForkName;
- SInt64 forkSize;
- FSForkIOParamPtr fsForkPtr[2];
- FSForkIOParamPtr currFSForkPtr;
- OSErr err;
- short i, j;
- char filename[256];
- short currFSForkIndex = 0;
- printf("Here we go...\n");
- StandardGetFile(NULL, -1, NULL, &stdReply);
- if (stdReply.sfGood) {
- FSpMakeFSRef(&stdReply.sfFile, &fsRef);
- FSGetDataForkName(&dataForkName);
- fsForkIOParam.ref = &fsRef;
- fsForkIOParam.forkNameLength = dataForkName.length;
- fsForkIOParam.forkName = dataForkName.unicode;
- fsForkIOParam.permissions = fsRdPerm;
- err = PBOpenForkSync(&fsForkIOParam);
- if (err) {
- printf("Error opening file (%d)", err);
- } else {
- /* Print the filename */
- BlockMove(stdReply.sfFile.name + 1, filename, stdReply.sfFile.name[0]);
- filename[stdReply.sfFile.name[0]] = 0;
- printf("File: %s\n", filename);
- FSGetForkSize(fsForkIOParam.forkRefNum, &forkSize);
- printf("Data Fork Size: %lld bytes\n", forkSize);
- /* Setup the two FSForkIOParam blocks */
- for (i = 0 ; i < 2 ; ++i) {
- fsForkPtr[i] = (FSForkIOParamPtr)NewPtrClear(sizeof(FSForkIOParam));
- fsForkPtr[i]->ioCompletion = 0;
- fsForkPtr[i]->forkRefNum = fsForkIOParam.forkRefNum;
- fsForkPtr[i]->positionMode = fsAtMark;
- fsForkPtr[i]->positionOffset = 0LL;
- fsForkPtr[i]->requestCount = kBufferSize;
- fsForkPtr[i]->buffer = NewPtrClear(kBufferSize);
- /* Add read to the queue */
- PBReadForkAsync(fsForkPtr[i]);
- }
- currFSForkPtr = fsForkPtr[0];
- i = 0;
- while (true) {
- /* Wait for data */
- j = 0;
- while (currFSForkPtr->ioResult > 0) {
- printf("[Thread %d]\t\tWaiting for data (%d)\n", currFSForkIndex + 1,currFSForkPtr->ioResult);
- if (++j == kMaxLoops) {
- printf("[Thread %d]\t\tWaited too long!\n");
- break;
- }
- };
- printf("[Thread %d][%d]\t%d bytes read. Mark now @%08llx. ",
- currFSForkIndex + 1,
- i++,
- currFSForkPtr->actualCount,
- currFSForkPtr->positionOffset);
- printf("Data: %llx\n", *((long long*)currFSForkPtr->buffer));
- /* eofErr is -39 */
- if (currFSForkPtr->ioResult < 0) {
- break;
- }
- /* Add next read to the queue */
- PBReadForkAsync(currFSForkPtr);
- /* Switch to the other buffer */
- currFSForkIndex = 1 - currFSForkIndex;
- currFSForkPtr = fsForkPtr[currFSForkIndex];
- }
- printf("[Thread %d]\t\tioResult was %d\n", currFSForkIndex + 1, currFSForkPtr->ioResult);
- /* Close the file */
- err = PBCloseForkSync(&fsForkIOParam);
- if (err) {
- printf("Error closing file (%d)", err);
- }
- }
- } else {
- printf("No file selected");
- }
- /* Cleanup */
- for (i = 0 ; i < 2 ; ++i) {
- DisposePtr(fsForkPtr[i]->buffer);
- DisposePtr((Ptr)fsForkPtr);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement