]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - tar/patches/tar-1.15.1-vfatTruncate.patch
Change file layout of the makefiles.
[people/ms/ipfire-3.x.git] / tar / patches / tar-1.15.1-vfatTruncate.patch
1 --- tar-1.15.1/src/system.c.vfatTruncate 2004-09-06 07:31:00.000000000 -0400
2 +++ tar-1.15.1/src/system.c 2006-02-03 14:40:51.000000000 -0500
3 @@ -272,8 +272,25 @@
4 int
5 sys_truncate (int fd)
6 {
7 + struct stat st;
8 off_t pos = lseek (fd, (off_t) 0, SEEK_CUR);
9 - return pos < 0 ? -1 : ftruncate (fd, pos);
10 +
11 + if ( pos < 0)
12 + return -1;
13 +
14 + if ( ftruncate(fd, pos) && errno == EPERM ) {
15 + /* wrapper around ftruncate:
16 + * ftruncate may fail to grow the size of a file with some OS and filesystem
17 + * combinations. Linux and vfat/fat is one example. If this is the case do
18 + * a write to grow the file to the desired length.
19 + */
20 + if( (fstat( fd, &st ) == -1) ||
21 + (st.st_size >= pos) ||
22 + (lseek( fd, pos - 1, SEEK_SET) == (off_t)-1) ||
23 + (write( fd, "\0", 1) == -1) )
24 + return -1;
25 + }
26 + return 0;
27 }
28
29 /* Return nonzero if NAME is the name of a regular file, or if the file