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 #define _LARGEFILE_SOURCE
13 #define _LARGEFILE64_SOURCE
18 #include <sys/types.h>
23 int full_read(int fd, char *buf, size_t count)
29 got = read(fd, buf, count);
31 if ((errno == EINTR) || (errno == EAGAIN))
33 return total ? total : -1;
48 int main(int argc, char **argv)
54 fprintf(stderr, "Usage: make-sparse out-file\n");
57 fd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0777);
63 got = full_read(0, buf, sizeof(buf));
66 if (got == sizeof(buf)) {
67 for (i=0; i < sizeof(buf); i++)
70 if (i == sizeof(buf)) {
71 lseek(fd, sizeof(buf), SEEK_CUR);