2 * make-sparse.c --- make a sparse file from stdin
4 * Copyright 2004 by Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
12 #ifndef _LARGEFILE_SOURCE
13 #define _LARGEFILE_SOURCE
15 #ifndef _LARGEFILE64_SOURCE
16 #define _LARGEFILE64_SOURCE
22 #include <sys/types.h>
27 int full_read(int fd, char *buf, size_t count)
33 got = read(fd, buf, count);
35 if ((errno == EINTR) || (errno == EAGAIN))
37 return total ? total : -1;
52 int main(int argc, char **argv)
59 fprintf(stderr, "Usage: make-sparse out-file\n");
62 fd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0777);
68 got = full_read(0, buf, sizeof(buf));
71 if (got == sizeof(buf)) {
72 for (i=0; i < sizeof(buf); i++)
75 if (i == sizeof(buf)) {
76 lseek(fd, sizeof(buf), SEEK_CUR);
85 lseek(fd, -1, SEEK_CUR);