This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Bug in TIME function
- From: Kaz Kylheku <920-082-4242 at kylheku dot com>
- To: cygwin at cygwin dot com
- Date: Thu, 12 Sep 2019 11:16:27 -0700
- Subject: Re: Bug in TIME function
- References: <009d01d56994$a8065040$f812f0c0$@twcny.rr.com>
On 2019-09-12 11:05, tlake@twcny.rr.com wrote:
The code below returns -1. It shouldn't.
Says who?
I don't see anything in the specification which says that a null pointer
argument is allowed:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/times.html
Passing a null pointer to an ISO C or POSIX library function results in
undefined behavior,
except where it is documented otherwise.
GNU/Linux (specifically the Glibc implementation of libc) also doesn't
document any such extension (being able to pass a null pointer to
times).
So even in light of the goal of Cygwin providing GNU/Linux compatibility
beyond POSIX, there is no justification for supporting times(0).
#include <sys/times.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("return value %ld\n", (long)times((struct tms*)0));
The pointer cast is not required here; you have a prototype of
the times function in scope; the equivalent times(0) will give you
the undefined behavior you're asking for.
return 0;
}
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple