Discontiguous data file – traditional approach

This seems quite simple: first seek to the required start offset and then write the data content for the required length; this can be done via the pair of lseek(2) and write(2) system calls. Of course, we will have to invoke this pair of system calls three times. So, we write some code to actually perform this task; see the (relevant snippets) of the code here (ch18/sgio_simple.c):

For readability, only key parts of the source code are displayed; to view the complete source code, build, and run it, the entire tree is available for cloning from GitHub here: https://github.com/PacktPublishing/Hands-on-System-Programming-with-Linux.
#define A_HOLE_LEN  10#define A_START_OFF A_HOLE_LEN#define A_LEN ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.