title: Determine `OSTYPE` during runtime in C program
body: <p>In a <code>C</code> program, I need to find the <code>OSTYPE</code> during runtime, on the basis of which I will do some operations. </p>
  
  <p>Here is the code </p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main () {
      const char * ostype = getenv("OSTYPE");
      if (strcasecmp(ostype, /* insert os name */) == 0) ... 
      return 0;
  }
  </code></pre>
  
  <p>But <code>getenv</code> returns <code>NULL</code> (and there is segmentation fault). When I do a <code>echo $OSTYPE</code> in the terminal it prints <code>darwin15</code> . But when I do <code>env | grep OSTYPE</code> nothing gets printed, which means it is not in the list of environment variables. To make it work on my local machine I can go to the <code>.bash_profile</code> and export the <code>OSTYPE</code>  manually but that doesn't solve the problem if I want to run a generated executable on a new machine. </p>
  
  <p>Why is <code>OSTYPE</code> available while running terminal, but apparently not there in the list of environment variables. How to get around this ? </p>