new
[libcurl.git] / lib / timeval.c
blobeabd754fc68eb1fe2abddd444ad98c8f6df44d3d
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * The contents of this file are subject to the Mozilla Public License
9 * Version 1.0 (the "License"); you may not use this file except in
10 * compliance with the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS"
14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15 * License for the specific language governing rights and limitations
16 * under the License.
18 * The Original Code is Curl.
20 * The Initial Developer of the Original Code is Daniel Stenberg.
22 * Portions created by the Initial Developer are Copyright (C) 1998.
23 * All Rights Reserved.
25 * ------------------------------------------------------------
26 * Main author:
27 * - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
29 * http://curl.haxx.nu
31 * $Source: /cvsroot/curl/curl/lib/timeval.c,v $
32 * $Revision: 1.1.1.1 $
33 * $Date: 1999-12-29 14:21:38 $
34 * $Author: bagder $
35 * $State: Exp $
36 * $Locker: $
38 * ------------------------------------------------------------
39 ****************************************************************************/
41 #ifdef WIN32
42 #include <windows.h>
43 #endif
44 #include "timeval.h"
46 #ifndef HAVE_GETTIMEOFDAY
48 #ifdef WIN32
49 int
50 gettimeofday (struct timeval *tp, void *nothing)
52 SYSTEMTIME st;
53 time_t tt;
54 struct tm tmtm;
55 /* mktime converts local to UTC */
56 GetLocalTime (&st);
57 tmtm.tm_sec = st.wSecond;
58 tmtm.tm_min = st.wMinute;
59 tmtm.tm_hour = st.wHour;
60 tmtm.tm_mday = st.wDay;
61 tmtm.tm_mon = st.wMonth - 1;
62 tmtm.tm_year = st.wYear - 1900;
63 tmtm.tm_isdst = -1;
64 tt = mktime (&tmtm);
65 tp->tv_sec = tt;
66 tp->tv_usec = st.wMilliseconds * 1000;
67 return 1;
69 #define HAVE_GETTIMEOFDAY
70 #endif
71 #endif
73 struct timeval tvnow ()
75 struct timeval now;
76 #ifdef HAVE_GETTIMEOFDAY
77 gettimeofday (&now, NULL);
78 #else
79 now.tv_sec = (long) time(NULL);
80 now.tv_usec = 0;
81 #endif
82 return now;
85 double tvdiff (struct timeval t1, struct timeval t2)
87 return (double)(t1.tv_sec - t2.tv_sec) + ((t1.tv_usec-t2.tv_usec)/1000000.0);
90 long tvlong (struct timeval t1)
92 return t1.tv_sec;