sponge.c (594B)
1 /* See LICENSE file for copyright and license details. */ 2 #include <stdio.h> 3 #include <stdlib.h> 4 5 #include "text.h" 6 #include "util.h" 7 8 static void 9 usage(void) 10 { 11 eprintf("usage: sponge file\n"); 12 } 13 14 int 15 main(int argc, char *argv[]) 16 { 17 FILE *fp, *tmpfp; 18 19 ARGBEGIN { 20 default: 21 usage(); 22 } ARGEND; 23 24 if (argc != 1) 25 usage(); 26 27 if (!(tmpfp = tmpfile())) 28 eprintf("tmpfile:"); 29 30 concat(stdin, "<stdin>", tmpfp, "<tmpfile>"); 31 rewind(tmpfp); 32 33 if (!(fp = fopen(argv[0], "w"))) 34 eprintf("fopen %s:", argv[0]); 35 concat(tmpfp, "<tmpfile>", fp, argv[0]); 36 37 fclose(fp); 38 fclose(tmpfp); 39 40 return 0; 41 }