projects
/
citadel.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6d624cc
)
ForEachUser() linked list , keep track of last item so we don't have to traverse...
author
Art Cancro
<ajc@citadel.org>
Sat, 28 Sep 2019 20:54:46 +0000
(16:54 -0400)
committer
Art Cancro
<ajc@citadel.org>
Sat, 28 Sep 2019 20:54:46 +0000
(16:54 -0400)
citadel/user_ops.c
patch
|
blob
|
history
diff --git
a/citadel/user_ops.c
b/citadel/user_ops.c
index 9a39b06b6754b7b4c940fbd0e06acf0959476411..c215e734a6706940472766ac502b366385868c4d 100644
(file)
--- a/
citadel/user_ops.c
+++ b/
citadel/user_ops.c
@@
-1202,32
+1202,39
@@
void ForEachUser(void (*CallBack) (char *, void *out_data), void *in_data)
struct feu *next;
char username[USERNAME_SIZE];
};
struct feu *next;
char username[USERNAME_SIZE];
};
- struct feu *usernames = NULL;
+ struct feu *ufirst = NULL;
+ struct feu *ulast = NULL;
struct feu *f = NULL;
cdb_rewind(CDB_USERS);
struct feu *f = NULL;
cdb_rewind(CDB_USERS);
- // Phase 1 :
load list of user
names
+ // Phase 1 :
build a linked list of all our user account
names
while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
usptr = (struct ctdluser *) cdbus->ptr;
if (strlen(usptr->fullname) > 0) {
f = malloc(sizeof(struct feu));
while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
usptr = (struct ctdluser *) cdbus->ptr;
if (strlen(usptr->fullname) > 0) {
f = malloc(sizeof(struct feu));
- f->next =
usernames
;
+ f->next =
NULL
;
strncpy(f->username, usptr->fullname, USERNAME_SIZE);
strncpy(f->username, usptr->fullname, USERNAME_SIZE);
- usernames = f;
+
+ if (ufirst == NULL) {
+ ufirst = f;
+ ulast = f;
+ }
+ else {
+ ulast->next = f;
+ ulast = f;
+ }
}
}
}
}
- // Phase 2 : perform the callback for each user
name
- while (u
sernames
!= NULL) {
- (*CallBack) (u
sernames
->username, in_data);
- f = u
sernames
;
- u
sernames = usernames
->next;
+ // Phase 2 : perform the callback for each user
while de-allocating the list
+ while (u
first
!= NULL) {
+ (*CallBack) (u
first
->username, in_data);
+ f = u
first
;
+ u
first = ufirst
->next;
free(f);
}
free(f);
}
-
- free(usernames);
}
}