From ba169b7c218dbec354d53181024c8e02bd061a17 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 22 Sep 2013 14:24:38 -0400 Subject: Keep the code consistent. --- toxcore/Messenger.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'toxcore/Messenger.c') diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 8fd58a44..9089144a 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1648,44 +1648,48 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length) /* Return the number of friends in the instance m. * You should use this to determine how much memory to allocate * for copy_friendlist. */ -size_t count_friendlist(Messenger *m) +uint32_t count_friendlist(Messenger *m) { - size_t ret = 0; + uint32_t ret = 0; uint32_t i; + for (i = 0; i < m->numfriends; i++) { if (m->friendlist[i].status > 0) { ret++; } } + return ret; } /* Copy a list of valid friend IDs into the array out_list. - * If out_list is NULL, returns -1. + * If out_list is NULL, returns 0. * Otherwise, returns the number of elements copied. * If the array was too small, the contents * of out_list will be truncated to list_size. */ -size_t copy_friendlist(Messenger *m, int *out_list, size_t list_size) +uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size) { if (!out_list) - return -1; - + return 0; + if (m->numfriends == 0) { return 0; } - + uint32_t i; - size_t ret = 0; + uint32_t ret = 0; + for (i = 0; i < m->numfriends; i++) { if (i >= list_size) { break; /* Abandon ship */ } + if (m->friendlist[i].status > 0) { out_list[i] = i; ret++; } } - + return ret; } -- cgit v1.2.3