Reputation: 51941
An old parser relies on a FILE *
to work. However, the Dropbox Sync API for iOS returns a NSFileHandle *
instead of a FILE *
as a file handle.
So I try to use fileDescriptor
of a NSFileHandle
:
- (NSFileHandle )readHandle:(DBError *)error
Returns a read-only file handle for the file. If the file is not cached then the method will block until the file is downloaded. Returns
A file handle if the file can be read, or nil if an error occurred.
and passed as a FILE *
:
- (void)loadDBFile:(DBFile *)dbFile
{
DBError *dbError;
NSFileHandle *fileHandle = [dbFile readHandle:&dbError];
if (fileHandle) {
FILE *file = fileHandle.fileDescriptor;
fseek(file, 0, SEEK_END); // EXE_BAD_ACCESS here!
// ...
}
}
However, there is an EXE_BAD_ACCESS
at the fseek
line.
Upvotes: 4
Views: 1715
Reputation: 25318
fileDescriptor
returns the underlying file descriptor, a simple integer, not a FILE
object (which wraps a file descriptor, but isn't the same thing). Use fdopen()
to obtain a FILE
object from the file descriptor:
FILE *file = fdopen([filehandle fileDescriptor], "r"); // Create a read-only FILE object
Upvotes: 6