summaryrefslogtreecommitdiff
path: root/apps/JAWS/clients/WebSTONE/src/gettimeofday.c
blob: 7d5614b8189df865c5a6508a5e88805c615d3460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

/*
 *  This file defines functions that are required for unix compatibility.
 *
 *  These functions are not available in the Microsoft C/C++ Run Time 
 *  and the Win32 API.
 *
 *  The following functions list may not be complete
 *  
 *  FUNCTIONS:
 *     SHARED   _gettimeofday
 *
 */


#include <windows.h>
#include <errno.h>
#include <winsock.h>		/* For definition of "timeval" structure */
#include <sys/timeb.h>		/* For prototype of "_ftime()" */


/*
 * gettimeofday() --  gets the current time in elapsed seconds and
 *                     microsends since GMT Jan 1, 1970.
 *
 * ARGUMENTS: - Pointer to a timeval struct to return the time into
 *
 * RETURN CODES: -  0 on success
 *                 -1 on failure
 */
int gettimeofday(curTimeP)
    struct timeval *curTimeP;
{
struct _timeb  localTime;

    if (curTimeP == (struct timeval *) NULL) {
	 errno = EFAULT;
	 return (-1);
    }

   /*
    *  Compute the elapsed time since Jan 1, 1970 by first
    *  obtaining the elapsed time from the system using the
    *  _ftime(..) call and then convert to the "timeval"
    *  equivalent.
    */

    _ftime(&localTime);

    curTimeP->tv_sec  = localTime.time + localTime.timezone;
    curTimeP->tv_usec = localTime.millitm * 1000;

    return(0);
}