6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
- #include " detail/config.hpp"
9
+ #include < CL/sycl/detail/os_util.hpp>
10
+ #include < detail/config.hpp>
10
11
11
12
#include < cstring>
12
13
#include < fstream>
@@ -21,7 +22,7 @@ namespace sycl {
21
22
namespace detail {
22
23
23
24
#ifndef SYCL_CONFIG_FILE_NAME
24
- #define SYCL_CONFIG_FILE_NAME " sycl.cfg "
25
+ #define SYCL_CONFIG_FILE_NAME " sycl.conf "
25
26
#endif // SYCL_CONFIG_FILE_NAME
26
27
27
28
#define CONFIG (Name, MaxSize, CompileTimeDef ) \
@@ -50,17 +51,22 @@ void readConfig() {
50
51
static bool Initialized = false ;
51
52
if (Initialized)
52
53
return ;
54
+
53
55
std::fstream File;
54
- // TODO: Find libsycl.so location.
55
- static const char *ConfigFile = getenv (" SYCL_CONFIG_FILE_NAME" );
56
- const char *FileToLoad = ConfigFile ? ConfigFile : SYCL_CONFIG_FILE_NAME;
57
- File.open (FileToLoad, std::ios::in);
56
+ if (const char *ConfigFile = getenv (" SYCL_CONFIG_FILE_NAME" ))
57
+ File.open (ConfigFile, std::ios::in);
58
+ else {
59
+ const std::string LibSYCLDir = sycl::detail::OSUtil::getCurrentDSODir ();
60
+ File.open (LibSYCLDir + sycl::detail::OSUtil::DirSep + SYCL_CONFIG_FILE_NAME,
61
+ std::ios::in);
62
+ }
63
+
58
64
if (File.is_open ()) {
59
65
// TODO: Use max size from macro instead of 256
60
66
char Key[MAX_CONFIG_NAME] = {0 }, Value[256 ] = {0 };
61
67
while (!File.eof ()) {
62
68
// Expected fromat:
63
- // ConfigName=Value
69
+ // ConfigName=Value\r
64
70
// ConfigName=Value
65
71
// TODO: Skip spaces before and after '='
66
72
File.getline (Key, sizeof (Key), ' =' );
@@ -72,6 +78,7 @@ void readConfig() {
72
78
continue ;
73
79
}
74
80
File.getline (Value, sizeof (Value), ' \n ' );
81
+
75
82
if (File.fail ()) {
76
83
// Fail to process the value while config name is OK. It's likely that
77
84
// value is too long. Currently just deal what we have got and ignore
@@ -80,6 +87,12 @@ void readConfig() {
80
87
File.clear (File.rdstate () & ~std::ios_base::failbit);
81
88
File.ignore (std::numeric_limits<std::streamsize>::max (), ' \n ' );
82
89
}
90
+
91
+ // Handle '\r' by nullifying it
92
+ const std::streamsize ReadSybmols = File.gcount ();
93
+ if (ReadSybmols > 1 && ' \r ' == Value[ReadSybmols - 2 ])
94
+ Value[ReadSybmols - 2 ] = ' \0 ' ;
95
+
83
96
initValue (Key, Value);
84
97
}
85
98
}
0 commit comments