Code

52cf18e4d50d9be425635d5a0ce90b133b8699a7
[pkg-rrdtool.git] / doc / librrd.pod
1 =pod
3 =head1 NAME
5 librrd - RRD library functions
7 =head1 DESCRIPTION
9 B<librrd> contains most of the functionality in B<RRDTool>.  The command
10 line utilities and language bindings are often just wrappers around the
11 code contained in B<librrd>.
13 This manual page documents the B<librrd> API.
15 B<NOTE:> This document is a work in progress, and should be considered
16 incomplete as long as this warning persists.  For more information about
17 the B<librrd> functions, always consult the source code.
19 =head1 UTILITY FUNCTIONS
21 =over
23 =item B<rrd_random()>
25 Generates random numbers just like random().  This further ensures that
26 the random number generator is seeded exactly once per process.
28 =item B<rrd_add_ptr(void ***dest, size_t *dest_size, void *src)>
30 Dynamically resize the array pointed to by C<dest>.  C<dest_size> is a
31 pointer to the current size of C<dest>.  Upon successful realloc(), the
32 C<dest_size> is incremented by 1 and the C<src> pointer is stored at the
33 end of the new C<dest>.  Returns 1 on success, 0 on failure.
35     type **arr = NULL;
36     type *elem = "whatever";
37     size_t arr_size = 0;
38     if (!rrd_add_ptr(&arr, &arr_size, elem))
39         handle_failure();
41 =item B<rrd_add_strdup(char ***dest, size_t *dest_size, char *src)>
43 Like C<rrd_add_ptr>, except adds a C<strdup> of the source string.
45     char **arr = NULL;
46     size_t arr_size = NULL;
47     char *str  = "example text";
48     if (!rrd_add_strdup(&arr, &arr_size, str))
49         handle_failure();
51 =item B<rrd_free_ptrs(void ***src, size_t *cnt)>
53 Free an array of pointers allocated by C<rrd_add_ptr> or
54 C<rrd_add_strdup>.  Also frees the array pointer itself.  On return, the
55 source pointer will be NULL and the count will be zero.
57     /* created as above */
58     rrd_free_ptrs(&arr, &arr_size);
59     /* here, arr == NULL && arr_size == 0 */
61 =back