summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-09-22 14:24:38 -0400
committerirungentoo <irungentoo@gmail.com>2013-09-22 14:24:38 -0400
commitba169b7c218dbec354d53181024c8e02bd061a17 (patch)
treed5ac01d23eb6c85c6a82d569a346b00e8e30efe8 /toxcore/Messenger.c
parent8b5d9dc13e5b5fe66f47701aec57ae7b04345be3 (diff)
Keep the code consistent.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c22
1 files changed, 13 insertions, 9 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. */
1651size_t count_friendlist(Messenger *m) 1651uint32_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. */
1668size_t copy_friendlist(Messenger *m, int *out_list, size_t list_size) 1670uint32_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