#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#define BUF1_LEN 0x2000
#define BUF2_LEN 0x3000
#define BUF3_LEN (BUF1_LEN + BUF2_LEN)

int main(int argc, char *argv[])
{
       int fd;
       static char buf1[BUF1_LEN], buf2[BUF2_LEN], buf3[BUF3_LEN];

       fd = open("/proc/kcore", O_RDONLY);
       if (fd == -1) {
               fprintf(stderr, "open(), errno=%d (%s)\n", errno, strerror(errno));
               exit(1);
       }
       if (read(fd, buf1, BUF1_LEN) != BUF1_LEN) {
               fprintf(stderr, "read(buf1, BUF1_LEN),
                       errno=%d (%s)\n", errno, strerror(errno));
               exit(1);
       }
       if (read(fd, buf2, BUF2_LEN) != BUF2_LEN) {
               fprintf(stderr, "read(buf2, BUF2_LEN),
                       errno=%d (%s)\n", errno, strerror(errno));
               exit(1);
       }
       if (lseek(fd, 0, SEEK_SET) == -1) {
               fprintf(stderr, "lseek(0),
                       errno=%d (%s)\n", errno, strerror(errno));
               exit(1);
       }
       if (read(fd, buf3, BUF3_LEN) != BUF3_LEN) {
               fprintf(stderr, "read(buf3, BUF3_LEN),
                       errno=%d (%s)\n", errno, strerror(errno));
               exit(1);
       }
       if (memcmp(buf3, buf1, BUF1_LEN) != 0)
               fprintf(stderr, "Error: buf3 != buf1\n");
       if (memcmp(buf3+BUF1_LEN, buf2, BUF2_LEN) != 0)
               fprintf(stderr, "Error: buf3+BUF1_LEN != buf2\n");
       (void)close(fd);
       return 0;
}