home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * $Source: /unixb/home/unixlib/source/unixlib37/src/time/c/RCS/gettod,v $
- * $Date: 1996/05/06 09:01:35 $
- * $Revision: 1.2 $
- * $State: Rel $
- * $Author: unixlib $
- *
- * $Log: gettod,v $
- * Revision 1.2 1996/05/06 09:01:35 unixlib
- * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
- * Saved for 3.7a release.
- *
- * Revision 1.1 1996/04/19 21:35:00 simon
- * Initial revision
- *
- ***************************************************************************/
-
- static const char rcs_id[] = "$Id: gettod,v 1.2 1996/05/06 09:01:35 unixlib Rel $";
-
- #include <errno.h>
- #include <time.h>
- #include <sys/time.h>
-
-
- /* The `gettimeofday' function returns the current date and time in
- the `struct timeval' structure indicated by TP. Information about
- the time zone is returned in the structure pointed at TZP. If the
- TZP argument is a null pointer, time zone information is ignored.
-
- The return value is `0' on success and `-1' on failure. The
- following `errno' error condition is defined for this function:
-
- `ENOSYS'
- The operating system does not support getting time zone
- information, and TZP is not a null pointer. The GNU
- operating system does not support using `struct timezone' to
- represent time zone information; that is an obsolete feature
- of 4.3 BSD. */
-
-
- /* Get the current time of day and timezone information,
- putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
- Returns 0 on success, -1 on errors. */
- int
- gettimeofday (struct timeval *tv, struct timezone *tz)
- {
- if (tv == NULL)
- {
- errno = EINVAL;
- return -1;
- }
-
- tv->tv_sec = time ((time_t *) NULL);
- tv->tv_usec = 0;
-
- if (tz != NULL)
- {
- const time_t timer = tv->tv_sec;
- const struct tm *tm;
-
- const int save_timezone = timezone;
- const struct tm saved_tz = __tz[0];
-
- tm = localtime (&timer);
-
- tz->tz_minuteswest = timezone / 60;
- tz->tz_dsttime = 0;
-
- timezone = save_timezone;
- __tz[0] = saved_tz;
-
- if (tm == NULL)
- return -1;
- }
-
- return 0;
- }
-