]>
Dogcows Code - chaz/tar/blob - tests/mksparse.c
1 /* This file is part of GNU tar test suite
3 Copyright (C) 2004 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any later
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 static void die (char const *, ...) __attribute__ ((noreturn
,
34 format (printf
, 1, 2)));
36 die (char const *fmt
, ...)
40 fprintf (stderr
, "%s: ", progname
);
42 vfprintf (stderr
, fmt
, ap
);
44 fprintf (stderr
, "\n");
49 mkhole (int fd
, off_t displ
)
51 if (lseek (fd
, displ
, SEEK_CUR
) == -1)
56 ftruncate (fd
, lseek (fd
, 0, SEEK_CUR
));
60 mksparse (int fd
, off_t displ
, char *marks
)
62 for (; *marks
; marks
++)
64 memset (buffer
, *marks
, buffer_size
);
65 if (write(fd
, buffer
, buffer_size
) != buffer_size
)
71 if (lseek (fd
, displ
, SEEK_CUR
) == -1)
79 static void usage (void) __attribute__ ((noreturn
));
83 printf ("Usage: mksparse filename blocksize disp letters [disp letters...] [disp]\n");
88 xlat_suffix (off_t
*vp
, char *p
)
114 main (int argc
, char **argv
)
121 progname
= strrchr (argv
[0], '/');
130 fd
= open (argv
[1], O_CREAT
|O_TRUNC
|O_RDWR
, 0644);
132 die ("cannot open %s", argv
[1]);
134 n
= strtoul (argv
[2], &p
, 0);
135 if (n
<= 0 || (*p
&& xlat_suffix (&n
, p
)))
136 die ("Invalid buffer size: %s", argv
[2]);
138 buffer
= malloc (buffer_size
);
140 die ("Not enough memory");
142 for (i
= 3; i
< argc
; i
+= 2)
146 displ
= strtoul (argv
[i
], &p
, 0);
147 if (displ
< 0 || (*p
&& xlat_suffix (&displ
, p
)))
148 die ("Invalid displacement: %s", argv
[i
]);
156 mksparse (fd
, displ
, argv
[i
+1]);
This page took 0.038994 seconds and 4 git commands to generate.