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
)
55 fprintf(stderr
, "Usage: make-sparse out-file\n");
58 fd
= open(argv
[1], O_WRONLY
|O_CREAT
|O_TRUNC
|O_LARGEFILE
, 0777);
64 got
= full_read(0, buf
, sizeof(buf
));
67 if (got
== sizeof(buf
)) {
68 for (i
=0; i
< sizeof(buf
); i
++)
71 if (i
== sizeof(buf
)) {
72 lseek(fd
, sizeof(buf
), SEEK_CUR
);
81 lseek(fd
, -1, SEEK_CUR
);