I open the file in read / write mode and perform a series of read, write and search operations (from user input).
At some point later, I want to make the file read-only to prevent it from being written further.
Is there a Linux (or POSIX) function for this? Perhaps some challenge fcntl?
Or is my only option is to save the current position in the file, close it and reopen it RD_ONLY?
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int fd = open("/path/to/file", O_RDWR);
write(fd, ...);
lseek(fd, ...);
read (fd, ...);
...
read (fd, ...);
lseek(fd, ...);
write(fd, ...);
source
share