summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorRob Kendrick <rjek@netsurf-browser.org>2007-01-30 15:32:31 +0000
committerRob Kendrick <rjek@netsurf-browser.org>2007-01-30 15:32:31 +0000
commit7c88381a59771a3e0be35800af3496da1171e9a4 (patch)
tree06ec2e369b3fa856c249d0ea9983105eff489d37 /utils
parentf3e6ad3e9093bca4f8e053aa43ddf0631c9d4a18 (diff)
downloadnetsurf-7c88381a59771a3e0be35800af3496da1171e9a4.tar.gz
netsurf-7c88381a59771a3e0be35800af3496da1171e9a4.tar.bz2
Make time taken that is displayed in status bar use gettimeofday()-based time rather than clock()-based time
svn path=/trunk/netsurf/; revision=3157
Diffstat (limited to 'utils')
-rw-r--r--utils/utils.c17
-rw-r--r--utils/utils.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/utils/utils.c b/utils/utils.c
index 05f0059ec..b0707b7f2 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -236,6 +236,23 @@ char *strcasestr(const char *haystack, const char *needle)
return NULL;
}
+/**
+ * Returns a number of centiseconds, that increases in real time, for the
+ * purposes of measuring how long something takes in wall-clock terms. It uses
+ * gettimeofday() for this. Should the call to gettimeofday() fail, it returns
+ * zero.
+ *
+ * \return number of centiseconds that increases monotonically
+ */
+unsigned int wallclock(void)
+{
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) == -1)
+ return 0;
+
+ return ((tv.tv_sec * 100) + (tv.tv_usec / 10000));
+}
#ifdef __FreeBSD__
diff --git a/utils/utils.h b/utils/utils.h
index cfc7d8edc..67173d242 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -56,6 +56,7 @@ void unicode_transliterate(unsigned int c, char **r);
char *human_friendly_bytesize(unsigned long bytesize);
const char *rfc1123_date(time_t t);
char *strcasestr(const char *haystack, const char *needle);
+unsigned int wallclock(void);
#ifdef __FreeBSD__
/* FreeBSD lacks strndup */
char *strndup(const char *s, size_t n);