[Vm-dev] FilePlugin and reading from stdio
Holger Freyther
holger at freyther.de
Fri Sep 23 07:33:26 UTC 2016
Good Morning,
I am working on some primitives to allow to populate a SQFile* based on int fd/FILE* and tried to understand the semantics of isStdioStream. When opening a non-file (e.g. a file descriptor returned from inotify_init1) I noticed this gem:
bytesRead = 0;
do {
clearerr(file);
if (fread(dst, 1, 1, file) == 1) {
bytesRead += 1;
if (dst[bytesRead-1] == '\n'
|| dst[bytesRead-1] == '\r')
break;
}
}
while (bytesRead <= 0 && ferror(file) && errno == EINTR);
* >>#primRead:into:startingAt:count: will ignore count and only fill one byte at max. After the first successful fread the while loop will be left. The if for checking for a \n or \r could be deleted. I assume the intention was to read until bytesRead == count or \n\r? So e.g. even count: 0 will be ignored and turned into a '1'.
* To me line buffering looks a bit like a workaround but if we want this semantic for stdio can't we use fgets?
regards
holger
More information about the Vm-dev
mailing list