diff options
Diffstat (limited to 'common/session-env.c')
-rw-r--r-- | common/session-env.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/common/session-env.c b/common/session-env.c index 1df2c4431..5d6b66dd6 100644 --- a/common/session-env.c +++ b/common/session-env.c @@ -98,13 +98,45 @@ static size_t lastallocatedarraysize; /* Return the names of standard environment variables one after the other. The caller needs to set the value at the address of - ITERATOR initially to 0 and then call this function until it returns - NULL. */ + ITERATOR initially to 0 and then call this function until it + returns NULL. If ITERATOR is NULL, a single comma delimited string + with the names is returned; NULL is never returned in this case and + R_ASSNAME is ignored. */ const char * session_env_list_stdenvnames (int *iterator, const char **r_assname) { - int idx = *iterator; + int idx; + static char *commastring; + + if (!iterator) + { + if (!commastring) + { + size_t len = 0; + char *p; + + for (idx = 0; idx < DIM (stdenvnames); idx++) + len += strlen (stdenvnames[idx].name) + 1; + commastring = xtrymalloc (len); + if (!commastring) + { + log_error ("%s: error allocating string: %s\n", __func__, + gpg_strerror (gpg_error_from_syserror ())); + return "GPG_TTY,TERM,DISPLAY"; + } + p = commastring; + for (idx = 0; idx < DIM (stdenvnames); idx++) + { + if (idx) + *p++ = ','; + p = stpcpy (p, stdenvnames[idx].name); + } + gpgrt_annotate_leaked_object (commastring); + } + return commastring; + } + idx = *iterator; if (idx < 0 || idx >= DIM (stdenvnames)) return NULL; *iterator = idx + 1; |