[14540] in Athena Bugs

home help back first fref pref prev next nref lref last post

sun4 8.0A: sunsoft.new and /usr/include/sys/timeb.h

daemon@ATHENA.MIT.EDU (Ezra Peisach)
Tue Aug 13 15:39:07 1996

To: bugs@MIT.EDU
Date: Tue, 13 Aug 1996 15:39:03 EDT
From: Ezra Peisach <epeisach@MIT.EDU>

System name:		dcl
Type and version:	SPARC/5 8.0A (1 update(s) to same version)
Display type:		cgthree

What were you trying to do?
Compile and use a program which uses a struct timeb

What's wrong:
Unaligned errors

What should have happened:
Program should work.

Please describe any relevant documentation references:
Personally - I think this is a fault of the Sun include file
sys/timeb.h.

Compile this program and get a core dump
------------------------------------------
#include <sys/time.h>
#include <sys/timeb.h>

main() 
{
  time_t t;
  struct timeb foo;

  /*  time(&foo.time);*/
  t = time((time_t *)0);
  foo.time = t;

printf("Time %d\n", t);
}

------------------------------------------------------------------

a) If I use suncc -malign2 - everything works
b) Gcc works fine with this file.
c) I suspect that the problem stems from the fact that
/usr/include/sys/timeb.h has the pack pragma - which causes the
structure to not be aligned on a 4 byte boundary. Either suncc is
botching it by not realizing that it will need to be careful when
accessing the elements of the structure - or the header file should not
have the pragma....

#if defined(__STDC__)
#pragma	pack(2)
#endif

/*
 * Structure returned by ftime system call
 */
struct timeb {
	time_t	time;		/* time, seconds since the epoch */
	unsigned short millitm;	/* 1000 msec of additional accuracy */
	short	timezone;	/* timezone, minutes west of GMT */
	short	dstflag;	/* daylight savings when appropriate? */
};

#if defined(__STDC__)
#pragma	pack()
#endif


home help back first fref pref prev next nref lref last post