diff options
author | Mattias Andrée <maandree@kth.se> | 2021-04-13 17:29:14 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-04-13 17:29:14 +0200 |
commit | 6546989d280d8fc1e8e2bc152f08d9b04090d4b8 (patch) | |
tree | d201c83a72d9ef296773794d0cfce6dd7ecab7e0 /libcontacts_save_contact.c | |
parent | Update todo: do not support multiple calendars, all birthdays shall be stored in gregorian, and other software shall convert (diff) | |
download | libcontacts-6546989d280d8fc1e8e2bc152f08d9b04090d4b8.tar.gz libcontacts-6546989d280d8fc1e8e2bc152f08d9b04090d4b8.tar.bz2 libcontacts-6546989d280d8fc1e8e2bc152f08d9b04090d4b8.tar.xz |
m + add section 3 man pages
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libcontacts_save_contact.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/libcontacts_save_contact.c b/libcontacts_save_contact.c index b373a46..6c653f9 100644 --- a/libcontacts_save_contact.c +++ b/libcontacts_save_contact.c @@ -32,7 +32,7 @@ int libcontacts_save_contact(struct libcontacts_contact *contact, const struct passwd *user) { char *data = NULL, *path = NULL, *tmppath = NULL; - int oflags = O_WRONLY | O_CREAT | O_TRUNC; + int oflags = O_WRONLY | O_CREAT | O_TRUNC, newid = 0; int fd = -1, saved_errno = errno, dirs_created = 0; ssize_t r; size_t p, n, num = 0; @@ -49,10 +49,12 @@ libcontacts_save_contact(struct libcontacts_contact *contact, const struct passw contact->id = strdup("unnamed"); if (!contact->id) goto fail; + newid = 1; } else { contact->id = strdup(contact->name); if (!contact->id) goto fail; + newid = 1; for (p = 0; contact->id[p]; p++) { if (isalpha(contact->id[p])) contact->id[p] = (char)tolower(contact->id[p]); @@ -147,6 +149,10 @@ fail: free(path); free(tmppath); free(basenam); + if (newid) { + free(contact->id); + contact->id = NULL; + } errno = saved_errno; return -1; } |