#include // so I don't have to do lo level io everywhere. #include // close, and in general #include //read #include //read #include //read #include // perror #include using namespace std; const char * filename = "fileHole"; int main() { int fd; int pos, bytes; char i; // more on this open soon. fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ); if (-1 == fd) { perror("Open failed"); return -1; } // write ten integers to the file. for(i='a';i<'j';i++) { bytes = write(fd, &i, sizeof(i)); if (-1 == bytes) { perror("Write failed: "); } } pos = lseek(fd, 0, SEEK_CUR); if (-1 == pos) { perror("Seek failed with offset of 0:"); } else { cout << "After writing we are at position " << pos << endl; } // now skip a block. pos = lseek(fd, 10*sizeof(i), SEEK_CUR); if (-1 == pos) { perror("Seek Failed: "); } else { cout << "Writing at position " << pos << endl; // put the 10. bytes = write(fd, &i, sizeof(i)); if (-1 == bytes) { perror("Writing at the end of a hole failed "); } } close(fd); return 0; }