writeBuffer_8c-source.html
4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!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 Page</span></a></li>
<li><a href="annotated.html"><span>Data 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 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 <stdio.h></span> <span class="comment">/* for ferror() */</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include <string.h></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
<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>