#include <dirent.h>
#include <ctype.h>
#include <fcntl.h>
+#include <time.h>
#include <sys/stat.h>
#include "libudev.h"
static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *syspath, char *value, size_t size)
{
char path[UTIL_PATH_SIZE];
+ char target[UTIL_PATH_SIZE];
ssize_t len;
const char *pos;
util_strscpyl(path, sizeof(path), syspath, "/", slink, NULL);
- len = readlink(path, path, sizeof(path));
- if (len <= 0 || len == (ssize_t)sizeof(path))
+ len = readlink(path, target, sizeof(target));
+ if (len <= 0 || len == (ssize_t)sizeof(target))
return -1;
- path[len] = '\0';
- pos = strrchr(path, '/');
+ target[len] = '\0';
+ pos = strrchr(target, '/');
if (pos == NULL)
return -1;
pos = &pos[1];
bits |= 1LLU << ((hash >> 18) & 63);
return bits;
}
+
+#define USEC_PER_SEC 1000000ULL
+#define NSEC_PER_USEC 1000ULL
+unsigned long long now_usec(void)
+{
+ struct timespec ts;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
+ return 0;
+ return (unsigned long long) ts.tv_sec * USEC_PER_SEC +
+ (unsigned long long) ts.tv_nsec / NSEC_PER_USEC;
+}