OSDN Git Service

time: Improve C99 compliance
authorJim Huang <jim.huang@linaro.org>
Thu, 16 Jun 2011 14:40:10 +0000 (22:40 +0800)
committerJim Huang <jserv@0xlab.org>
Wed, 22 Jun 2011 08:44:45 +0000 (16:44 +0800)
Quote from Linux Programmer's Manual:
  "If t is non-NULL, the return value is also stored in the memory
   pointed to by t."

Change-Id: I8cb66b67e5f34c536ce2f0db76a6dc337c42ea3f
Signed-off-by: Jim Huang <jserv@0xlab.org>
libc/unistd/time.c

index 13d7366..7b450c7 100644 (file)
@@ -34,12 +34,15 @@ time_t
 time(time_t *t)
 {
        struct timeval tt;
+       time_t ret;
 
        if (gettimeofday(&tt, (struct timezone *)0) < 0)
-               return (-1);
-       if (t)
-               *t = (time_t)tt.tv_sec;
-       return (tt.tv_sec);
+               ret = -1;
+       else
+               ret = tt.tv_sec;
+       if (t != NULL)
+               *t = ret;
+       return ret;
 }