mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 06:58:35 +00:00
Introduce GA_APPEND()
This macro is used to append an element to a growable array. It replaces this common idiom: ga_grow(&ga, 1); ((item_type *)ga.ga_data)[ga.ga_len] = item; ++ga.ga_len;
This commit is contained in:

committed by
Justin M. Keyes

parent
be3a4b6ca8
commit
45e7814e6a
@@ -21,16 +21,13 @@ int os_get_usernames(garray_T *users)
|
||||
ga_init(users, sizeof(char *), 20);
|
||||
|
||||
# if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H)
|
||||
char *user;
|
||||
struct passwd *pw;
|
||||
|
||||
setpwent();
|
||||
while ((pw = getpwent()) != NULL) {
|
||||
// pw->pw_name shouldn't be NULL but just in case...
|
||||
if (pw->pw_name != NULL) {
|
||||
ga_grow(users, 1);
|
||||
user = xstrdup(pw->pw_name);
|
||||
((char **)(users->ga_data))[users->ga_len++] = user;
|
||||
GA_APPEND(char *, users, xstrdup(pw->pw_name));
|
||||
}
|
||||
}
|
||||
endpwent();
|
||||
|
Reference in New Issue
Block a user