This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: sysdeps/unix/sysv/linux/lseek.c on ILP32 question


On Tue, 2017-02-21 at 19:58 +0100, Andreas Schwab wrote:
> 
> > And I am not sure the conversion from offset to the two llseek
> > arguments is correct for both LP64 and ILP32 modes when offset is
> > negative.
> This isn't used for LP64, which won't have _llseek.
> 
> Andreas.

OK, that makes sense.  But there is still a problem with the test.c
example I attached to the email (attached here too).  I just tried this
on x86_64 and I get the same output difference that I see on aarch64.
Note that I am not even using the latest glibc, I am just using the
default one on my Ubuntu 16.04 system.  Maybe my test case is bad?
If so, I don't see where the problem is.

Steve Ellcey
sellcey@cavium.com

x86 with -m64 prints:

fd = 3
val(1) = 0
val(2) = 40
val(3) = 0
val(4) = 40
val(5) = 0


x86 with -mx32 prints:

fd = 3
val(1) = 0
val(2) = 40
val(3) = 0
val(4) = 0
Gee, let's write something in the file!

fu�
41
val(5) = 0


Maybe my test case is bogus but I am not sure why.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>

char crmsg[] = "Gee, let's write something in the file!\n";

int main()
{
	char fname[1024], buf[1024];
	int x, fd, val;

	strcpy(fname,"/tmp/foobar932");
	fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
	printf("fd = %d\n", fd);

        x = 0;
        val = lseek(fd, x, 0);
        printf("val(1) = %d\n", val);

        val = write(fd, crmsg, sizeof(crmsg) - 1);
        printf("val(2) = %d\n", val);

	/* 1 == SEEK_CUR */
        val = lseek(fd, -(sizeof(crmsg) - 1), 1);
        printf("val(3) = %d\n", val);

        val = read(fd, buf, sizeof(crmsg) - 1);
        printf("val(4) = %d\n", val);

        if (strncmp(crmsg, buf, sizeof(crmsg) - 1))
                {
                printf("%s\n", crmsg);
                printf("%s\n", buf);
                printf("%d\n", (int) sizeof(crmsg));
                }
        val = close(fd);
	printf("val(5) = %d\n", val);
}


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