Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Utils.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018 the Talvos developers. All rights reserved.
2 //
3 // This file is distributed under a three-clause BSD license. For full license
4 // terms please see the LICENSE file distributed with this source code.
5 
8 
9 #include <cstdlib>
10 #include <cstring>
11 #include <iostream>
12 
13 namespace talvos
14 {
15 
16 bool checkEnv(const char *Name, bool Default)
17 {
18  const char *Value = getenv(Name);
19  if (!Value)
20  return Default;
21 
22  if (!strcmp(Value, "0"))
23  return false;
24  else if (!strcmp(Value, "1"))
25  return true;
26 
27  std::cerr << std::endl
28  << "ERROR: Invalid value for " << Name << " environment variable"
29  << std::endl;
30  abort();
31 }
32 
33 unsigned long getEnvUInt(const char *Name, unsigned Default)
34 {
35  const char *StrValue = getenv(Name);
36  if (!StrValue)
37  return Default;
38 
39  char *End;
40  unsigned long Value = strtoul(StrValue, &End, 10);
41  if (strlen(End) || !strlen(StrValue) || Value == 0)
42  {
43  std::cerr << std::endl
44  << "ERROR: Invalid value for " << Name << " environment variable"
45  << std::endl;
46  abort();
47  }
48  return Value;
49 }
50 
51 } // namespace talvos
unsigned long getEnvUInt(const char *Name, unsigned Default)
Returns the integer value for the environment variable Name, or Default if it is not set...
Definition: Utils.cpp:33
bool checkEnv(const char *Name, bool Default)
Returns true if the environment variable Name is set to 1, false for 0, or Default if it is not set...
Definition: Utils.cpp:16