Skip to content

Instantly share code, notes, and snippets.

@andrestc
Created May 31, 2017 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrestc/a0d290ac7200c51760792334caaffe1a to your computer and use it in GitHub Desktop.
Save andrestc/a0d290ac7200c51760792334caaffe1a to your computer and use it in GitHub Desktop.
int i, holes = 0;
while ((numRead = read(inputFd, buf, BUF_SIZE)) > 0)
{
if (keepHoles == 1) {
for (i = 0; i < numRead; i++) {
if (buf[i] == '\0') {
holes++;
continue;
} else if (holes > 0) {
lseek(outputFd, holes, SEEK_CUR);
holes = 0;
}
if (write(outputFd, &buf[i], 1) != 1)
fatal("couldnt write char to file");
}
} else {
if (write(outputFd, buf, numRead) != numRead)
fatal("couldn't write whole buffer to file");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment