title: Mac solution for "safe" alternatives to "unsafe" C/C++ Standard Library functions?
body: <p>What's the best one-stop-shop "safe" C library solution on the Mac?  I use quotes on "safe"/"unsafe" because there is much debate as to the benefits of certain Standard Library functions or their putatively improved alternatives.</p>
  
  <p>Many traditional Standard C Library functions (e.g., <code>vfprintf</code>) are considered to be unsafe due to the potential for buffer overflow or other security problems.</p>
  
  <p>On Windows, the Microsoft C/C++ compilers <a href="http://msdn.microsoft.com/en-us/library/8ef0s5kh.aspx" rel="noreferrer">provide</a> the "_s" functions (e.g., <code>vfprintf_s</code>) as a safer alternative to the standard library calls. These functions are not drop-in replacements since they have the different signatures necessary to provide additional safety information (e.g., buffer length).  They also provide other features such as invalid format string detection, different file security, etc.  As far as I know, this implementation is not available on the Mac.</p>
  
  <p>Does Apple (or a third party) provide anything similar for use with GCC on OSX?</p>
  
  <p>In particular, I'm looking for "safe" implementations of <em>at least</em> the following functions:</p>
  
  <p><code>fopen vfprintf vsprintf sprintf strncpy strcpy strcat</code></p>
  
  <p><em>Please note: This question is about the Mac.  I am NOT asking for your opinions about Microsoft's implementation (unless it's available on the Mac.)  Although some of these functions might be easy to write myself, not all are.  I am NOT asking how to write these myself.  I'm NOT asking for tips on how to use STL classes to do this.  I'm NOT asking how to turn off warnings.  My particular needs are very specific.  I'm trying to identify a best-practice Mac API that is as similar as possible to the traditional C library calls while adding safety.  Of course a portable implementation that works on Mac and Windows (and other operating systems) would be even better.</em></p>