Subject: Strange open & f/stat behavior in 1.6Q
To: None <port-sparc@netbsd.org>
From: Steve Foster <steve@devidian.me.uk>
List: port-sparc
Date: 04/17/2003 09:45:19
OK so I'm probably going mad but I think that fstat and stat aren't working correctly within 1.6Q

The following test code should return the size of /etc/hosts:

# cat t.c
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>

int main()
{
        struct stat sbuf;
	int fd, ret;
	char afile[] = "/etc/hosts";
				
	fd = open(afile, O_RDONLY);
	ret = fstat(fd, &sbuf);
	printf("Size: %d\n", sbuf.st_size);
	printf("ret: %d\n", ret);
}
# gcc -o t t.c

Tracing the excution:

 18603 t        CALL  open(0xeffff7e0,0,0)
 18603 t        NAMI  "/etc/hosts"
 18603 t        RET   open 3
 18603 t        CALL  __fstat13(0x3,0xeffff7f8)
 18603 t        RET   __fstat13 0
 18603 t        CALL  __fstat13(0x1,0xeffff138)
 18603 t        RET   __fstat13 0
 18603 t        CALL  __sysctl(0xeffff050,0x2,0xeffff030,0xeffff034,0,0)
 18603 t        RET   __sysctl 0
 18603 t        CALL  readlink(0x101a8980,0xeffff0e8,0x3f)
 18603 t        NAMI  "/etc/malloc.conf"
 18603 t        RET   readlink -1 errno 2 No such file or directory
 18603 t        CALL  mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0)
 18603 t        RET   mmap 268713984/0x10044000
 18603 t        CALL  break(0x20f38)
 18603 t        RET   break 0
 18603 t        CALL  break(0x21f38)
 18603 t        RET   break 0
 18603 t        CALL  break(0x22000)
 18603 t        RET   break 0
 18603 t        CALL  break(0x32000)
 18603 t        RET   break 0
 18603 t        CALL  ioctl(0x1,TIOCGETA,0xeffff170)
 18603 t        RET   ioctl 0
 18603 t        CALL  write(0x1,0x22000,0x8)
 18603 t        GIO   fd 1 wrote 8 bytes
       "Size: 0
       "
 18603 t        RET   write 8
 18603 t        CALL  write(0x1,0x22000,0x7)
 18603 t        GIO   fd 1 wrote 7 bytes
       "ret: 0
       "
 18603 t        RET   write 7
 18603 t        CALL  exit(0x1)


Thoughts?

Steve