Alberto
Alberto

Reputation: 194

OS detection using only open(), read(), write() and close()

I'm writing some code that is going to run under an hypervisor which only allows open, read, write and close syscalls to the external world.

Since part of the code is dependant on the platform it is being run on, I'd like to be able to automatically choose the appropriate code-path at runtime.

What is the most robust way of detecting the operating system using only these syscalls? I'm primarily interested in detecting windows and linux, but osx would be useful too.

Upvotes: 0

Views: 87

Answers (1)

keltar
keltar

Reputation: 18409

uname watches for /proc/sys/kernel/ostype, you could use that. For windows, it's worse. In theory, you should have C:\windows\system32\kernel32.dll. The problem is, however, that windows installation root is not required to be 'C:\' (although it's very common) - so i highly doubt ordinary open() could be considered reliable.

Upvotes: 1

Related Questions