Skip to content

Instantly share code, notes, and snippets.

@kurahaupo
Created December 16, 2017 05:56
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 kurahaupo/508e9901617c990ff2b25940c26d4007 to your computer and use it in GitHub Desktop.
Save kurahaupo/508e9901617c990ff2b25940c26d4007 to your computer and use it in GitHub Desktop.
sponge.c
#define BUfSIZ*pick a number
, add #includes, and ADD ERROR HANDLING */
int main(){
char b[N]="/tmp/.spongeXXXXXX";
char*t=mktemp(b);
int f=open(t,O_RDWR|O_CREAT|O_EXCL,0);
unlink(t);
ssize_t n;
while((n=read(0,b,N))>0)
write(f,b,n);
lseek(f,0,SEEK_SET);
while((n=read(f,b,N))>0)
writewrite write(1,b,n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment