Bug found in Solaris 2.4 include files - not fixed by fixinc.svr4

1 view
Skip to first unread message

Ronald F. Guilmette

unread,
Apr 30, 1995, 3:00:00 AM4/30/95
to

I've just been building a copylefted package (Samba, an NFS like server
system for PeeCee networks) and I've run across a small bug in one of the
Solaris 2.4 include files.

It appears that the Solaris 2.4 <sys/time.h> file fails to provide _any_
declaration of gettimeofday/settimeofday (let alone prototyped declarations)
unless __cplusplus is defined.

Looking in the relevant part of <sys/time.h> this looks like a mere
slip-up to me. Thus, I believe that this is something which fixinc.svr4
ought to be made to fix.

I don't have the time just now to do the necessary patch for fixinc.svr4,
but I can show anyone who might like to fix this problem what has to be
done. It's simple. The following diff illustrates the change that
fixinc.svr4 ought to be making to <sys/time.h>:

*** time.h- Sun Apr 30 12:50:59 1995
--- time.h Sun Apr 30 12:51:29 1995
***************
*** 218,225 ****
int setitimer(int, struct itimerval *, struct itimerval *);

- #ifdef __cplusplus
int gettimeofday(struct timeval *, void *);
int settimeofday(struct timeval *, void *);
- #endif

hrtime_t gethrtime(void);
--- 218,223 ----

-- Ron Guilmette, Sunnyvale, CA -------- RG Consulting ---------------------
---- E-mail: r...@segfault.us.com --------Purveyors of Compiler Test Suites -
---- finger: r...@rahul.net -------------------------------------------------

Paul Eggert

unread,
May 1, 1995, 3:00:00 AM5/1/95
to

Date: Sun, 30 Apr 1995 23:28:20 -0700
From: "Ronald F. Guilmette" <r...@segfault.us.com>

Surely there _is_ one (and only one) ``correct'' prototype for whatever
the heck is actually in the library under the name ``gettimeofday''.

Unfortunately I think that there are two different prototypes; which
one is correct depends on the context. In the future, I think the
two-argument prototype will be correct; but right now, according to
the Solaris 2.4 documentation, the one-argument prototype is correct.

Whatever prototype that is, it should be present in <sys/time.h>. and
it doesn't make any sense at all to have it in there for only C and
not C++ or vise versa.

It isn't entirely senseless. The Solaris 2.4 documentation does not
describe the C++ binding to gettimeofday; it describes only the C
binding. So if Sun wants to switch to the two-argument gettimeofday
eventually, but (due to compatibility concerns) can't change its C
binding, then it makes a weird sort of sense for Sun to omit the
prototype for C only.

Surely it is the same damn function regardless of which language
you call it from, yes?

I believe so. But since the function always ignores its second
argument, either prototype will do. The problem is that if you put in
one prototype, then programs assuming the _other_ prototype won't compile.


Any portable application will have to worry about one- vs two-
argument gettimeofday anyway, since some SVR4 systems put a
one-argument gettimeofday prototype into their sys/time.h.
The autoconf way to work around this problem is to put a line like the
following into configure.in (the following line is taken from Python):

AC_CHECK_FUNC(gettimeofday, AC_TRY_COMPILE([#include <sys/time.h>], [gettimeofday((struct timeval*)0,(struct timezone*)0);], ,AC_DEFINE(GETTIMEOFDAY_NO_TZ)))

Perhaps you can talk the Samba folks into adding this to their
configuration options.

Paul Eggert

unread,
May 1, 1995, 3:00:00 AM5/1/95
to
From: r...@segfault.US.COM (Ronald F. Guilmette)
Date: 30 Apr 1995 19:43:33 -0400

It appears that the Solaris 2.4 <sys/time.h> file fails to provide _any_
declaration of gettimeofday/settimeofday (let alone prototyped declarations)
unless __cplusplus is defined.

I think this omission was on purpose, and I'm not sure it's wise to change it.

Traditional BSD defined a two-argument version of gettimeofday in which
the 2nd argument was the time zone. This 2nd argument is now obsolete
(modern OSes don't have the time zone in the kernel), so SVR4.0 decided
to remove the 2nd arg (and this is how gettimeofday is documented in
the Solaris 2.4 man page). However, this made a lot of programs not
compile, and I've heard X/Open has decided to put the second argument
back (even though it's now useless and ignored), so that those old
programs will compile. My guess is that some time in the near future
Sun will put a two-argument version in the header to be X/Open
compatible.

I'd guess Sun is omitting the declaration to make it easier to compile
both (1) programs that assume current documented Solaris 2.4 behavior,
and (2) programs that assume two-argument gettimeofday. My advice for
GCC is to follow Sun's lead and leave gettimeofday alone.

Reply all
Reply to author
Forward
0 new messages