~ubuntu-branches/ubuntu/warty/curl/warty-security

« back to all changes in this revision

Viewing changes to lib/timeval.c

  • Committer: Bazaar Package Importer
  • Author(s): Domenico Andreoli
  • Date: 2004-06-04 19:09:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040604190925-wy048bp31320r2z6
Tags: 7.12.0.is.7.11.2-1
* Reverted to version 7.11.2 (closes: #252348).
* Disabled support for libidn (closes: #252367). This is to leave
  curl in unstable as much similar as possible to the one in testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 *                                  _   _ ____  _     
3
 
 *  Project                     ___| | | |  _ \| |    
4
 
 *                             / __| | | | |_) | |    
5
 
 *                            | (__| |_| |  _ <| |___ 
 
1
/***************************************************************************
 
2
 *                                  _   _ ____  _
 
3
 *  Project                     ___| | | |  _ \| |
 
4
 *                             / __| | | | |_) | |
 
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
 
 * In order to be useful for every potential user, curl and libcurl are
11
 
 * dual-licensed under the MPL and the MIT/X-derivate licenses.
 
10
 * This software is licensed as described in the file COPYING, which
 
11
 * you should have received as part of this distribution. The terms
 
12
 * are also available at http://curl.haxx.se/docs/copyright.html.
12
13
 *
13
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
14
15
 * copies of the Software, and permit persons to whom the Software is
15
 
 * furnished to do so, under the terms of the MPL or the MIT/X-derivate
16
 
 * licenses. You may pick one of these licenses.
 
16
 * furnished to do so, under the terms of the COPYING file.
17
17
 *
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: timeval.c,v 1.11 2001/11/12 22:10:09 bagder Exp $
22
 
 *****************************************************************************/
 
21
 * $Id: timeval.c,v 1.23 2004/04/09 09:36:31 bagder Exp $
 
22
 ***************************************************************************/
23
23
 
24
 
#ifdef WIN32
25
 
#include <windows.h>
26
 
#endif
27
24
#include "timeval.h"
28
25
 
29
26
#ifndef HAVE_GETTIMEOFDAY
30
27
 
31
28
#ifdef WIN32
32
 
int
33
 
gettimeofday (struct timeval *tp, void *nothing)
34
 
{
35
 
 SYSTEMTIME st;
36
 
 time_t tt;
37
 
 struct tm tmtm;
38
 
 /* mktime converts local to UTC */
39
 
 GetLocalTime (&st);
40
 
 tmtm.tm_sec = st.wSecond;
41
 
 tmtm.tm_min = st.wMinute;
42
 
 tmtm.tm_hour = st.wHour;
43
 
 tmtm.tm_mday = st.wDay;
44
 
 tmtm.tm_mon = st.wMonth - 1;
45
 
 tmtm.tm_year = st.wYear - 1900;
46
 
 tmtm.tm_isdst = -1;
47
 
 tt = mktime (&tmtm);
48
 
 tp->tv_sec = tt;
49
 
 tp->tv_usec = st.wMilliseconds * 1000;
50
 
 return 1;
51
 
}
52
 
#define HAVE_GETTIMEOFDAY
53
 
#endif
54
 
#endif
 
29
#include <mmsystem.h>
55
30
 
56
 
struct timeval Curl_tvnow (void)
 
31
static int gettimeofday(struct timeval *tp, void *nothing)
57
32
{
58
 
 struct timeval now;
59
 
#ifdef HAVE_GETTIMEOFDAY
60
 
 gettimeofday (&now, NULL);
 
33
#ifdef WITHOUT_MM_LIB
 
34
  SYSTEMTIME st;
 
35
  time_t tt;
 
36
  struct tm tmtm;
 
37
  /* mktime converts local to UTC */
 
38
  GetLocalTime (&st);
 
39
  tmtm.tm_sec = st.wSecond;
 
40
  tmtm.tm_min = st.wMinute;
 
41
  tmtm.tm_hour = st.wHour;
 
42
  tmtm.tm_mday = st.wDay;
 
43
  tmtm.tm_mon = st.wMonth - 1;
 
44
  tmtm.tm_year = st.wYear - 1900;
 
45
  tmtm.tm_isdst = -1;
 
46
  tt = mktime (&tmtm);
 
47
  tp->tv_sec = tt;
 
48
  tp->tv_usec = st.wMilliseconds * 1000;
61
49
#else
62
 
 now.tv_sec = (long) time(NULL);
63
 
 now.tv_usec = 0;
64
 
#endif
65
 
 return now;
 
50
  /**
 
51
   ** The earlier time calculations using GetLocalTime
 
52
   ** had a time resolution of 10ms.The timeGetTime, part
 
53
   ** of multimedia apis offer a better time resolution
 
54
   ** of 1ms.Need to link against winmm.lib for this
 
55
   **/
 
56
  unsigned long Ticks = 0;
 
57
  unsigned long Sec =0;
 
58
  unsigned long Usec = 0;
 
59
  Ticks = timeGetTime();
 
60
 
 
61
  Sec = Ticks/1000;
 
62
  Usec = (Ticks - (Sec*1000))*1000;
 
63
  tp->tv_sec = Sec;
 
64
  tp->tv_usec = Usec;
 
65
#endif /* WITHOUT_MM_LIB */
 
66
  (void)nothing;
 
67
  return 0;
 
68
}
 
69
#else /* WIN32 */
 
70
/* non-win32 version of Curl_gettimeofday() */
 
71
static int gettimeofday(struct timeval *tp, void *nothing)
 
72
{
 
73
  (void)nothing; /* we don't support specific time-zones */
 
74
  tp->tv_sec = (long)time(NULL);
 
75
  tp->tv_usec = 0;
 
76
  return 0;
 
77
}
 
78
#endif /* WIN32 */
 
79
#endif /* HAVE_GETTIMEOFDAY */
 
80
 
 
81
/* Return the current time in a timeval struct */
 
82
struct timeval curlx_tvnow(void)
 
83
{
 
84
  struct timeval now;
 
85
  (void)gettimeofday(&now, NULL);
 
86
  return now;
66
87
}
67
88
 
68
89
/*
69
90
 * Make sure that the first argument is the more recent time, as otherwise
70
91
 * we'll get a weird negative time-diff back...
 
92
 *
 
93
 * Returns: the time difference in number of milliseconds.
71
94
 */
72
 
long Curl_tvdiff (struct timeval newer, struct timeval older)
 
95
long curlx_tvdiff(struct timeval newer, struct timeval older)
73
96
{
74
97
  return (newer.tv_sec-older.tv_sec)*1000+
75
 
    (499+newer.tv_usec-older.tv_usec)/1000;
76
 
}
77
 
 
78
 
long Curl_tvlong (struct timeval t1)
79
 
{
80
 
 return t1.tv_sec;
 
98
    (newer.tv_usec-older.tv_usec)/1000;
81
99
}
82
100
 
83
101
/*
84
 
 * local variables:
85
 
 * eval: (load-file "../curl-mode.el")
86
 
 * end:
87
 
 * vim600: fdm=marker
88
 
 * vim: et sw=2 ts=2 sts=2 tw=78
 
102
 * Same as curlx_tvdiff but with full usec resolution.
 
103
 *
 
104
 * Returns: the time difference in seconds with subsecond resolution.
89
105
 */
 
106
double curlx_tvdiff_secs(struct timeval newer, struct timeval older)
 
107
{
 
108
  return (double)(newer.tv_sec-older.tv_sec)+
 
109
    (double)(newer.tv_usec-older.tv_usec)/1000000.0;
 
110
}
 
111
 
 
112
/* return the number of seconds in the given input timeval struct */
 
113
long Curl_tvlong(struct timeval t1)
 
114
{
 
115
  return t1.tv_sec;
 
116
}