UNIX file locking
Hello, guys! Sorry my bad english :)
I use a small txt base in file, write there and read (strings), size its is changed constantly, as i can install locking for reading or for writing?
if i use
when i will read the file, as i will know what size of *buf i will take? Or there is more flexible ways?
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
>can install locking for reading or for writing?
You can use locks on your file for both read as well as write mode. See help on functions like: lockf(), flock(), ...
>what size of *buf i will take?
You cannot do it while reading itself, instead, if you are sure there are only fixed number of bytes to be read, you can hard-code. Else, read byte-by-byte until EOF is reached, the most flexible way.