Hi,
I'm trying to lock a file from objective-c (or plain C) so that other processes cannot read or write to it. So far, unsuccessfully.
I've tried to use all APIs I can think of, but none locked the file:
open then flock
open then lockf
open with O_EXLOCK
open then fcntl (F_SETLK)
open then NSDistributedLock
I'm running macOS 11.6.1 on an APFS drive.
For every API used, I was able to open and edit the file from command line using vi or just using cat on the file.
Isn't there any way of preventing another process from accessing a file, until I'm done with it (ie. I closed the file, or the file handle is relinquished)?
Thanks,
Chris