title: Race condition stat and mkdir
body: <p>I am working fixing on some coverity issues and i am confused about how to solve toctou for stat a directory and make a directory.</p>
  <pre><code>////////////////////////////////////
  // Make sure storage dir exists. If
  // not, create it.
  if( stat( dir, &amp;statBuff ) != -1 )
  {
      if( S_ISDIR( statBuff.st_mode ) )
      {
          if( (dirPtr = opendir( fabcSsrDbStorageDir )) == NULL)
          {
  
          }
          closedir(dirPtr);
      }
  }
  else
  {
      ////////////////////////////////////
      // dir directory
      // does not exist- create it
      // now.
      if( (mkdir( dir, S_IRWXU )) != 0 )
      {
  
      }
  }
  </code></pre>
  <p>Please give your suggestions
  Thanks</p>