I have some C code that uses open and lseek (and other functions of
course). I build the C code using XCode as a dylib, I created the
project using the "BSD Dynamic Library" option. I then created
another project as a "Cocoa Application".
Inside main.m in the app, I can use open and lseek fine. However,
when the main.m file calls a function inside the dylib that calls open
and lseek, lseek always fails with EINVAL. I know the file handle is
valid though -- calls to read() work with that same handle, it is only
lseek that fails.
I'm thinking maybe the file is being opened in a way that seeks are
not possible, like in a mode used for pipes or devices that do not
sup****t seeking. Maybe the default mode for open() is different for a
Cocoa Application project vs a BSD Dylib project?
Any help is greatly appreciated. Also, what are the most popular Mac
developer forums/lists, and do I need to pay to access them? I found
public lists on apple.com, but I think most of the real discussion is
on private lists... wherever those are.
I've got my code down to just this in both projects (same code works
in app, but not in dylib):
int fh;
fh = open("/test/test.dat",O_RDWR);
assert(fh != -1);
assert(lseek(fh,0,SEEK_SET) != -1);
close(fh);
The lseek line fails (returns -1), and I've had other code to check
errno, and it is set to EINVAL. Again, same code works in app, but
fails in dylib.


|