summaryrefslogtreecommitdiffstats
path: root/common.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-08-20 16:33:09 +0000
committerRoy Marples <roy@marples.name>2007-08-20 16:33:09 +0000
commit0b48939e2aa7eb125ffc6e97f33735b6b13de298 (patch)
treee76c79963e8063aa68a85e905764448704b5ff4a /common.c
parent184826065166942d397b9f5f526d232688133b70 (diff)
downloaddhcpcd-0b48939e2aa7eb125ffc6e97f33735b6b13de298.tar.xz
Rework the arp code again so that we don't link to librt on Linux.
Diffstat (limited to 'common.c')
-rw-r--r--common.c75
1 files changed, 45 insertions, 30 deletions
diff --git a/common.c b/common.c
index 2eb4e937..b0cdb4e7 100644
--- a/common.c
+++ b/common.c
@@ -76,12 +76,54 @@ size_t strlcpy (char *dst, const char *src, size_t size)
# endif
#endif
+/* This requires us to link to rt on glibc, so we use sysinfo instead */
+#ifdef __linux__
+#include <sys/sysinfo.h>
+long uptime (void)
+{
+ struct sysinfo info;
+
+ sysinfo (&info);
+ return info.uptime;
+}
+#elif __APPLE__
+/* Darwin doesn't appear to have an uptime, so try and make one ourselves */
+long uptime (void)
+{
+ struct timeval tv;
+ static long start = 0;
+
+ if (gettimeofday (&tv, NULL) == -1) {
+ logger (LOG_ERR, "gettimeofday: %s", strerror (errno));
+ return -1;
+ }
+
+ if (start == 0)
+ start = tv.tv_sec;
+
+ return tv.tv_sec - start;
+}
+#else
+long uptime (void)
+{
+ struct timespec tp;
+
+ if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1) {
+ logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
+ return -1;
+ }
+
+ return tp.tv_sec;
+}
+#endif
+
/* Handy function to get the time.
* We only care about time advancements, not the actual time itself
* Which is why we use CLOCK_MONOTONIC, but it is not available on all
* platforms
*/
-#ifdef CLOCK_MONOTONIC
+#ifdef HAVE_GET_TIME
+# ifdef CLOCK_MONOTONIC
int get_time (struct timeval *tp)
{
struct timespec ts;
@@ -95,19 +137,7 @@ int get_time (struct timeval *tp)
tp->tv_usec = ts.tv_nsec / 1000;
return (0);
}
-
-long uptime (void)
-{
- struct timespec tp;
-
- if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1) {
- logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
- return (-1);
- }
-
- return (tp.tv_sec);
-}
-#else
+# else
int get_time (struct timeval *tp)
{
if (gettimeofday (&tp, NULL) == -1) {
@@ -116,22 +146,7 @@ int get_time (struct timeval *tp)
}
return (0);
}
-
-long uptime (void)
-{
- struct timeval tv;
- static long start = 0;
-
- if (gettimeofday (&tv, NULL) == -1) {
- logger (LOG_ERR, "gettimeofday: %s", strerror (errno));
- return (-1);
- }
-
- if (start == 0)
- start = tv.tv_sec;
-
- return (tv.tv_sec - start);
-}
+# endif
#endif
void *xmalloc (size_t s)