My application uses lseek()to search for the desired position for recording data. File successfully opened by open(), and my application could be used lseek()and write()a lot of times.
At some point in time, for some users it is not easy to play, it lseek()returns -1 s errnoout of 9. The file does not close before this, and the file descriptor (int) is not reset.
After that another file is created; open()again in order and lseek()and write()work again.
To make this even worse, this user again tried the full sequence, and everything was fine.
So my question is: can the OS close the file for me for some reason? What could be the reason for this? Is there a file indexer or file scanner?
What is the best way to solve this problem? is this pseudo code the best solution? (not paying attention to the code layout, it will create functions for it)
int fd=open(...);
if (fd>-1) {
long result = lseek(fd,....);
if (result == -1 && errno==9) {
close(fd..); //make sure we try to close nicely
fd=open(...);
result = lseek(fd,....);
}
}
Does anyone experience something similar?
Summary: file searching and writing work fine for a given fd and unexpectedly returns errno = 9 for no reason.
source
share