Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on A fundamental introduction to x86 assembly programming. Parent comment
The function should read in a loop, to fulfill its contract (read a record).
#include <unistd.h> ssize_t read_record(int fd, void* buf, size_t record_size, size_t* written) { for (*written = 0; *written < record_size; ) { ssize_t n = read(fd, (char*)buf + *written, record_size - *written); if (n < 1) return n; /* error or EOF */ *written += n; } return *written; }
There are no comments on this comment yet.
The function should read in a loop, to fulfill its contract (read a record).