diff options
-rw-r--r-- | toxcore/Messenger.c | 22 | ||||
-rw-r--r-- | toxcore/Messenger.h | 6 | ||||
-rw-r--r-- | toxcore/tox.c | 6 | ||||
-rw-r--r-- | toxcore/tox.h | 8 |
4 files changed, 23 insertions, 19 deletions
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) | |||
1648 | /* Return the number of friends in the instance m. | 1648 | /* Return the number of friends in the instance m. |
1649 | * You should use this to determine how much memory to allocate | 1649 | * You should use this to determine how much memory to allocate |
1650 | * for copy_friendlist. */ | 1650 | * for copy_friendlist. */ |
1651 | size_t count_friendlist(Messenger *m) | 1651 | uint32_t count_friendlist(Messenger *m) |
1652 | { | 1652 | { |
1653 | size_t ret = 0; | 1653 | uint32_t ret = 0; |
1654 | uint32_t i; | 1654 | uint32_t i; |
1655 | |||
1655 | for (i = 0; i < m->numfriends; i++) { | 1656 | for (i = 0; i < m->numfriends; i++) { |
1656 | if (m->friendlist[i].status > 0) { | 1657 | if (m->friendlist[i].status > 0) { |
1657 | ret++; | 1658 | ret++; |
1658 | } | 1659 | } |
1659 | } | 1660 | } |
1661 | |||
1660 | return ret; | 1662 | return ret; |
1661 | } | 1663 | } |
1662 | 1664 | ||
1663 | /* Copy a list of valid friend IDs into the array out_list. | 1665 | /* Copy a list of valid friend IDs into the array out_list. |
1664 | * If out_list is NULL, returns -1. | 1666 | * If out_list is NULL, returns 0. |
1665 | * Otherwise, returns the number of elements copied. | 1667 | * Otherwise, returns the number of elements copied. |
1666 | * If the array was too small, the contents | 1668 | * If the array was too small, the contents |
1667 | * of out_list will be truncated to list_size. */ | 1669 | * of out_list will be truncated to list_size. */ |
1668 | size_t copy_friendlist(Messenger *m, int *out_list, size_t list_size) | 1670 | uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size) |
1669 | { | 1671 | { |
1670 | if (!out_list) | 1672 | if (!out_list) |
1671 | return -1; | 1673 | return 0; |
1672 | 1674 | ||
1673 | if (m->numfriends == 0) { | 1675 | if (m->numfriends == 0) { |
1674 | return 0; | 1676 | return 0; |
1675 | } | 1677 | } |
1676 | 1678 | ||
1677 | uint32_t i; | 1679 | uint32_t i; |
1678 | size_t ret = 0; | 1680 | uint32_t ret = 0; |
1681 | |||
1679 | for (i = 0; i < m->numfriends; i++) { | 1682 | for (i = 0; i < m->numfriends; i++) { |
1680 | if (i >= list_size) { | 1683 | if (i >= list_size) { |
1681 | break; /* Abandon ship */ | 1684 | break; /* Abandon ship */ |
1682 | } | 1685 | } |
1686 | |||
1683 | if (m->friendlist[i].status > 0) { | 1687 | if (m->friendlist[i].status > 0) { |
1684 | out_list[i] = i; | 1688 | out_list[i] = i; |
1685 | ret++; | 1689 | ret++; |
1686 | } | 1690 | } |
1687 | } | 1691 | } |
1688 | 1692 | ||
1689 | return ret; | 1693 | return ret; |
1690 | } | 1694 | } |
1691 | 1695 | ||
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 81e661e1..2b29896c 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -459,14 +459,14 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length); | |||
459 | /* Return the number of friends in the instance m. | 459 | /* Return the number of friends in the instance m. |
460 | * You should use this to determine how much memory to allocate | 460 | * You should use this to determine how much memory to allocate |
461 | * for copy_friendlist. */ | 461 | * for copy_friendlist. */ |
462 | size_t count_friendlist(Messenger *m); | 462 | uint32_t count_friendlist(Messenger *m); |
463 | 463 | ||
464 | /* Copy a list of valid friend IDs into the array out_list. | 464 | /* Copy a list of valid friend IDs into the array out_list. |
465 | * If out_list is NULL, returns -1. | 465 | * If out_list is NULL, returns 0. |
466 | * Otherwise, returns the number of elements copied. | 466 | * Otherwise, returns the number of elements copied. |
467 | * If the array was too small, the contents | 467 | * If the array was too small, the contents |
468 | * of out_list will be truncated to list_size. */ | 468 | * of out_list will be truncated to list_size. */ |
469 | size_t copy_friendlist(Messenger *m, int *out_list, size_t list_size); | 469 | uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size); |
470 | 470 | ||
471 | /* Allocate and return a list of valid friend id's. List must be freed by the | 471 | /* Allocate and return a list of valid friend id's. List must be freed by the |
472 | * caller. | 472 | * caller. |
diff --git a/toxcore/tox.c b/toxcore/tox.c index dfafaf20..fa53e693 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -265,18 +265,18 @@ void tox_set_sends_receipts(void *tox, int friendnumber, int yesno) | |||
265 | /* Return the number of friends in the instance m. | 265 | /* Return the number of friends in the instance m. |
266 | * You should use this to determine how much memory to allocate | 266 | * You should use this to determine how much memory to allocate |
267 | * for copy_friendlist. */ | 267 | * for copy_friendlist. */ |
268 | size_t tox_count_friendlist(void *tox) | 268 | uint32_t tox_count_friendlist(void *tox) |
269 | { | 269 | { |
270 | Messenger *m = tox; | 270 | Messenger *m = tox; |
271 | return count_friendlist(m); | 271 | return count_friendlist(m); |
272 | } | 272 | } |
273 | 273 | ||
274 | /* Copy a list of valid friend IDs into the array out_list. | 274 | /* Copy a list of valid friend IDs into the array out_list. |
275 | * If out_list is NULL, returns -1. | 275 | * If out_list is NULL, returns 0. |
276 | * Otherwise, returns the number of elements copied. | 276 | * Otherwise, returns the number of elements copied. |
277 | * If the array was too small, the contents | 277 | * If the array was too small, the contents |
278 | * of out_list will be truncated to list_size. */ | 278 | * of out_list will be truncated to list_size. */ |
279 | size_t tox_copy_friendlist(void *tox, int *out_list, size_t list_size) | 279 | uint32_t tox_copy_friendlist(void *tox, int *out_list, uint32_t list_size) |
280 | { | 280 | { |
281 | Messenger *m = tox; | 281 | Messenger *m = tox; |
282 | return copy_friendlist(m, out_list, list_size); | 282 | return copy_friendlist(m, out_list, list_size); |
diff --git a/toxcore/tox.h b/toxcore/tox.h index ed471542..9c810418 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -283,14 +283,14 @@ void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno); | |||
283 | /* Return the number of friends in the instance m. | 283 | /* Return the number of friends in the instance m. |
284 | * You should use this to determine how much memory to allocate | 284 | * You should use this to determine how much memory to allocate |
285 | * for copy_friendlist. */ | 285 | * for copy_friendlist. */ |
286 | size_t tox_count_friendlist(void *tox); | 286 | uint32_t tox_count_friendlist(void *tox); |
287 | 287 | ||
288 | /* Copy a list of valid friend IDs into the array out_list. | 288 | /* Copy a list of valid friend IDs into the array out_list. |
289 | * If out_list is NULL, returns -1. | 289 | * If out_list is NULL, returns 0. |
290 | * Otherwise, returns the number of elements copied. | 290 | * Otherwise, returns the number of elements copied. |
291 | * If the array was too small, the contents | 291 | * If the array was too small, the contents |
292 | * of out_list will be truncated to list_size. */ | 292 | * of out_list will be truncated to list_size. */ |
293 | size_t tox_copy_friendlist(void *tox, int *out_list, size_t list_size); | 293 | uint32_t tox_copy_friendlist(void *tox, int *out_list, uint32_t list_size); |
294 | 294 | ||
295 | /* Set the function that will be executed when a friend request is received. | 295 | /* Set the function that will be executed when a friend request is received. |
296 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) | 296 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) |