1 /******************************************************************************
3 *****************************************************************************/
5 #define _FILE_OFFSET_BITS 64
14 #define THRESHOLD 1023
18 fputs("sparse: create a sparse file from stdin\n\n", stderr
);
19 fputs("Usage: sparse [-v] [-c threshold] <output_file>\n\n", stderr
);
23 int main(int argc
, char ** argv
)
27 unsigned long threshold
= THRESHOLD
, seeks
=0;
30 while( (c
= getopt(argc
, argv
, "vhc:")) != -1 )
36 threshold
= strtoul(optarg
, NULL
, 10);
60 fo
= fopen(argv
[optind
], "w");
63 perror("fopen() failed");
67 while((c
= getc(stdin
)) != EOF
)
72 if(offset
> threshold
)
74 if(verbose
) fprintf(stderr
, "seek: offset CUR + %ld\n", offset
);
76 fseek(fo
, offset
, SEEK_CUR
);
81 for(i
=0; i
<offset
; i
++)
92 if(verbose
) fprintf(stderr
, "seek: offset CUR + %ld\n", offset
-1);
94 fseek(fo
, offset
-1, SEEK_CUR
);
100 if(verbose
) fprintf(stderr
, "total seeks: %lu\n", seeks
);