Mail Archives: djgpp-workers/2000/01/16/06:57:53
According to Eli Zaretskii:
>
> On Thu, 13 Jan 100, Martin Stromberg wrote:
>
> > The problem is that the INT21 call registers used for offset (input
> > and output) is totally only 32 bits, so we have this mapping:
> > register contents -> offset
> > 0 0
> > . .
> > . .
> > . .
> > 2^32-2 2^32-2
> > 2^32-1 -1 (failure)
> >
> > So my tests showed calling lseek(fd, -2, SEEK_SET) would result in the
> > file growing to maxsize (as if lseek(fd, 2^32-2 , SEEK_SET) was
> > called). Please try this and verify my findings, if possible.
>
> Unfortunately, I don't have any access to a system with FAT32 volumes
> (FAT32 considerably slows down disk I/O, so I routinely refuse
> Windows's suggestion to convert).
>
> So, if I understand correctly, you are suggesting to implement lseek
> of -2 as lseek of -3 followed by lseek of +1, is that right?
Eeeh... I don't understand what that would give us.
Consider this program:
#include <unistd.h>
#include <stdio.h>
#include <limits.h>
#include <fcntl.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
char ch;
char new_ch;
int fd;
long long ret;
if( argc != 2
|| sscanf(argv[1], "%c", &new_ch) != 1
)
{
fprintf(stderr, "%s: run like this '%s <char_to_write>'.\n",
argv[0], argv[0]
);
exit(1);
}
fd = open("g:/ggg.grr", O_RDWR|O_CREAT, S_IWUSR);
if( 0 <= fd )
{
printf("fd = %d.\n", fd);
lseek(fd, -3, SEEK_SET);
ret = read(fd, &ch, 1);
printf("1: ret = %lld, ch = %d.\n", ret, ch);
ret = write(fd, &new_ch, 1);
printf("1: ret = %lld.\n", ret);
}
return(0);
}
After running this, I'll have a file g:/ggg.grr that is 2^32-3 big!
Substitute -3 with any big value in [2^31, 2^32-3] and you'll get a
big file (I've tried a couple different ones).
If you use -2 instead of -3, the program behavs erratically. Every two
runs it will create a file of max size and the other runs it will
create a file of size 2!
Glass, Satyagraha,
MartinS
- Raw text -