writeBuffer_8c-source.html 4.7 KB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xmlrpc: reader/commonReader/writeBuffer.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<h1>reader/commonReader/writeBuffer.c</h1><a href="writeBuffer_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;stdio.h&gt;</span>      <span class="comment">/* for ferror() */</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;string.h&gt;</span>     <span class="comment">/* for memset and stuff */</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 
<a name="l00005"></a>00005 <span class="keywordtype">int</span>
<a name="l00006"></a><a class="code" href="writeBuffer_8c.html#a947cab623514e5a9c9700bca074b77e">00006</a> <a class="code" href="writeBuffer_8h.html#a947cab623514e5a9c9700bca074b77e">writeBuffer</a>(<span class="keywordtype">char</span> ** buffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> * readPos, FILE * wHandle)
<a name="l00007"></a>00007 {
<a name="l00008"></a>00008     <span class="keywordtype">char</span> * nlpos   = strchr(*buffer, <span class="charliteral">'\n'</span>);
<a name="l00009"></a>00009     <span class="keywordtype">int</span>    written = 0;
<a name="l00010"></a>00010 
<a name="l00011"></a>00011     <span class="keywordflow">while</span> (NULL != nlpos) {
<a name="l00012"></a>00012         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> moveSize, clearSize;
<a name="l00013"></a>00013         <span class="keywordtype">char</span> *       actAddr;
<a name="l00014"></a>00014 
<a name="l00015"></a>00015         *nlpos   = <span class="charliteral">'\0'</span>;
<a name="l00016"></a>00016 
<a name="l00017"></a>00017         <span class="keywordflow">if</span> (0 != strlen(*buffer)) {
<a name="l00018"></a>00018             <span class="comment">/* write remaining stuff to file */</span>
<a name="l00019"></a>00019             fputs(*buffer, wHandle);
<a name="l00020"></a>00020             <span class="keywordflow">if</span> (ferror(wHandle)) {
<a name="l00021"></a>00021                 <span class="keywordflow">return</span> -1;
<a name="l00022"></a>00022             }
<a name="l00023"></a>00023 
<a name="l00024"></a>00024             fputc(<span class="charliteral">'\n'</span>, wHandle);
<a name="l00025"></a>00025             <span class="keywordflow">if</span> (ferror(wHandle)) {
<a name="l00026"></a>00026                 <span class="keywordflow">return</span> -1;
<a name="l00027"></a>00027             }
<a name="l00028"></a>00028 
<a name="l00029"></a>00029             fflush(wHandle);
<a name="l00030"></a>00030             <span class="keywordflow">if</span> (ferror(wHandle)) {
<a name="l00031"></a>00031                 <span class="keywordflow">return</span> -1;
<a name="l00032"></a>00032             }
<a name="l00033"></a>00033 
<a name="l00034"></a>00034             written += strlen(*buffer) + 1;
<a name="l00035"></a>00035         }
<a name="l00036"></a>00036 
<a name="l00037"></a>00037         actAddr    = *buffer + *readPos;
<a name="l00038"></a>00038         moveSize   = actAddr - nlpos - 1;
<a name="l00039"></a>00039         clearSize  = actAddr - *buffer - moveSize;
<a name="l00040"></a>00040         memmove(*buffer, nlpos+1, moveSize);
<a name="l00041"></a>00041         memset(*buffer + moveSize, 0, clearSize);
<a name="l00042"></a>00042         *readPos = moveSize;
<a name="l00043"></a>00043 
<a name="l00044"></a>00044         nlpos = strchr(*buffer, <span class="charliteral">'\n'</span>);
<a name="l00045"></a>00045     }
<a name="l00046"></a>00046 
<a name="l00047"></a>00047     <span class="keywordflow">return</span> written;
<a name="l00048"></a>00048 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 10 01:24:35 2010 for xmlrpc by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>