title: snprintf() returning inappropriate value
body: <p>I've been looking over this piece of code for a while, and I can't seem to find my bug.  I think I know how <code>snprintf(dest, n, fmt, src)</code> is supposed to work ( it returns the number of remaining characters in the <code>src</code> buffer after filling the <code>dest</code> buffer with <code>n</code> characters from the <code>fmt</code> string and the <code>src</code> buffer) but it is not doing what I would expect.  Instead of returning the number of remaining characters to be copied, it is returning the <strong>total</strong> characters copied. </p>
  
  <p>The code below:</p>
  
  <pre><code> 40   char header_file_name[200];
   ....
   87   int n_overflow = 0;
   88   n_overflow = snprintf( header_file_name, 200, "%s.h", template_name );
   89   if ( n_overflow &gt; 0 )
   90   {
   91       printf( "That template name is too large; try a smaller template name\n");
   92       printf("n_overflow = %d\n", n_overflow);
   93       printf("header_file_name = %s\n", header_file_name );
   94       printf("length of header_file_name = %d\n", strlen(header_file_name));
   95       printf( "template_name = %s\n", template_name );
   96       printf("length of template_name = %d\n", strlen(template_name));
   97       exit(4);
   98   }
   99   if ( n_overflow &lt; 0 )
  100   {
  101       printf( "An error occurred while handling your input; file: %s, line:%d\n", __FILE__, __LINE__);
  102       exit(1);
  103   }
  </code></pre>
  
  <p>outputs the following:</p>
  
  <pre><code>Compiling template file ABAQUS_Version_5.template
  That template name is too large; try a smaller template name
  n_overflow = 18
  header_file_name = ABAQUS_Version_5.h
  length of header_file_name = 18
  template_name = ABAQUS_Version_5
  length of template_name = 16
  *** Error code 4
  clearmake: Error: Build script failed for "ABAQUS_Version_5.o"
  </code></pre>
  
  <p>What makes it so confusing is that my <code>dest</code> (<code>header_file_name</code>) has a length, and even has data in it after the <code>snprintf()</code> call, and my <code>src</code> (<code>template_name</code>) also has a length and is not <code>NULL</code>.  I've probably just made some gaff in my code, or I don't really understand <code>snprintf()</code>, and have been starring at it for too long.  Any assistance will be greatly appreciated!</p>