]> granicus.if.org Git - shadow/commitdiff
Implement commonio_append.
authorEric W. Biederman <ebiederm@xmission.com>
Tue, 22 Jan 2013 09:13:26 +0000 (01:13 -0800)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 5 Aug 2013 15:08:45 +0000 (10:08 -0500)
To support files that do not have a simple unique key implement
commonio_append to allow new entries to be added.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
lib/commonio.c
lib/commonio.h

index 1c0555c32eacfbd0d842b12e332c4adbbb854bf9..c7a9fca8f3bbf5a61891de76ebe3b1ab9399a50b 100644 (file)
@@ -1113,6 +1113,36 @@ int commonio_update (struct commonio_db *db, const void *eptr)
        return 1;
 }
 
+int commonio_append (struct commonio_db *db, const void *eptr)
+{
+       struct commonio_entry *p;
+       void *nentry;
+
+       if (!db->isopen || db->readonly) {
+               errno = EINVAL;
+               return 0;
+       }
+       nentry = db->ops->dup (eptr);
+       if (NULL == nentry) {
+               errno = ENOMEM;
+               return 0;
+       }
+       /* new entry */
+       p = (struct commonio_entry *) malloc (sizeof *p);
+       if (NULL == p) {
+               db->ops->free (nentry);
+               errno = ENOMEM;
+               return 0;
+       }
+
+       p->eptr = nentry;
+       p->line = NULL;
+       p->changed = true;
+       add_one_entry (db, p);
+
+       db->changed = true;
+       return 1;
+}
 
 void commonio_del_entry (struct commonio_db *db, const struct commonio_entry *p)
 {
index 902cc6fdfe69434ab046468784884d9090bb3f72..5b49f25e4b23eddbc91df9b8aba46d8d8eb3c833 100644 (file)
@@ -146,6 +146,7 @@ extern int commonio_lock_nowait (struct commonio_db *, bool log);
 extern int commonio_open (struct commonio_db *, int);
 extern /*@observer@*/ /*@null@*/const void *commonio_locate (struct commonio_db *, const char *);
 extern int commonio_update (struct commonio_db *, const void *);
+extern int commonio_append (struct commonio_db *, const void *);
 extern int commonio_remove (struct commonio_db *, const char *);
 extern int commonio_rewind (struct commonio_db *);
 extern /*@observer@*/ /*@null@*/const void *commonio_next (struct commonio_db *);