[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: time returns -1



On Thu, 9 Nov 1995, Richard Kettlewell wrote:

> Dale Scheetz writes:
> 
> >Thanks for the pointers James. It was a big help. I probably should
> >have thought of errno on my own. The man page on time is very
> >cryptic. The only technical information it provides is:
> >
> >If t is not null, the return value is also stored in the memory
> >pointed to by t.
> 
> Just before that - on mine - it says:
> 
>        time returns the time since 00:00:00 GMT, January 1, 1970,
>        measured in seconds.

Yes, I guess that does qualify as technical info. I saw it as a 
description of the function.

> 
> >What it fails to tell you is, if you pass time a null pointer (t) it
> >will return an error instead of the time.
> 
> If time() behaves this way then fails to follow the C standard, does
> it not?  The following works fine on my home machine (0.93R5,
> downloaded several months ago and spiced with occasional upgrades):
> 
>     #include <time.h>
>     #include <stdio.h>
> 
>     main()
>     {
> 	time_t t;
> 
> 	t = time(NULL);
> 	printf("%ld\n", (long)t);
> 	return 0;
>     }
> 
> If this produces output other than the current time (probably around
> 810000000) then I believe you've found a bug.
> 
Well, Richard, my code looks a little different, but I think the net 
result is the same:

function()
	{
	time_t *jt;
	time_t jtime;
	

	jtime = time(jt);
	printf("jtime = %i", (int)jtime);
	}

This code prints out:

jtime = -1

if I put the line:

jt = malloc(sizeof(time_t));

just before the call to time I get:

jtime = 854563279

Memory says that my first code worked fine in R5 also. Can someone check 
this out on an R6 machine? If this is a bug, how do I report it?

Thanks,

Dale


Reply to: