#include <sgp/group.h>
#include <sgp/friend.h>
#include <stdlib.h>
+#include <errno.h>
struct sgp_group {
struct sgp_friend **friends;
return group;
}
+/*
+ * TODO: start using references. The group can't take it if we want to
+ * add a friend to more groups. A single global reference for all
+ * friends may be good enough.
+ */
int sgp_group_add_friend(struct sgp_group *group, struct sgp_friend *friend)
{
+ struct sgp_friend **old_friends;
+ old_friends = group->friends;
+ group->nr_friends++;
+ group->friends = realloc(old_friends,
+ group->nr_friends * sizeof(friend));
+ if (!group->friends) {
+ group->friends = old_friends;
+ group->nr_friends--;
+ return -ENOMEM;
+ }
+ group->friends[group->nr_friends - 1] = friend;
return 0;
}