Subject: port-alpha/5154: 64 bit clean problem with struct stat on NetBSD/alpha
To: None <>
From: None <>
List: netbsd-bugs
Date: 03/12/1998 15:37:12
>Number:         5154
>Category:       port-alpha
>Synopsis:       sizeof(struct stat) changes with definition of _POSIX_SOURCE
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 12 13:50:01 1998
>Originator:     Eric Schnoebelen
Central Iowa (Model) Railroad
>Release:        NetBSD 1.3

System: NetBSD nicetry 1.3 NetBSD 1.3 (GENERIC) #0: Tue Dec 30 23:32:12 PST 1997 cjs@bishop:/u1/cjs/co/branch/src/sys/arch/alpha/compile/GENERIC alpha

	On the alpha processor platform, 
		sizeof(time_t) == 4
		sizeof(long) == 8
		sizeof(struct timespec) == 16

	In struct stat, the timestamp's are defined as either struct
timespec's, or pairs of time_t/long's, dending upon the preprocessor

		sizeof(struct timespec) != (sizeof(long) + sizeof(time_t)	

	This causes the size of the stat structure to change depending
upon the preprocessor flag _POSIX_SOURCE.  The changing size of this stucture
causes references to st_size to return a truly bogus number (the low
order bits of the clock) when _POSIX_SOURCE is defined, and the program
is compiled on the alpha processor.

----------------------[cut here]-------------------------------
#	demonstrate a problem with the size of the stat structure
#	changing on the alpha processor platform
#	Eric Schnoebelen --, 12 March, 1998
cat >stat-test.c <<-_EOF_
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

main(int argc, char **argv)
	int i;
	struct stat st;

	for(i = 1; i < argc; i++){
		if (stat(argv[i], &st) != 0)
			return 1;

		printf("%s:	%ld\n", argv[i], st.st_size);

	printf("sizeof(long): %d\n", sizeof(long));
	printf("sizeof(time_t): %d\n", sizeof(time_t));
	printf("sizeof(struct timespec): %d\n", sizeof(struct timespec));
	printf("sizeof(struct stat): %d\n", sizeof(struct stat));

cc -o stat-test stat-test.c
./stat-test stat-test stat-test.c
cc -D_POSIX_SOURCE -o stat-test stat-test.c
./stat-test stat-test stat-test.c
exit 0
----------------------[cut here]-------------------------------
	Define struct timespec in terms of time_t, and the modify struct
stat so that it uses time_t for both bits of time information for atime,
ctime and mtime.