You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ioctl_tty(2) says that fionread accepts an int*, which may overflow for large files.
Incidentally, the correct size will be returned if we pass a pointer to int64_t, but this something we probably shouldn't rely on.
We probably should use a different syscall (fstat?) to query file size for regular files instead of fionread. Relevant discussion occurs in #552.
See this example C code which exhibits this behavior.
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <stdint.h>
int main(int argc, char** argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s [file path]\n", argv[0]);
exit(1);
}
FILE* file = fopen(argv[1], "r");
if (file == NULL) {
perror("opening file");
exit(1);
}
int fd = fileno(file);
int avail = 0;
//int64_t avail = 0;
int ret = ioctl(fd, FIONREAD, &avail);
if (ret == -1) {
perror("ioctl");
exit(1);
}
printf("Bytes available: %d\n", avail);
//printf("Bytes available: %ld\n", avail);
return 0;
}
The text was updated successfully, but these errors were encountered:
ioctl_tty(2)
says thatfionread
accepts anint*
, which may overflow for large files.Incidentally, the correct size will be returned if we pass a pointer to
int64_t
, but this something we probably shouldn't rely on.We probably should use a different syscall (
fstat
?) to query file size for regular files instead offionread
. Relevant discussion occurs in #552.See this example C code which exhibits this behavior.
The text was updated successfully, but these errors were encountered: