This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fastjar: Small _chsize/ftruncate fix


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]