|
6 months ago | |
---|---|---|
posix | 6 months ago | |
LICENSE | 6 months ago | |
Makefile | 6 months ago | |
README.md | 6 months ago | |
libenv.c | 6 months ago | |
libenv.h | 6 months ago | |
libenv_test.c | 6 months ago |
README.md
libenv-1.0.0
libenv is a library for modifying environment variables under UNIX like operating systems.
Included is a wrapper library called posix_env that implements a POSIX compliant interface to the following functions:
char *getenv(const char *name);
https://pubs.opengroup.org/onlinepubs/9699919799/functions/getenv.html
int setenv(const char *envname, const char *envval, int overwrite);
https://pubs.opengroup.org/onlinepubs/9699919799/functions/setenv.html
int unsetenv(const char *name);
https://pubs.opengroup.org/onlinepubs/9699919799/functions/unsetenv.html
How to use
For libenv, first initialize the library by calling env_init():
#include "libenv.h"
// Mandatory global variable declaration
env_t test_env;
int main(int argc,
char **argv,
char **envp)
{
if (env_init(
envp,
&test_env
) < 1)
{
printf("[main] ERROR: Couldn't initialize environment\n");
exit(0);
}
...
/* Use API here (see libenv.h for declarations) */
...
}
For posix_env, first initialize the underlying libenv library by calling env_init():
#include <stdio.h>
#include "libenv.h"
#include "posix_env.h"
// Mandatory global variable declaration
env_t posix_env;
int main(int argc,
char **argv,
char **envp)
{
if (env_init(
envp,
&posix_env
) < 1)
{
printf("[main] ERROR: Couldn't initialize environment\n");
exit(0);
}
...
/* Use API here (see posix_env.h for declarations):
*
* char *posix_getenv(const char *);
* int posix_setenv(const char *, const char *, int);
* int posix_unsetenv(const char *);
*
* POSIX functions have a prefixed "posix_" to avoid
* namespace conflicts with system header declarations
* or definitions.
*
*/
...
}
How to compile
For libenv, include libenv.h and libenv.c in your project and add libenv.c to the compiler invocation:
bash# c99 -o myproject myproject.c libenv.c
Consult the included Makefile in libenv-1.0.0 for a specific example.
For posix_env, include libenv.h, libenv.c, posix_env.h and posix_env.c in your project and add libenv.c and posix_env.c to the compiler invocation:
bash# c99 -o myproject myproject.c libenv.c posix_env.c
Consult the included Makefile in libenv-1.0.0/posix for a specific example.