Skip to content

Commit 4c1f4d1

Browse files
committed
applying comments
Signed-off-by: Vlad Romanov <[email protected]>
1 parent d8ec32d commit 4c1f4d1

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

sycl/source/detail/config.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "detail/config.hpp"
9+
#include <CL/sycl/detail/os_util.hpp>
10+
#include <detail/config.hpp>
1011

1112
#include <cstring>
1213
#include <fstream>
@@ -21,7 +22,7 @@ namespace sycl {
2122
namespace detail {
2223

2324
#ifndef SYCL_CONFIG_FILE_NAME
24-
#define SYCL_CONFIG_FILE_NAME "sycl.cfg"
25+
#define SYCL_CONFIG_FILE_NAME "sycl.conf"
2526
#endif // SYCL_CONFIG_FILE_NAME
2627

2728
#define CONFIG(Name, MaxSize, CompileTimeDef) \
@@ -50,17 +51,22 @@ void readConfig() {
5051
static bool Initialized = false;
5152
if (Initialized)
5253
return;
54+
5355
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+
5864
if (File.is_open()) {
5965
// TODO: Use max size from macro instead of 256
6066
char Key[MAX_CONFIG_NAME] = {0}, Value[256] = {0};
6167
while (!File.eof()) {
6268
// Expected fromat:
63-
// ConfigName=Value
69+
// ConfigName=Value\r
6470
// ConfigName=Value
6571
// TODO: Skip spaces before and after '='
6672
File.getline(Key, sizeof(Key), '=');
@@ -72,6 +78,7 @@ void readConfig() {
7278
continue;
7379
}
7480
File.getline(Value, sizeof(Value), '\n');
81+
7582
if (File.fail()) {
7683
// Fail to process the value while config name is OK. It's likely that
7784
// value is too long. Currently just deal what we have got and ignore
@@ -80,6 +87,12 @@ void readConfig() {
8087
File.clear(File.rdstate() & ~std::ios_base::failbit);
8188
File.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
8289
}
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+
8396
initValue(Key, Value);
8497
}
8598
}

0 commit comments

Comments
 (0)