/* * splinter -- memory scoping. * * The one thing that must never break: the user id. Every request carries it, * and it comes from who is running - not from a setting someone can forget. */ #include #include #include #include "splinter.h" #include "memory.h" static int failures; #define CHECK(c) do { if (!(c)) { fprintf(stderr, "FAIL %s:%d: %s\n", \ __FILE__, __LINE__, #c); failures++; } } while (0) int main(void) { const char *user; /* from the environment */ CHECK(setenv("USER", "lotherk", 1) == 0); user = sp_memory_user(); CHECK(user != NULL); CHECK(strcmp(user, "lotherk") == 0); /* without USER it falls back to the passwd entry, never to empty */ CHECK(unsetenv("USER") == 0); user = sp_memory_user(); CHECK(user != NULL); CHECK(strlen(user) > 0); if (failures == 0) printf("test_memory: ok\n"); return failures == 0 ? 0 : 1; }