2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
6
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
7
<link rev="made" href="mailto:root@localhost" />
10
<body style="background-color: white">
15
<p><a name="__index__"></a></p>
20
<li><a href="#name">NAME</a></li>
21
<li><a href="#description">DESCRIPTION</a></li>
22
<li><a href="#core_functions">CORE FUNCTIONS</a></li>
23
<li><a href="#utility_functions">UTILITY FUNCTIONS</a></li>
24
<li><a href="#author">AUTHOR</a></li>
36
<h1><a name="name">NAME</a></h1>
37
<p>librrd - RRD library functions</p>
41
<h1><a name="description">DESCRIPTION</a></h1>
42
<p><strong>librrd</strong> contains most of the functionality in <strong>RRDTool</strong>. The command
43
line utilities and language bindings are often just wrappers around the
44
code contained in <strong>librrd</strong>.</p>
45
<p>This manual page documents the <strong>librrd</strong> API.</p>
46
<p><strong>NOTE:</strong> This document is a work in progress, and should be considered
47
incomplete as long as this warning persists. For more information about
48
the <strong>librrd</strong> functions, always consult the source code.</p>
52
<h1><a name="core_functions">CORE FUNCTIONS</a></h1>
54
<dt><strong><a name="rrd_dump_cb_r" class="item"><strong>rrd_dump_cb_r(char *filename, int opt_header, rrd_output_callback_t cb, void *user)</strong></a></strong></dt>
57
<p>In some situations it is necessary to get the output of <code>rrd_dump</code> without
58
writing it to a file or the standard output. In such cases an application
59
can ask <strong>rrd_dump_cb_r</strong> to call an user-defined function each time there
60
is output to be stored somewhere. This can be used, to e.g. directly feed
61
an XML parser with the dumped output or transfer the resulting string
63
<p>The arguments for <strong>rrd_dump_cb_r</strong> are the same as for <strong>rrd_dump_opt_r</strong>
64
except that the output filename parameter is replaced by the user-defined
65
callback function and an additional parameter for the callback function
66
that is passed untouched, i.e. to store information about the callback state
67
needed for the user-defined callback to function properly.</p>
68
<p>Recent versions of <strong>rrd_dump_opt_r</strong> internally use this callback mechanism
69
to write their output to the file provided by the user.</p>
71
size_t rrd_dump_opt_cb_fileout(
76
return fwrite(data, 1, len, (FILE *)user);
78
<p>The associated call for <strong>rrd_dump_cb_r</strong> looks like</p>
80
res = rrd_dump_cb_r(filename, opt_header,
81
rrd_dump_opt_cb_fileout, (void *)out_file);</pre>
82
<p>where the last parameter specifies the file handle <strong>rrd_dump_opt_cb_fileout</strong>
83
should write to. There's no specific condition for the callback to detect
84
when it is called for the first time, nor for the last time. If you require
85
this for initialization and cleanup you should do those tasks before and
86
after calling <strong>rrd_dump_cr_r</strong> respectively.</p>
92
<h1><a name="utility_functions">UTILITY FUNCTIONS</a></h1>
94
<dt><strong><a name="rrd_random" class="item"><strong>rrd_random()</strong></a></strong></dt>
97
<p>Generates random numbers just like <code>random()</code>. This further ensures that
98
the random number generator is seeded exactly once per process.</p>
100
<dt><strong><a name="rrd_add_ptr" class="item"><strong>rrd_add_ptr(void ***dest, size_t *dest_size, void *src)</strong></a></strong></dt>
103
<p>Dynamically resize the array pointed to by <code>dest</code>. <code>dest_size</code> is a
104
pointer to the current size of <code>dest</code>. Upon successful <code>realloc()</code>, the
105
<code>dest_size</code> is incremented by 1 and the <code>src</code> pointer is stored at the
106
end of the new <code>dest</code>. Returns 1 on success, 0 on failure.</p>
109
type *elem = "whatever";
111
if (!rrd_add_ptr(&arr, &arr_size, elem))
112
handle_failure();</pre>
114
<dt><strong><a name="rrd_add_strdup" class="item"><strong>rrd_add_strdup(char ***dest, size_t *dest_size, char *src)</strong></a></strong></dt>
117
<p>Like <a href="#rrd_add_ptr"><code>rrd_add_ptr</code></a>, except adds a <code>strdup</code> of the source string.</p>
120
size_t arr_size = NULL;
121
char *str = "example text";
122
if (!rrd_add_strdup(&arr, &arr_size, str))
123
handle_failure();</pre>
125
<dt><strong><a name="rrd_free_ptrs" class="item"><strong>rrd_free_ptrs(void ***src, size_t *cnt)</strong></a></strong></dt>
128
<p>Free an array of pointers allocated by <a href="#rrd_add_ptr"><code>rrd_add_ptr</code></a> or
129
<a href="#rrd_add_strdup"><code>rrd_add_strdup</code></a>. Also frees the array pointer itself. On return, the
130
source pointer will be NULL and the count will be zero.</p>
132
/* created as above */
133
rrd_free_ptrs(&arr, &arr_size);
134
/* here, arr == NULL && arr_size == 0 */</pre>
136
<dt><strong><a name="rrd_mkdir_p" class="item"><strong>rrd_mkdir_p(const char *pathname, mode_t mode)</strong></a></strong></dt>
139
<p>Create the directory named <code>pathname</code> including all of its parent
140
directories (similar to <code>mkdir -p</code> on the command line - see <em>mkdir(1)</em> for
141
more information). The argument <code>mode</code> specifies the permissions to use. It
142
is modified by the process's <code>umask</code>. See <em>mkdir(2)</em> for more details.</p>
143
<p>The function returns 0 on success, a negative value else. In case of an error,
144
<code>errno</code> is set accordingly. Aside from the errors documented in <em>mkdir(2)</em>,
145
the function may fail with the following errors:</p>
147
<dt><strong><a name="einval" class="item"><strong>EINVAL</strong></a></strong></dt>
150
<p><code>pathname</code> is <code>NULL</code> or the empty string.</p>
152
<dt><strong><a name="enomem" class="item"><strong>ENOMEM</strong></a></strong></dt>
155
<p>Insufficient memory was available.</p>
157
<dt><strong><a name="stat" class="item"><strong>any error returned by <a href="#stat">stat(2)</a></strong></a></strong></dt>
160
<p>In contrast to <em>mkdir(2)</em>, the function does <strong>not</strong> fail if <code>pathname</code>
161
already exists and is a directory.</p>
167
<h1><a name="author">AUTHOR</a></h1>
168
<p>RRD Contributors <<a href="mailto:rrd-developers@lists.oetiker.ch">rrd-developers@lists.oetiker.ch</a>></p>