]>
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. */
38 fprintf (stderr
, "%s: ", progname
);
40 vfprintf (stderr
, fmt
, ap
);
42 fprintf (stderr
, "\n");
46 mkhole (int fd
, off_t displ
)
48 if (displ
= lseek (fd
, displ
, SEEK_CUR
) == -1)
53 ftruncate (fd
, lseek (fd
, 0, SEEK_CUR
));
57 mksparse (int fd
, off_t displ
, char *marks
)
61 for (; *marks
; marks
++)
63 memset (buffer
, *marks
, buffer_size
);
64 if (write(fd
, buffer
, buffer_size
) != buffer_size
)
70 if (lseek (fd
, displ
, SEEK_CUR
) == -1)
81 printf ("Usage: mksparse filename blocksize disp letters [disp letters...] [disp]\n");
86 xlat_suffix (off_t
*vp
, char *p
)
112 main (int argc
, char **argv
)
119 progname
= strrchr (argv
[0], '/');
128 fd
= open (argv
[1], O_CREAT
|O_TRUNC
|O_RDWR
, 0644);
130 die ("cannot open %s", argv
[1]);
132 n
= strtoul (argv
[2], &p
, 0);
133 if (n
<= 0 || (*p
&& xlat_suffix (&n
, p
)))
134 die ("Invalid buffer size: %s", argv
[2]);
136 buffer
= malloc (buffer_size
);
138 die ("Not enough memory");
140 for (i
= 3; i
< argc
; i
+= 2)
144 displ
= strtoul (argv
[i
], &p
, 0);
145 if (displ
< 0 || (*p
&& xlat_suffix (&displ
, p
)))
146 die ("Invalid displacement: %s", argv
[i
]);
154 mksparse (fd
, displ
, argv
[i
+1]);
This page took 0.042758 seconds and 4 git commands to generate.