title: LKM Implicit declaration of function stat
body: <p>I am currently writing a Linux Kernel Module (for the first time).</p>
  
  <p>I am trying to use the stat function. I understand that regular imports are not going to work in Kernel code, so I imported their equivalent (that is what I thought...):</p>
  
  <pre><code>#include &lt;linux/stat.h&gt;
  #include &lt;linux/errno.h&gt;
  #include &lt;linux/unistd.h&gt;
  </code></pre>
  
  <p>I don't get any error about the imports directly, but I get the following messages:</p>
  
  <ul>
  <li><strong>error: implicit declaration of function ‘stat’ [-Werror=implicit-function-declaration]</strong></li>
  <li><strong>error: ‘errno’ undeclared (first use in this function)</strong></li>
  </ul>
  
  <p>For the two lines respectively:</p>
  
  <pre><code>int ret = stat(pathname, statbuf);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>errno = ENOENT;
  </code></pre>
  
  <p>Any help woule be welcome.</p>
  
  <p>Thank you.</p>
  
  <p>PS: I am working on Kali 4.9.0-kali4-amd64 but I am trying to write something generic, that could work on multiple versions of Linux.</p>