Skip to content

Commit 1ed7353

Browse files
committed
fix other mistakes in linux implementation (lack of 2nd argument in open function, not treating TAB as space, missing header)
1 parent bede820 commit 1ed7353

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/nbl/system/ISystem.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,30 +360,33 @@ bool ISystem::isDebuggerAttached()
360360
#include <sys/stat.h>
361361
#include <fcntl.h>
362362
#include <unistd.h>
363+
#include <cstring>
363364

364365
bool ISystem::isDebuggerAttached()
365366
{
366367
constexpr char debuggerPidStr[] = "TracerPid:";
367368
constexpr size_t bufSize = 4096;
368-
char buf[bufSize];
369369

370-
const int status = open("/proc/self/status");
370+
const int status = open("/proc/self/status", O_RDONLY);
371371
if (status == -1)
372372
return false;
373373

374-
const size_t numRead = read(status, static_cast<void*>(buf), sizeof(buf) - 1);
374+
char buf[bufSize];
375+
const size_t numRead = read(status, static_cast<void*>(buf), bufSize - 1);
375376
close(status);
376377

377378
buf[numRead] = '\0';
378379
const auto offset = strstr(buf, debuggerPidStr);
379380
if (not offset)
380381
return false;
381382

382-
auto isSpace = [](const char c) { return c == ' '; };
383+
384+
auto isSpace = [](const char c) { return c == ' ' || c == '\t'; };
383385
auto isDigit = [](const char c) { return c >= '0' && c <= '9'; };
384386

385387
for (const char* cPtr = offset + sizeof(debuggerPidStr) - 1; cPtr <= buf + numRead; cPtr++)
386388
{
389+
std::cout << static_cast<int>(*cPtr) << "\n";
387390
if (isSpace(*cPtr))
388391
continue;
389392
else

0 commit comments

Comments
 (0)