This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: sysdeps/unix/sysv/linux/lseek.c on ILP32 question
- From: Steve Ellcey <sellcey at caviumnetworks dot com>
- To: Andreas Schwab <schwab at linux-m68k dot org>
- Cc: libc-alpha <libc-alpha at sourceware dot org>
- Date: Tue, 21 Feb 2017 11:19:24 -0800
- Subject: Re: sysdeps/unix/sysv/linux/lseek.c on ILP32 question
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Steve dot Ellcey at cavium dot com;
- References: <1487701367.2866.118.camel@caviumnetworks.com> <87poibid66.fsf@linux-m68k.org>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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);
}