diff options
author | Mattias Andrée <maandree@kth.se> | 2021-04-08 17:58:54 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-04-08 18:15:49 +0200 |
commit | 508828c5861bf8487b995df537cbfa0b0b7a8ba4 (patch) | |
tree | 0ae6366528057f6fea28cb347d7c582850708a85 | |
parent | Add test for libcontacts_get_path (diff) | |
download | libcontacts-508828c5861bf8487b995df537cbfa0b0b7a8ba4.tar.gz libcontacts-508828c5861bf8487b995df537cbfa0b0b7a8ba4.tar.bz2 libcontacts-508828c5861bf8487b995df537cbfa0b0b7a8ba4.tar.xz |
Add with_me parameter to libcontacts_list_contacts and libcontacts_load_contacts
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libcontacts.h | 4 | ||||
-rw-r--r-- | libcontacts_list_contacts.c | 10 | ||||
-rw-r--r-- | libcontacts_load_contacts.c | 4 |
3 files changed, 10 insertions, 8 deletions
diff --git a/libcontacts.h b/libcontacts.h index 877840d..98bce5b 100644 --- a/libcontacts.h +++ b/libcontacts.h @@ -291,9 +291,9 @@ struct libcontacts_contact { void libcontacts_contact_destroy(struct libcontacts_contact *); -int libcontacts_list_contacts(char ***, const struct passwd *); +int libcontacts_list_contacts(char ***, const struct passwd *, int); int libcontacts_load_contact(const char *, struct libcontacts_contact *, const struct passwd *); /* errno = 0 if malformatted */ -int libcontacts_load_contacts(struct libcontacts_contact ***, const struct passwd *); +int libcontacts_load_contacts(struct libcontacts_contact ***, const struct passwd *, int); int libcontacts_save_contact(struct libcontacts_contact *, const struct passwd *); int libcontacts_same_number(const char *, const char *, const char *, const char *); /* might be removed in the future */ diff --git a/libcontacts_list_contacts.c b/libcontacts_list_contacts.c index fbf56ee..6879999 100644 --- a/libcontacts_list_contacts.c +++ b/libcontacts_list_contacts.c @@ -3,7 +3,7 @@ int -libcontacts_list_contacts(char ***idsp, const struct passwd *user) +libcontacts_list_contacts(char ***idsp, const struct passwd *user, int with_me) { char *dirnam; DIR *dir; @@ -36,10 +36,12 @@ libcontacts_list_contacts(char ***idsp, const struct passwd *user) goto start; while ((f = readdir(dir))) { - if (strchr(f->d_name, '.')) - continue; - if (!f->d_name[0] || strchr(f->d_name, '\0')[-1] == '~') + if (f->d_name[0] == '.') { + if (!with_me || strcmp(f->d_name, ".me")) + continue; + } else if (!f->d_name[0] || strchr(f->d_name, '\0')[-1] == '~') { continue; + } if (!((*idsp)[i++] = strdup(f->d_name))) goto fail; start: diff --git a/libcontacts_load_contacts.c b/libcontacts_load_contacts.c index 0bb0b86..8d44a9a 100644 --- a/libcontacts_load_contacts.c +++ b/libcontacts_load_contacts.c @@ -3,7 +3,7 @@ int -libcontacts_load_contacts(struct libcontacts_contact ***contactsp, const struct passwd *user) +libcontacts_load_contacts(struct libcontacts_contact ***contactsp, const struct passwd *user, int with_me) { int saved_errno = errno; char **ids; @@ -13,7 +13,7 @@ libcontacts_load_contacts(struct libcontacts_contact ***contactsp, const struct *contactsp = NULL; - if (libcontacts_list_contacts(&ids, user)) + if (libcontacts_list_contacts(&ids, user, with_me)) return -1; for (n = 0; ids[n]; n++); |