Shazter
Shazter

Reputation: 171

How to check OS (Linux or Android) during runtime with Native C

I would like to check if the current operating system is linux or android during runtime with native C. Is it possible? Because I have to execute different code depending on the OS.

Upvotes: 2

Views: 976

Answers (1)

Vladyslav Marchenko
Vladyslav Marchenko

Reputation: 671

To ensure program runs on Android you can check environment variables named ANDROID_ROOT and ANDROID_DATA. Usually they are present and refer to /system and /data folders.

C: You can use getenv function from stdlib.h:

getenv("ANDROID_ROOT");
getenv("ANDROID_DATA");

CLI:

$ env | grep ANDROID_

Upvotes: 2

Related Questions