[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lib/ftruncate bug and patch for GNU tar 1.13.25
From: |
Bruce Lilly |
Subject: |
lib/ftruncate bug and patch for GNU tar 1.13.25 |
Date: |
Tue, 27 Aug 2002 17:27:43 -0400 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 |
The ftruncate function in the lib subdirectory of
GNU tar 1.13.25 doesn't work for SVR2.2 and earlier.
The attached patch corrects that deficiency.
OTOH, one wonders why ftruncate() is used at all in
GNU tar, since
a) it is always called with a length argument of 0
and
b) in case a, it would be simpler, more efficient,
and more portable to have open()ed the file with
O_TRUNC in the first place.
*** lib/ftruncate.c.or Mon Aug 26 04:20:42 2002
--- lib/ftruncate.c Mon Aug 26 05:08:31 2002
***************
*** 83,93 ****
extern int errno;
# endif
int
ftruncate (int fd, off_t length)
{
! errno = EIO;
! return -1;
}
# endif /* not HAVE_CHSIZE */
--- 83,107 ----
extern int errno;
# endif
+ #include <stdio.h>
+
int
ftruncate (int fd, off_t length)
{
! if (length) {
! errno = EIO;
! return -1;
! } else {
! int fd2;
! FILE *f;
!
! if ((fd2 = dup(fd)) >= 0)
! if ((f = fdopen(fd2, "w")) != NULL)
! fclose(f);
! else
! close(fd2);
! return 0;
! }
}
# endif /* not HAVE_CHSIZE */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- lib/ftruncate bug and patch for GNU tar 1.13.25,
Bruce Lilly <=