2 * collectd - src/common.h
3 * Copyright (C) 2005,2006 Florian octo Forster
5 * This program is free software; you can redistribute it and/
6 * or modify it under the terms of the GNU General Public Li-
7 * cence as published by the Free Software Foundation; either
8 * version 2 of the Licence, or any later version.
10 * This program is distributed in the hope that it will be use-
11 * ful, but WITHOUT ANY WARRANTY; without even the implied war-
12 * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public Licence for more details.
15 * You should have received a copy of the GNU General Public
16 * Licence along with this program; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21 * Florian octo Forster <octo at verplant.org>
22 * Niki W. Waibel <niki.waibel@gmx.net>
36 void sstrncpy(char *d, const char *s, int len);
37 char *sstrdup(const char *s);
38 void *smalloc(size_t size);
45 * Splits a string into parts and stores pointers to the parts in `fields'.
46 * The characters split at are ` ' (space) and "\t" (tab).
49 * `string' String to split. This string will be modified. `fields' will
50 * contain pointers to parts of this string, so free'ing it
51 * will destroy `fields' as well.
52 * `fields' Array of strings where pointers to the parts will be stored.
53 * `size' Number of elements in the array. No more than `size'
54 * pointers will be stored in `fields'.
57 * Returns the number of parts stored in `fields'.
59 int strsplit (char *string, char **fields, size_t size);
66 * Joins together several parts of a string using `sep' as a seperator. This
67 * is equipollent to the perl buildin `join'.
70 * `dst' Buffer where the result is stored.
71 * `dst_len' Length of the destination buffer. No more than this many
72 * bytes will be written to the memory pointed to by `dst',
73 * including the trailing null-byte.
74 * `fields' Array of strings to be joined.
75 * `fields_num' Number of elements in the `fields' array.
76 * `sep' String to be inserted between any two elements of `fields'.
77 * This string is neither prepended nor appended to the result.
78 * Instead of passing "" (empty string) one can pass NULL.
81 * Returns the number of characters in `dst', NOT including the trailing
82 * null-byte. If an error occured (empty array or `dst' too small) a value
83 * smaller than zero will be returned.
85 int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const char *sep);
92 * Removes slashes from the string `buf' and substitutes them with something
93 * appropriate. This function should be used whenever a path is to be used as
94 * (part of) an instance.
97 * `buf' String to be escaped.
98 * `buf_len' Length of the buffer. No more then this many bytes will be
99 * written to `buf', including the trailing null-byte.
102 * Returns zero upon success and a value smaller than zero upon failure.
104 int escape_slashes (char *buf, int buf_len);
106 /* FIXME: `timeval_sub_timespec' needs a description */
107 int timeval_sub_timespec (struct timeval *tv0, struct timeval *tv1, struct timespec *ret);
109 int rrd_update_file (char *host, char *file, char *values,
110 char **ds_def, int ds_num);
113 int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name);
114 long long get_kstat_value (kstat_t *ksp, char *name);
117 #endif /* COMMON_H */