#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
static void die(const char *msg)
{
fprintf(stderr, "%s\n", msg);
_exit(1);
}
int main()
{
int fd;
struct stat statbuf;
char buf[16];
if ((fd = open("test.txt", O_RDWR)) < 0)
die("open failed");
if (lseek(fd, 100, SEEK_SET) != 100)
die("seek failed");
if (write(fd, "youpi", 5) != 5)
die("write failed");
if (fstat(fd, &statbuf) < 0)
die("stat failed");
printf("%ld\n", statbuf.st_size);
if (lseek(fd, 0, SEEK_SET) != 0)
die("seek failed");
if (read(fd, buf, 13) != 13)
die("read failed");
printf("%s\n", buf);
if (read(fd, buf, 3) != 3)
die("read failed");
printf("%02x %02x %02x\n", buf[0], buf[1], buf[2]);
if (lseek(fd, 98, SEEK_SET) != 98)
die("seek failed");
if (read(fd, buf, 2) != 2)
die("read failed");
printf("%02x %02x\n", buf[0], buf[1]);
if (read(fd, buf, 5) != 5)
die("read failed");
printf("%.5s\n", buf);
close(fd);
return 0;
}