*BSD News Article 83877


Return to BSD News archive

Newsgroups: comp.unix.solaris,comp.unix.bsd.misc
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.Hawaii.Edu!news.caldera.com!enews.sgi.com!EU.net!sun4nl!cs.vu.nl!kjb
From: kjb@cs.vu.nl (Kees J Bot)
Subject: Re: Solaris 2.6
Nntp-Posting-Host: hornet.cs.vu.nl
References: <32986299.AC7@mail.esrin.esa.it> <57djlg$bks@agate.berkeley.edu>   <57dkbq$bsr@panix2.panix.com> <casper.329abb76@mail.fwi.uva.nl>   <57ej3a$7ij@panix2.panix.com> <casper.329ae8f2@mail.fwi.uva.nl> <57hhcp$kp9@innocence.interface-business.de>
Sender: news@cs.vu.nl
Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
Date: Fri, 29 Nov 1996 10:39:30 GMT
Message-ID: <E1Mo9u.9oJ@cs.vu.nl>
Distribution: inet
Lines: 42
Xref: euryale.cc.adfa.oz.au comp.unix.solaris:90853 comp.unix.bsd.misc:1627

j@ida.interface-business.de (J Wunsch) writes:

[snip]
>int
>main(void)
>{
>        int fd;
>        off_t o;
>        ssize_t x;
>        char b[200];

>        if ((fd = open("foobar", O_RDWR|O_CREAT, 0666)) == -1)
>                return 1;
>        write(fd, s, sizeof s - 1);
>        lseek(fd, 6, SEEK_SET);
[snip]

Note that SEEK_SET is 0, so this is compiled to something that looks
like this:

	push	0		! SEEK_SET
	push	0		! High 32 bits of (off_t) 6
	push	6		! Low 32 bits of (off_t) 6
	push	-4(ebp)		! Fd most likely
	call	_lseek
	add	esp, 4*4

If an old library assumes that off_t is 32 bits then it will use the
high half of the offset argument that was pushed above.  This high half
is conveniently zero, the same as SEEK_SET.

Could you try again with the above lseek() call replaced by:

        lseek(fd, 3, SEEK_SET);
        lseek(fd, 3, SEEK_CUR);

SEEK_CUR is 1, so my guess is that the program linked against the old
library will print "lo World\n", because it sees a 0 as the third
argument of the second lseek().
--
	                        Kees J. Bot  (kjb@cs.vu.nl)
	              Systems Programmer, Vrije Universiteit Amsterdam