+ if (file_offset + count <= file_bufsize)
+ {
+ memcpy (buf, file_buf + file_offset, count);
+ file_offset += count;
+ return count;
+ }
+ else if (file_bufsize > 0)
+ {
+ int l = file_bufsize - file_offset;
+ if (l > 0)
+ memcpy (buf, file_buf + file_offset, l);
+ if (count - l > file_bufsize)
+ {
+ r = read (fd, buf, count);
+ if (r > 0)
+ file_bufsize = read (fd, file_buf, file_bufsize);
+ else
+ file_bufsize = 0;
+ file_offset = 0;
+ return r;
+ }
+ r = read (fd, file_buf, file_bufsize);
+ if (r == -1)
+ {
+ logf (LOG_FATAL|LOG_ERRNO, "read");
+ exit (1);
+ }
+ memcpy (buf + l, file_buf, count - l);
+ file_offset = count - l;
+ file_bufsize = r;
+ }