fastjar: Small _chsize/ftruncate fix

Aaron W. LaFramboise aaronavay62@aaronwl.com
Thu Jul 22 10:23:00 GMT 2004


DJ Delorie wrote:
> Using an undocumented function in libiberty, certainly when not also
> testing for it, is bad.

Perhaps all of the ftruncate code and workarounds and tricks might make
a good candidate to be added to libiberty?

> Why can't we use the age-old trick of write()ing zero bytes (not a
> single NUL byte) to truncate a file?

How does this work?  This doesnt seem to work:

#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main() {
  int fd = open("test.txt", O_RDWR);
  lseek(fd, 5, SEEK_SET);
  write(fd, 0, 0);
  close(fd);
  return 0;
}

Aaron W. LaFramboise



More information about the Java-patches mailing list