Why time instead of gettimeofday?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Why time instead of gettimeofday?

John D. Ramsdell-2
I built a cross-compiler using binutils, gcc, and newlib
<http://sources.redhat.com/newlib/>, and then used it to compile the
lua program.  The program fails to link because it refers to the
time(2) library call.  This call is obsoleted by gettimeofday(2).  Why
not use it instead of time(2)?  Are there environments in which time
is available, but not gettimeofday?

John
Reply | Threaded
Open this post in threaded view
|

Re: Why time instead of gettimeofday?

Luiz Henrique de Figueiredo
gettimeofday is not ANSI C, time is.
--lhf
Reply | Threaded
Open this post in threaded view
|

Re: Why time instead of gettimeofday?

Andreas Stenius-2
In reply to this post by John D. Ramsdell-2
John D. Ramsdell skrev:
>  Are there environments in which time
> is available, but not gettimeofday?
>  
Yes, I'm one of those..

Reply | Threaded
Open this post in threaded view
|

Re: Why time instead of gettimeofday?

John D. Ramsdell-2
In reply to this post by John D. Ramsdell-2
[hidden email] writes:

> gettimeofday is not ANSI C, time is.
> --lhf

Okay then I'll submit a bug report to the newlib maintainers.  Thanks.

John
Reply | Threaded
Open this post in threaded view
|

Re: Why time instead of gettimeofday?

John D. Ramsdell-2
In reply to this post by John D. Ramsdell-2
You were right.  My original bug report was misdirected.  The lack of
time(2) being fixed by a newlib maintainer.

John

Jeff Johnston <[hidden email]> writes:

> Hmm, the libc/time/time.c code checks for the existence of
> HAVE_GETTIMEOFDAY flag and if not present, it doesn't compile the
> entire time function.  The time function is ANSI and ifdefing it out
> is wrong. It also doesn't make sense to check for the syscall before
> calling it as it is one of the basic syscalls (stubbed in libnosys to
> return -1). I will fix this.  In your case, you will see time() return
> -1 when libnosys provides the syscall.
>
> -- Jeff J.