title: getlogin() c function returns NULL and error "No such file or directory"
body: <p>I have a question regarding the getlogin() function (). I tried to get the login name of my account from the c program using this function. But the function returns a NULL. Using perror shows that the error is "No such file or directory". </p>
  
  <p>I don't get what is the problem. Is there a way to get user login name in a program. </p>
  
  <p>Here is a sample code: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main()
  {
    char *name;
    name = getlogin();
    perror("getlogin() error");
    //printf("This is the login info: %s\n", name);
    return 0;
  }
  </code></pre>
  
  <p>And this is the output:  <code>getlogin() error: No such file or directory</code></p>
  
  <p>Please let me know how to get this right.</p>
  
  <p>Thanks.</p>