title: FreeBSD SysCall in C -> implicit declaration of function 'modfind'
body: <p>I'm extending a FreeBSD module, and I need to be able to call 2 system call functions that I wrote  (using KLD).  I know that the system call functions themselves are working fine, since I have a separate test program for them that calls them and returns the correct values just fine.</p>
  
  <p>However, when I tried plugging in the appropriate parts of that test program into the real program, I get</p>
  
  <pre><code>vnode.c: In function 'getSyscall':
  vnode.c:1014: warning: implicit declaration of function 'modfind'
  vnode.c:1022: warning: implicit declaration of function 'modstat'
  *** Error code 1
  </code></pre>
  
  <p>I have all of the includes of the (working) test program in the real thing, so I don't understand why it can't find the modfind and modstat functions.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/syscall.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/module.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/param.h&gt;
  
  // Lots of other unrelated functions here
  
  
  /*
   *
   * returns a syscall number or -1 for error
   */
  int getSyscall
  (char *str)
  {
      struct module_stat stat;
      int modid;
      int syscallnum;
  
      modid = modfind(str);
      if (modid == -1)
      {
          perror("modfind: ");
          return -1;
      }
  
      stat.version = sizeof(stat);
      if (modstat(modid, &amp;stat) == -1)
      {
          perror("modstat: ");
          return -1;
      }
  
      syscallnum = stat.data.intval;
  
      return syscallnum;
  }
  </code></pre>