title: Test if file exists with Postgres
body: <p>I need to create a function to test if a file exist with postgres. I'm doing it with C language, but i'm having a problem. The code is:</p>
  
  <pre><code>#include "postgres.h"
  #include &lt;string.h&gt;
  #include "fmgr.h"
  #include &lt;stdio.h&gt;
  #include&lt;sys/stat.h&gt;
  
  #ifdef PG_MODULE_MAGIC
  PG_MODULE_MAGIC;
  #endif
  
  /* by value */
  
  PG_FUNCTION_INFO_V1(file_exists);
  Datum
  file_exists (PG_FUNCTION_ARGS)
  {
     text *fileName= PG_GETARG_TEXT_P(0);
  
     struct stat buf;
     int i = stat(fileName, &amp;buf);
       /* File found */
       if ( i == 0 )
       {
         PG_RETURN_INT32(1);
       }
       PG_RETURN_INT32(0);
  
  }
  </code></pre>
  
  <p>I think the problem is with the first argument in the "stat" function, because fileName is a text and this function receives a char.</p>
  
  <p>This is the first time i write C code, so maybe everything is wrong.</p>