SQLite Forum

Possible bug in .read when a directory is specified?
Login
> Those are the C library interfaces. Try the POSIX ones, without the leading “f”. I assume the Unix VFS uses the latter.

`open()` and `read()` do the same on my system (Mint Linux 20):

```c
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main() {
	int e;
	size_t i;
  char buf[256];
	int fd = open(".", O_RDONLY);
	printf("%d\n", fd);
	if (!fd<0) return -1;

	i = (ssize_t) read(fd, buf, sizeof(buf));
	e = errno;
	printf("%llu %d %s\n", (unsigned long long)i, e, strerror(e));

	close(fd);
	return 0;
}
```

Output:

```
3
18446744073709551615 21 Is a directory
```

Whether or not that's a standard behaviour, i don't know. It was a good 5 or 6 years ago that i had a piece of software simply open/fopen and read/fread a directory handle - perhaps that was specific to those C libs. No man pages i've found make any mention of it being an error to open/fopen a directory.

[IEEE fopen() lists only one error case][ieee] which sounds relevant:

[ieee]: https://pubs.opengroup.org/onlinepubs/9699919799/

```
[EISDIR]
    [CX] [Option Start] The named file is a directory and mode requires write access.
```

strongly implying that opening a directory *is* acceptable in read-only mode.

/shrugs shoulders