~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to lib/timeval.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.31 2008-05-12 02:04:22 yangtse Exp $
 
21
 * $Id: timeval.c,v 1.32 2008-07-02 03:04:56 yangtse Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "timeval.h"
52
52
  */
53
53
  struct timeval now;
54
54
  struct timespec tsnow;
55
 
  (void)clock_gettime(CLOCK_MONOTONIC, &tsnow);
56
 
  now.tv_sec = tsnow.tv_sec;
57
 
  now.tv_usec = tsnow.tv_nsec / 1000;
 
55
  if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
 
56
    now.tv_sec = tsnow.tv_sec;
 
57
    now.tv_usec = tsnow.tv_nsec / 1000;
 
58
  }
 
59
  /*
 
60
  ** Even when the configure process has truly detected monotonic clock
 
61
  ** availability, it might happen that it is not actually available at
 
62
  ** run-time. When this occurs simply fallback to other time source.
 
63
  */
 
64
#ifdef HAVE_GETTIMEOFDAY
 
65
  else
 
66
    (void)gettimeofday(&now, NULL);
 
67
#else
 
68
  else {
 
69
    now.tv_sec = (long)time(NULL);
 
70
    now.tv_usec = 0;
 
71
  }
 
72
#endif
58
73
  return now;
59
74
}
60
75