d1a424c002
This will allow us to redefine the exit function.
For example:
```
#define exit(code) { \
fprintf(stderr, "%s:%d: exit(%s) in function ‘%s’\n",
__FILE__, __LINE__, #code, __func__); \
_exit(code); \
}
```
44 lines
988 B
C
44 lines
988 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
//puts(getenv("SHELL"));
|
|
//puts(getenv("CC"));
|
|
|
|
char* owned = malloc(26); // "TEST=Updates accordingly." + NUL
|
|
strcpy(owned, "TEST=It's working!!");
|
|
|
|
putenv(owned);
|
|
puts(getenv("TEST"));
|
|
|
|
strcpy(owned, "TEST=Updates accordingly.");
|
|
puts(getenv("TEST"));
|
|
|
|
// Allocation is reused
|
|
setenv("TEST", "in place", 1);
|
|
puts(getenv("TEST"));
|
|
puts(owned);
|
|
|
|
// Allocation is not reused
|
|
setenv("TEST", "Value overwritten and not in place because it's really long", 1);
|
|
puts(getenv("TEST"));
|
|
puts(owned);
|
|
|
|
// Value is not overwritten
|
|
setenv("TEST", "Value not overwritten", 0);
|
|
puts(getenv("TEST"));
|
|
|
|
unsetenv("TEST");
|
|
char* env = getenv("TEST");
|
|
if (env) {
|
|
puts("This should be null, but isn't");
|
|
puts(env);
|
|
exit(EXIT_FAILURE);
|
|
} else {
|
|
puts("Value deleted successfully!");
|
|
}
|
|
|
|
free(owned);
|
|
}
|