3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 13:02:44 +01:00

util: knownnetworks: move timespec_compare into util

This commit is contained in:
James Prestwood 2019-07-30 11:37:16 -07:00 committed by Denis Kenzior
parent 04dc20cf5d
commit e2bed192f6
3 changed files with 27 additions and 21 deletions

View File

@ -40,36 +40,19 @@
#include "src/dbus.h"
#include "src/knownnetworks.h"
#include "src/scan.h"
#include "src/util.h"
static struct l_queue *known_networks;
static size_t num_known_hidden_networks;
static struct l_dir_watch *storage_dir_watch;
static int timespec_compare(const struct timespec *tsa,
const struct timespec *tsb)
{
if (tsa->tv_sec > tsb->tv_sec)
return -1;
if (tsa->tv_sec < tsb->tv_sec)
return 1;
if (tsa->tv_nsec > tsb->tv_nsec)
return -1;
if (tsa->tv_nsec < tsb->tv_nsec)
return -1;
return 0;
}
static int connected_time_compare(const void *a, const void *b, void *user_data)
{
const struct network_info *ni_a = a;
const struct network_info *ni_b = b;
return timespec_compare(&ni_a->connected_time, &ni_b->connected_time);
return util_timespec_compare(&ni_a->connected_time,
&ni_b->connected_time);
}
const char *known_network_get_path(const struct network_info *network)
@ -131,7 +114,7 @@ static void known_network_update(struct network_info *orig_network,
else
network = network_info_add_known(ssid, security);
if (timespec_compare(&network->connected_time, connected_time) &&
if (util_timespec_compare(&network->connected_time, connected_time) &&
orig_network) {
l_dbus_property_changed(dbus_get_bus(),
known_network_get_path(network),

View File

@ -27,6 +27,7 @@
#include <string.h>
#include <stdio.h>
#include <sys/uio.h>
#include <sys/time.h>
#include <ell/ell.h>
@ -208,3 +209,22 @@ const char *util_get_username(const char *identity)
return identity;
}
int util_timespec_compare(const struct timespec *tsa,
const struct timespec *tsb)
{
if (tsa->tv_sec > tsb->tv_sec)
return -1;
if (tsa->tv_sec < tsb->tv_sec)
return 1;
if (tsa->tv_nsec > tsb->tv_nsec)
return -1;
if (tsa->tv_nsec < tsb->tv_nsec)
return -1;
return 0;
}

View File

@ -65,4 +65,7 @@ static inline bool util_mem_is_zero(const uint8_t *field, size_t size)
return true;
}
int util_timespec_compare(const struct timespec *tsa,
const struct timespec *tsb);
#endif /* __UTIL_H */