The function you’re looking for is called “read”. You have to pass it a buffer you’ve already allocated previously, however. Something like this ought to work:
if (fd) {
char buffer[1024];
int n = read(fd, buffer, 1024);
/* ... */
}
after that call, n will contain the number of bytes read from the fd (or 0 for none or less than 0 if an error occured).
If you have raw ints in that file, you could then access them kinda like this:
int *ibuffer = (int*)buffer;
ibuffer is then an array of ints of length 1024/sizeof(int) containing the first n/sizeof(int) consecutive ints in fd. Strictly speaking this isn’t quite legal C, but then I haven’t seen an architecture lately where this wouldn’t have worked.
2
solved Low-level read file [closed]