I got NSFileHandle
from a function call and would like to access the file it refers to. How to get it?
I know that the resource might have multiple file paths or no file path at all (file in memory). However, it would be nice to get anything :)
I got NSFileHandle
from a function call and would like to access the file it refers to. How to get it?
I know that the resource might have multiple file paths or no file path at all (file in memory). However, it would be nice to get anything :)
You can use F_GETPATH
:
NSFileHandle* Handle = [NSFileHandle fileHandleForReadingAtPath:
@"/Applications/TextEdit.app/Contents/Info.plist"];
char Path[MAXPATHLEN];
if (Handle && fcntl([Handle fileDescriptor], F_GETPATH, Path) != -1)
NSLog(@"%@", [NSString stringWithUTF8String:Path]);
In swift:
var buffer = [CChar](repeating: 0, count: Int(MAXPATHLEN))
_ = fcntl(fileHandle.fileDescriptor, F_GETPATH, &buffer)
let fileName = String(cString: buffer)