c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef ENV_UTIL_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define ENV_UTIL_H
a128456c8530046dd9a998386f383160e70b532fTimo Sirainen
a128456c8530046dd9a998386f383160e70b532fTimo Sirainen/* Add new environment variable. Wrapper to putenv(). Note that calls to this
a128456c8530046dd9a998386f383160e70b532fTimo Sirainen function allocates memory which isn't free'd until env_clean() is called. */
a128456c8530046dd9a998386f383160e70b532fTimo Sirainenvoid env_put(const char *env);
8e6e668126491f248d5305b5f7b15f46f03f07b1Timo Sirainen/* Remove a single environment. */
8e6e668126491f248d5305b5f7b15f46f03f07b1Timo Sirainenvoid env_remove(const char *name);
a128456c8530046dd9a998386f383160e70b532fTimo Sirainen/* Clear all environment variables. */
a128456c8530046dd9a998386f383160e70b532fTimo Sirainenvoid env_clean(void);
5aaddefb351e87ea1e97db92924a75ff8aa50181Timo Sirainen/* Clear all environment variables except what's listed in preserve_envs[] */
5aaddefb351e87ea1e97db92924a75ff8aa50181Timo Sirainenvoid env_clean_except(const char *const preserve_envs[]);
a128456c8530046dd9a998386f383160e70b532fTimo Sirainen
9e95ca63385f300c7625beba9174cbf0e019d406Timo Sirainen/* Save a copy of the current environment. */
9e95ca63385f300c7625beba9174cbf0e019d406Timo Sirainenstruct env_backup *env_backup_save(void);
9e95ca63385f300c7625beba9174cbf0e019d406Timo Sirainen/* Clear the current environment and restore the backup. */
9e95ca63385f300c7625beba9174cbf0e019d406Timo Sirainenvoid env_backup_restore(struct env_backup *env);
9e95ca63385f300c7625beba9174cbf0e019d406Timo Sirainen/* Free the memory used by environment backup. */
9e95ca63385f300c7625beba9174cbf0e019d406Timo Sirainenvoid env_backup_free(struct env_backup **env);
9e95ca63385f300c7625beba9174cbf0e019d406Timo Sirainen
a857fb61f1cc77a81d18adee6a95ae04c27a5ffbTimo Sirainen/* Returns the value of "&environ". This is more portable than using it
a857fb61f1cc77a81d18adee6a95ae04c27a5ffbTimo Sirainen directly. */
a857fb61f1cc77a81d18adee6a95ae04c27a5ffbTimo Sirainenchar ***env_get_environ_p(void);
a857fb61f1cc77a81d18adee6a95ae04c27a5ffbTimo Sirainen
e8c29d12e0e75ca35a64f0a0d096ad44248b206fTimo Sirainen/* Free all memory used by env_put() function. Environment must not be
e8c29d12e0e75ca35a64f0a0d096ad44248b206fTimo Sirainen accessed afterwards. */
e8c29d12e0e75ca35a64f0a0d096ad44248b206fTimo Sirainenvoid env_deinit(void);
e8c29d12e0e75ca35a64f0a0d096ad44248b206fTimo Sirainen
a128456c8530046dd9a998386f383160e70b532fTimo Sirainen#endif