News for hackers. Stuff that matters.
Re:A fundamental introduction to x86 assembly programming by d0mine on Friday May 20, 2016 @08:58PM (#11742639)
Unrelated: the code is equivalent to read(fd, buf, RECORD_SIZE) that may read less than RECORD_SIZE.

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.