Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pallavi0703

macrumors newbie
Original poster
Dec 12, 2007
27
0
Hello All,
In Xcode Carbon C bundel application I want to open a file and read data from it, but at runtime I am not able to make FSRef from file path. Following code I am using please tell me what changed are required in this code.



CFURLRef url ;
Boolean flag;
FSRef ref , ref2 ;
OSErr error ,result;
char *volname = NULL;
char revpath[PATH_MAX];
HFSUniStr255 dataForkName;
SInt16 forkRefNum;

volumeNameForPath("/", &volname);//user defined function to get default volume name
strcat(volname,":CFURL.txt");//now volname = "Macintosh HD:CFURL.txt" and strlen((char*)volname = 22

url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,volname,strlen((char*)volname),false);
flag = CFURLGetFSRef((CFURLRef)url , &ref);//true if success else false
//flag returned is 0 it should be 1

or

error = FSPathMakeRef(volname,&ref2,false);

result = FSGetDataForkName(&dataForkName);
if (result != noErr) {
syslog(LOG_INFO, "FSGetDataForkName() returned %d", result);
return;
}

result = FSOpenFork(&ref, dataForkName.length, dataForkName.unicode, fsRdPerm, &forkRefNum);//result returned is -35.


Thanks & Regards,
Pallavi.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Hello All,
In Xcode Carbon C bundel application I want to open a file and read data from it, but at runtime I am not able to make FSRef from file path. Following code I am using please tell me what changed are required in this code.



CFURLRef url ;
Boolean flag;
FSRef ref , ref2 ;
OSErr error ,result;
char *volname = NULL;
char revpath[PATH_MAX];
HFSUniStr255 dataForkName;
SInt16 forkRefNum;

volumeNameForPath("/", &volname);//user defined function to get default volume name
strcat(volname,":CFURL.txt");//now volname = "Macintosh HD:CFURL.txt" and strlen((char*)volname = 22

url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,volname,strlen((char*)volname),false);
flag = CFURLGetFSRef((CFURLRef)url , &ref);//true if success else false
//flag returned is 0 it should be 1

or

error = FSPathMakeRef(volname,&ref2,false);

result = FSGetDataForkName(&dataForkName);
if (result != noErr) {
syslog(LOG_INFO, "FSGetDataForkName() returned %d", result);
return;
}

result = FSOpenFork(&ref, dataForkName.length, dataForkName.unicode, fsRdPerm, &forkRefNum);//result returned is -35.

Read the documentation for CFURLCreateFromFileSystemRepresentation. The comment for the second parameter says "The character bytes to convert into a CFURL object. This should be the path as you would use in POSIX function calls."
 

pallavi0703

macrumors newbie
Original poster
Dec 12, 2007
27
0
now error for FSReadFork

Hello gnasher729,
Now I am using posix file path ,
but for reading file every time new error code is returned like -4628 ,-4132,-5380 etc.

ByteCount requestCount;
void *buffer;
ByteCount *actualCount;

result = FSOpenFork(&ref, dataForkName.length, dataForkName.unicode, fsRdPerm, &forkRefNum);// returns noErr
if(result == noErr) {

buffer = malloc(1024);
requestCount = 128;
Err1= FSReadFork(forkRefNum,fsFromStart,0, requestCount,&buffer, &actualCount);//program get hanged
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.