static char *get_primary_language(ssize_t *len) { char *l; #define test_env(str) do { \ l = getenv(str); \ if (l == NULL) { \ break; \ } \ *len = strlen(l); \ char *_ = memchr(l, '_', *len); \ if (_ != NULL) { \ *len = _ - l; \ } \ if (*len == 0) { \ break; \ } \ return l; \ } while (0) test_env("LC_ALL"); test_env("LC_MESSAGES"); test_env("LANG"); #undef test_env *len = 1; return "C"; }
int main(int argc, char** argv) { set_env(); environ = NULL; test_env(); set_env(); environ[0] = NULL; test_env(); static char* emptyEnv[1] = {NULL}; set_env(); environ = emptyEnv; test_env(); set_env(); environ = (char**)calloc(1, sizeof(*environ)); test_env(); // clearenv() is not part of the POSIX specs #if 1 set_env(); clearenv(); test_env(); #endif return 0; }
int main() { test_zero("evntest: env test"); test_setunset("evntest: setunset test"); test_env("evntest: env test"); _exit(0); }
int main(int argc, char** argv) { test_env("LD_PRELOAD"); test_env("DYLD_INSERT_LIBRARIES"); if (!process_flags(argc, argv)) { usage(argv[0]); return 1; } if (initial_sleep > 0) { printf("Sleeping %d sec...\n", initial_sleep); sleep(initial_sleep); printf("Awoke\n"); } if (test_sync) { test_sync_init(); } int i; for (i = 0; i < cycles; i++) { if (i > 0 && step_sleep > 0) { printf("\tsleeping %d sec...\n", step_sleep); sleep(4); } printf("cycle %d\n", i); test(i); } if (test_sync) { test_wait_shutdown(); } return 0; }
/** * System initialization thread. * * @param parameter parameter */ void sys_init_thread(void* parameter){ set_system_status(SYSTEM_STATUS_INIT); /* EasyFlash initialization */ if (flash_init() == FLASH_NO_ERR) { /* initialize OK and switch to running status */ set_system_status(SYSTEM_STATUS_RUN); /* test Env demo */ test_env(); } else { /* initialize fail and switch to fault status */ set_system_status(SYSTEM_STATUS_FAULT); } rt_thread_delete(rt_thread_self()); }
int update_env(t_env *e, char **av) { int i; int res; i = 1; while (av[i] != NULL) { res = test_arg(e, av + i); if (res == -1) _exit(EXIT_FAILURE); i += res; } if (!test_env(e)) { usage(); _exit(EXIT_FAILURE); } return (1); }