diff options
author | irungentoo <irungentoo@gmail.com> | 2013-09-22 14:14:53 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-09-22 14:14:53 -0400 |
commit | 8b5d9dc13e5b5fe66f47701aec57ae7b04345be3 (patch) | |
tree | 80caf6a1cf7729078dee1bb8bb59d9753a0f36e8 /toxcore/Messenger.c | |
parent | 64150f4bde73f4b4748a3e46664a2930a3635054 (diff) | |
parent | cb68be00b0bb8802da94b877a24e68ee35b5658a (diff) |
Merge branch 'patch-9001' of https://github.com/stal888/ProjectTox-Core into stal888-patch-9001
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 43db2a9d..8fd58a44 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1645,6 +1645,50 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length) | |||
1645 | return Messenger_load_old(m, data, length); | 1645 | return Messenger_load_old(m, data, length); |
1646 | } | 1646 | } |
1647 | 1647 | ||
1648 | /* Return the number of friends in the instance m. | ||
1649 | * You should use this to determine how much memory to allocate | ||
1650 | * for copy_friendlist. */ | ||
1651 | size_t count_friendlist(Messenger *m) | ||
1652 | { | ||
1653 | size_t ret = 0; | ||
1654 | uint32_t i; | ||
1655 | for (i = 0; i < m->numfriends; i++) { | ||
1656 | if (m->friendlist[i].status > 0) { | ||
1657 | ret++; | ||
1658 | } | ||
1659 | } | ||
1660 | return ret; | ||
1661 | } | ||
1662 | |||
1663 | /* Copy a list of valid friend IDs into the array out_list. | ||
1664 | * If out_list is NULL, returns -1. | ||
1665 | * Otherwise, returns the number of elements copied. | ||
1666 | * If the array was too small, the contents | ||
1667 | * of out_list will be truncated to list_size. */ | ||
1668 | size_t copy_friendlist(Messenger *m, int *out_list, size_t list_size) | ||
1669 | { | ||
1670 | if (!out_list) | ||
1671 | return -1; | ||
1672 | |||
1673 | if (m->numfriends == 0) { | ||
1674 | return 0; | ||
1675 | } | ||
1676 | |||
1677 | uint32_t i; | ||
1678 | size_t ret = 0; | ||
1679 | for (i = 0; i < m->numfriends; i++) { | ||
1680 | if (i >= list_size) { | ||
1681 | break; /* Abandon ship */ | ||
1682 | } | ||
1683 | if (m->friendlist[i].status > 0) { | ||
1684 | out_list[i] = i; | ||
1685 | ret++; | ||
1686 | } | ||
1687 | } | ||
1688 | |||
1689 | return ret; | ||
1690 | } | ||
1691 | |||
1648 | /* Allocate and return a list of valid friend id's. List must be freed by the | 1692 | /* Allocate and return a list of valid friend id's. List must be freed by the |
1649 | * caller. | 1693 | * caller. |
1650 | * | 1694 | * |