diff options
Diffstat (limited to 'runtime/docs/html/scbuf_8c-source.html')
-rw-r--r-- | runtime/docs/html/scbuf_8c-source.html | 164 |
1 files changed, 94 insertions, 70 deletions
diff --git a/runtime/docs/html/scbuf_8c-source.html b/runtime/docs/html/scbuf_8c-source.html index a9e9ddc8..ffdfaac7 100644 --- a/runtime/docs/html/scbuf_8c-source.html +++ b/runtime/docs/html/scbuf_8c-source.html @@ -5,75 +5,99 @@ </head><body> <!-- Generated by Doxygen 1.4.1 --> <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> -<h1>scbuf.c</h1><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef _SCBUF_C_</span> -00002 <span class="preprocessor"></span><span class="preprocessor">#define _SCBUF_C_</span> +<h1>scbuf.c</h1><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef _SCBUF_C_ </span><span class="comment">/* -*- linux-c -*- */</span> +00002 <span class="preprocessor">#define _SCBUF_C_</span> 00003 <span class="preprocessor"></span> -00004 <span class="comment">/* -*- linux-c -*- */</span><span class="comment"></span> -00005 <span class="comment">/** @file scbuf.c</span> -00006 <span class="comment"> * @addtogroup scbuf Scratch Buffer</span> -00007 <span class="comment"> * Scratch Buffer Functions.</span> -00008 <span class="comment"> * The scratch buffer is for collecting output before storing in a map,</span> -00009 <span class="comment"> * printing, etc. This is a per-cpu static buffer. It is necessary because </span> -00010 <span class="comment"> * of the limited stack space available in the kernel.</span> -00011 <span class="comment"> * @{</span> -00012 <span class="comment"> */</span> -00013 <span class="comment"></span> -00014 <span class="comment">/** Maximum size of buffer, not including terminating NULL */</span> -<a name="l00015"></a><a class="code" href="group__scbuf.html#ga6">00015</a> <span class="preprocessor">#define STP_BUF_LEN 8191</span> -00016 <span class="preprocessor"></span><span class="comment"></span> -00017 <span class="comment">/** Scratch buffer for printing, building strings, etc */</span> -<a name="l00018"></a><a class="code" href="group__scbuf.html#ga0">00018</a> <span class="keywordtype">char</span> <a class="code" href="group__scbuf.html#ga0">_stp_scbuf</a>[<a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a>+1]; -00019 <span class="keyword">static</span> <span class="keywordtype">int</span> _stp_scbuf_len = <a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a>; -00020 <span class="comment"></span> -00021 <span class="comment">/** Sprint into the scratch buffer.</span> -00022 <span class="comment"> * Like printf, except output goes into #_stp_scbuf,</span> -00023 <span class="comment"> * which will contain the null-terminated output.</span> -00024 <span class="comment"> * Safe because overflowing #_stp_scbuf is not allowed.</span> -00025 <span class="comment"> * Size is limited by length of scratch buffer, STP_BUF_LEN.</span> -00026 <span class="comment"> *</span> -00027 <span class="comment"> * @param fmt A printf-style format string followed by a </span> -00028 <span class="comment"> * variable number of args.</span> -00029 <span class="comment"> * @sa _stp_scbuf_clear</span> -00030 <span class="comment"> */</span> -00031 -<a name="l00032"></a><a class="code" href="group__scbuf.html#ga2">00032</a> <span class="keywordtype">void</span> <a class="code" href="group__scbuf.html#ga2">_stp_sprint</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, ...) -00033 { -00034 <span class="keywordtype">int</span> num; -00035 va_list args; -00036 <span class="keywordtype">char</span> *buf = <a class="code" href="group__scbuf.html#ga0">_stp_scbuf</a> + <a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a> - _stp_scbuf_len; -00037 va_start(args, fmt); -00038 num = vscnprintf(buf, _stp_scbuf_len, fmt, args); -00039 va_end(args); -00040 <span class="keywordflow">if</span> (num > 0) -00041 _stp_scbuf_len -= num; -00042 } -00043 -00044 <span class="keywordtype">void</span> _stp_sprint_str (<span class="keyword">const</span> <span class="keywordtype">char</span> *str) -00045 { -00046 <span class="keywordtype">char</span> *buf = <a class="code" href="group__scbuf.html#ga0">_stp_scbuf</a> + <a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a> - _stp_scbuf_len; -00047 <span class="keywordtype">int</span> num = strlen (str); -00048 <span class="keywordflow">if</span> (num > _stp_scbuf_len) -00049 num = _stp_scbuf_len; -00050 strncpy (buf, str, num); -00051 _stp_scbuf_len -= num; -00052 } -00053 <span class="comment"></span> -00054 <span class="comment">/** Clear the scratch buffer.</span> -00055 <span class="comment"> * Output from _stp_sprint() will accumulate in the buffer</span> -00056 <span class="comment"> * until this is called.</span> -00057 <span class="comment"> */</span> -00058 -<a name="l00059"></a><a class="code" href="group__scbuf.html#ga4">00059</a> <span class="keywordtype">void</span> _stp_scbuf_clear (<span class="keywordtype">void</span>) -00060 { -00061 _stp_scbuf_len = <a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a>; -00062 <a class="code" href="group__scbuf.html#ga0">_stp_scbuf</a>[0] = 0; -00063 } -00064 -00065 <span class="keyword">static</span> <span class="keywordtype">char</span> *_stp_scbuf_cur (<span class="keywordtype">void</span>) -00066 { -00067 <span class="keywordflow">return</span> <a class="code" href="group__scbuf.html#ga0">_stp_scbuf</a> + <a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a> - _stp_scbuf_len; -00068 } -00069 <span class="comment"></span> -00070 <span class="comment">/** @} */</span> -00071 <span class="preprocessor">#endif </span><span class="comment">/* _SCBUF_C_ */</span> +00004 <span class="preprocessor">#include <linux/config.h></span> +00005 <span class="comment"></span> +00006 <span class="comment">/** @file scbuf.c</span> +00007 <span class="comment"> * @addtogroup scbuf Scratch Buffer</span> +00008 <span class="comment"> * Scratch Buffer Functions.</span> +00009 <span class="comment"> * The scratch buffer is for collecting output before storing in a map,</span> +00010 <span class="comment"> * printing, etc. This is a per-cpu static buffer. It is necessary because </span> +00011 <span class="comment"> * of the limited stack space available in the kernel.</span> +00012 <span class="comment"> * @todo Need careful review of these to insure safety.</span> +00013 <span class="comment"> * @{</span> +00014 <span class="comment"> */</span> +00015 <span class="comment"></span> +00016 <span class="comment">/** Maximum size of buffer, not including terminating NULL */</span> +<a name="l00017"></a><a class="code" href="group__scbuf.html#ga6">00017</a> <span class="preprocessor">#define STP_BUF_LEN 8191</span> +00018 <span class="preprocessor"></span><span class="comment"></span> +00019 <span class="comment">/** Scratch buffer for printing, building strings, etc */</span> +00020 <span class="keyword">static</span> <span class="keywordtype">char</span> _stp_scbuf[NR_CPUS][<a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a>+1]; +00021 <span class="keyword">static</span> <span class="keywordtype">int</span> _stp_scbuf_len[NR_CPUS]; +00022 <span class="comment"></span> +00023 <span class="comment">/** Sprint into the scratch buffer.</span> +00024 <span class="comment"> * Like printf, except output goes into a global scratch buffer</span> +00025 <span class="comment"> * which will contain the null-terminated output.</span> +00026 <span class="comment"> * Safe because overflowing the buffer is not allowed.</span> +00027 <span class="comment"> * Size is limited by length of scratch buffer, STP_BUF_LEN.</span> +00028 <span class="comment"> *</span> +00029 <span class="comment"> * @param fmt A printf-style format string followed by a </span> +00030 <span class="comment"> * variable number of args.</span> +00031 <span class="comment"> * @sa _stp_scbuf_clear</span> +00032 <span class="comment"> */</span> +00033 +<a name="l00034"></a><a class="code" href="group__scbuf.html#ga2">00034</a> <span class="keywordtype">void</span> <a class="code" href="group__scbuf.html#ga2">_stp_sprint</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, ...) +00035 { +00036 <span class="keywordtype">int</span> num; +00037 va_list args; +00038 <span class="keywordtype">int</span> cpu = smp_processor_id(); +00039 <span class="keywordtype">char</span> *buf = _stp_scbuf[cpu] + <a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a> - _stp_scbuf_len[cpu]; +00040 va_start(args, fmt); +00041 num = vscnprintf(buf, _stp_scbuf_len[cpu], fmt, args); +00042 va_end(args); +00043 <span class="keywordflow">if</span> (num > 0) +00044 _stp_scbuf_len[cpu] -= num; +00045 } +00046 <span class="comment"></span> +00047 <span class="comment">/** Write a string into the scratch buffer.</span> +00048 <span class="comment"> * Copies a string into a global scratch buffer.</span> +00049 <span class="comment"> * Safe because overflowing the buffer is not allowed.</span> +00050 <span class="comment"> * Size is limited by length of scratch buffer, STP_BUF_LEN.</span> +00051 <span class="comment"> * This is more efficient than using _stp_sprint().</span> +00052 <span class="comment"> *</span> +00053 <span class="comment"> * @param str A string.</span> +00054 <span class="comment"> */</span> +00055 +<a name="l00056"></a><a class="code" href="group__scbuf.html#ga3">00056</a> <span class="keywordtype">void</span> <a class="code" href="group__scbuf.html#ga3">_stp_sprint_str</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *str) +00057 { +00058 <span class="keywordtype">int</span> cpu = smp_processor_id(); +00059 <span class="keywordtype">char</span> *buf = _stp_scbuf[cpu] + <a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a> - _stp_scbuf_len[cpu]; +00060 <span class="keywordtype">int</span> num = strlen (str); +00061 <span class="keywordflow">if</span> (num > _stp_scbuf_len[cpu]) +00062 num = _stp_scbuf_len[cpu]; +00063 strncpy (buf, str, num); +00064 _stp_scbuf_len[cpu] -= num; +00065 } +00066 <span class="comment"></span> +00067 <span class="comment">/** Clear the scratch buffer.</span> +00068 <span class="comment"> * This function should be called before anything is written to </span> +00069 <span class="comment"> * the scratch buffer. Output will accumulate in the buffer</span> +00070 <span class="comment"> * until this function is called again. </span> +00071 <span class="comment"> * @returns A pointer to the buffer.</span> +00072 <span class="comment"> */</span> +00073 +<a name="l00074"></a><a class="code" href="group__scbuf.html#ga4">00074</a> <span class="keywordtype">char</span> *<a class="code" href="group__scbuf.html#ga4">_stp_scbuf_clear</a> (<span class="keywordtype">void</span>) +00075 { +00076 <span class="keywordtype">int</span> cpu = smp_processor_id(); +00077 _stp_scbuf_len[cpu] = <a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a>; +00078 *_stp_scbuf[cpu] = 0; +00079 <span class="keywordflow">return</span> _stp_scbuf[cpu]; +00080 } +00081 <span class="comment"></span> +00082 <span class="comment">/** Get the current top of the scratch buffer.</span> +00083 <span class="comment"> * This returns the address of the location where</span> +00084 <span class="comment"> * data will be written next in the scratch buffer.</span> +00085 <span class="comment"> * @returns A pointer</span> +00086 <span class="comment"> */</span> +00087 +00088 <span class="keyword">static</span> <span class="keywordtype">char</span> *_stp_scbuf_cur (<span class="keywordtype">void</span>) +00089 { +00090 <span class="keywordtype">int</span> cpu = smp_processor_id(); +00091 <span class="keywordflow">return</span> _stp_scbuf[cpu] + <a class="code" href="group__scbuf.html#ga6">STP_BUF_LEN</a> - _stp_scbuf_len[cpu]; +00092 } +00093 <span class="comment"></span> +00094 <span class="comment">/** @} */</span> +00095 <span class="preprocessor">#endif </span><span class="comment">/* _SCBUF_C_ */</span> </pre></div></body></html> |