Exemplo n.º 1
0
tr_sys_file_t
tr_logGetFile (void)
{
  static bool initialized = false;
  static tr_sys_file_t file = TR_BAD_SYS_FILE;

  if (!initialized)
    {
      const int fd = tr_env_get_int ("TR_DEBUG_FD", 0);

      switch (fd)
        {
          case 1:
            file = tr_sys_file_get_std (TR_STD_SYS_FILE_OUT, NULL);
            break;

          case 2:
            file = tr_sys_file_get_std (TR_STD_SYS_FILE_ERR, NULL);
            break;
        }

      initialized = true;
    }

  return file;
}
Exemplo n.º 2
0
static int
test_env (void)
{
  const char * test_key = "TR_TEST_ENV";
  int x;
  char * s;

  unsetenv (test_key);

  check (!tr_env_key_exists (test_key));
  x = tr_env_get_int (test_key, 123);
  check_int_eq (123, x);
  s = tr_env_get_string (test_key, NULL);
  check (s == NULL);
  s = tr_env_get_string (test_key, "a");
  check_streq ("a", s);
  tr_free (s);

  setenv (test_key, "", 1);

  check (tr_env_key_exists (test_key));
  x = tr_env_get_int (test_key, 456);
  check_int_eq (456, x);
  s = tr_env_get_string (test_key, NULL);
  check_streq ("", s);
  tr_free (s);
  s = tr_env_get_string (test_key, "b");
  check_streq ("", s);
  tr_free (s);

  setenv (test_key, "135", 1);

  check (tr_env_key_exists (test_key));
  x = tr_env_get_int (test_key, 789);
  check_int_eq (135, x);
  s = tr_env_get_string (test_key, NULL);
  check_streq ("135", s);
  tr_free (s);
  s = tr_env_get_string (test_key, "c");
  check_streq ("135", s);
  tr_free (s);

  return 0;
}