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 * Reads exactly `n' bytes or failes. Syntax and other behavior is analogous
46 * to `read(2)'. If EOF is received the file descriptor is closed and an
50 * `fd' File descriptor to write to.
51 * `buf' Buffer that is to be written.
52 * `count' Numver of bytes in the buffer.
55 * Zero upon success or non-zero if an error occured. `errno' is set in this
58 ssize_t sread (int fd, void *buf, size_t count);
65 * Writes exactly `n' bytes or failes. Syntax and other behavior is analogous
69 * `fd' File descriptor to write to.
70 * `buf' Buffer that is to be written.
71 * `count' Numver of bytes in the buffer.
74 * Zero upon success or non-zero if an error occured. `errno' is set in this
77 ssize_t swrite (int fd, const void *buf, size_t count);
84 * Splits a string into parts and stores pointers to the parts in `fields'.
85 * The characters split at are ` ' (space) and "\t" (tab).
88 * `string' String to split. This string will be modified. `fields' will
89 * contain pointers to parts of this string, so free'ing it
90 * will destroy `fields' as well.
91 * `fields' Array of strings where pointers to the parts will be stored.
92 * `size' Number of elements in the array. No more than `size'
93 * pointers will be stored in `fields'.
96 * Returns the number of parts stored in `fields'.
98 int strsplit (char *string, char **fields, size_t size);
105 * Joins together several parts of a string using `sep' as a seperator. This
106 * is equipollent to the perl buildin `join'.
109 * `dst' Buffer where the result is stored.
110 * `dst_len' Length of the destination buffer. No more than this many
111 * bytes will be written to the memory pointed to by `dst',
112 * including the trailing null-byte.
113 * `fields' Array of strings to be joined.
114 * `fields_num' Number of elements in the `fields' array.
115 * `sep' String to be inserted between any two elements of `fields'.
116 * This string is neither prepended nor appended to the result.
117 * Instead of passing "" (empty string) one can pass NULL.
120 * Returns the number of characters in `dst', NOT including the trailing
121 * null-byte. If an error occured (empty array or `dst' too small) a value
122 * smaller than zero will be returned.
124 int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const char *sep);
131 * Removes slashes from the string `buf' and substitutes them with something
132 * appropriate. This function should be used whenever a path is to be used as
133 * (part of) an instance.
136 * `buf' String to be escaped.
137 * `buf_len' Length of the buffer. No more then this many bytes will be
138 * written to `buf', including the trailing null-byte.
141 * Returns zero upon success and a value smaller than zero upon failure.
143 int escape_slashes (char *buf, int buf_len);
145 /* FIXME: `timeval_sub_timespec' needs a description */
146 int timeval_sub_timespec (struct timeval *tv0, struct timeval *tv1, struct timespec *ret);
148 int rrd_update_file (char *host, char *file, char *values,
149 char **ds_def, int ds_num);
152 int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name);
153 long long get_kstat_value (kstat_t *ksp, char *name);
156 #endif /* COMMON_H */