delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/06/20/19:36:23

From: fox AT cat DOT nyu DOT edu (David Fox)
Subject: Re: lseek past EOF doesn't append zeros under Windows 95
20 Jun 1998 19:36:23 -0700 :
Message-ID: <y5ahg1goyqn.fsf.cygnus.gnu-win32@dsf.net>
References: <y5a3ed0r4h5 DOT fsf_-_ AT dsf DOT net>
To: gnu-win32 AT cygnus DOT com
Cc: beshers AT cs DOT columbia DOT edu

David Fox <fox AT cat DOT nyu DOT edu> writes:

> 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?

Here is a wrapper for lseek that works around this problem:

off_t zlseek(int fildes, off_t offset, int whence)
{
  off_t end = lseek(fildes, 0L, SEEK_END);
  if (end < offset) {
    char buf[offset-end];
    memset(buf, 0, offset - end);
    write(fildes, buf, offset - end);
  }
  return lseek(fildes, offset, whence);
}

-- 
David Fox	   http://www.cat.nyu.edu/fox		xoF divaD
NYU Media Research Lab   fox AT cat DOT nyu DOT edu   baL hcraeseR aideM UYN
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019