AiCPlayer
Interface of aic vm - for rendering aspect, sensors, video records
config_env.c
Go to the documentation of this file.
1 
4 #include "logger.h"
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 
9 #include "config_env.h"
10 
11 #define LOG_TAG "config_env"
12 
13 static char* configvar_raw(char* varname)
14 {
15  char* val = getenv(varname);
16  if (val == NULL)
17  {
18  LOGE("No envvar %s", varname);
19  exit(1);
20  }
21  if (strlen(val) == 0)
22  {
23  LOGE("Envvar %s is empty", varname);
24  exit(1);
25  }
26  return val;
27 }
28 
29 char* configvar_string(char* varname)
30 {
31  char* val = configvar_raw(varname);
32  LOGD("%s: %s", varname, val);
33  return val;
34 }
35 
36 int configvar_int(char* varname)
37 {
38  int ret;
39  char* val = configvar_raw(varname);
40  ret = atoi(val);
41  LOGD("%s: %d", varname, ret);
42  return ret;
43 }
44 
45 int configvar_bool(char* varname)
46 {
47  int ret = 0;
48  char* val = configvar_raw(varname);
49  char yn = val[0];
50  if (yn == 'y' || yn == 'Y' || yn == '1')
51  {
52  ret = 1;
53  }
54  else if (yn != 'n' && yn != 'N' && yn != '0')
55  {
56  LOGE("%s: value must start with (y|n|0|1), was %s", varname, val);
57  exit(1);
58  }
59  LOGD("%s: %d", varname, ret);
60  return ret;
61 }
Utilities to get config values from the environment.
#define LOGD(...)
Log at DEBUG level.
Definition: logger.h:21
#define LOGE(...)
Log at ERROR level (makes the application abort)
Definition: logger.h:31
char * configvar_string(char *varname)
Get the value of a config variable from the env.
Definition: config_env.c:29
Logging macros.
int configvar_bool(char *varname)
Get the value of a boolean config variable from the env.
Definition: config_env.c:45
int configvar_int(char *varname)
Get the value of a integer config variable from the env.
Definition: config_env.c:36