Subject: lseek past EOF doesn't append zeros under Windows 95
From: [email-masked] (David Fox)

20 Jun 1998 05:15:24 -0700
Message-ID: <[email-masked]>
References: [email-masked] (David Fox)
To: [email-masked]
Cc: [email-masked]

The documentation for lseek states

       The lseek function allows the file offset to be set beyond
       the  end  of the existing end-of-file of the file. If data
       is later written at this point, subsequent  reads  of  the
       data in the gap return bytes of zeros (until data is actu-
       ally written into the gap).

but under Windows 95 the cygwin32 package does not behave this
way.  The gap is filled with garbage.  One package that depends
on the zeroing behavior is db-1.86.  Here is a test program:

#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

main(int ac, char *av[])
{
  int size = atoi(av[1]);
  int fd = open("seektest", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
  char buffer[size];
  int count;
  count = lseek(fd, size, SEEK_SET);
  printf("Attempt seek to %d, result %d\n", size, count);
  count = write(fd, buffer, size);
  printf("Wrote %d of %d character(s)\n", count, size);
  count = lseek(fd, 0, SEEK_SET);
  printf("Attempt seek to %d, result %d\n", size, count);
  count = read(fd, buffer, size);
  printf("Read %d of %d characters\n", count, size);
}

Run this with the argument 100 and you will get a two hundred byte
file filled with garbage.  Under Unix or cygwin32_nt the first hundred
bytes will be zero.  Any advice?
-- 
David Fox	   http://www.cat.nyu.edu/fox		xoF divaD
NYU Media Research Lab   [email-masked]   baL hcraeseR aideM UYN
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".