2 * collectd - src/common.h
3 * Copyright (C) 2005-2007 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
20 * Niki W. Waibel <niki.waibel@gmx.net>
34 void sstrncpy(char *d, const char *s, int len);
35 char *sstrdup(const char *s);
36 void *smalloc(size_t size);
43 * Reads exactly `n' bytes or failes. Syntax and other behavior is analogous
44 * to `read(2)'. If EOF is received the file descriptor is closed and an
48 * `fd' File descriptor to write to.
49 * `buf' Buffer that is to be written.
50 * `count' Numver of bytes in the buffer.
53 * Zero upon success or non-zero if an error occured. `errno' is set in this
56 ssize_t sread (int fd, void *buf, size_t count);
63 * Writes exactly `n' bytes or failes. Syntax and other behavior is analogous
67 * `fd' File descriptor to write to.
68 * `buf' Buffer that is to be written.
69 * `count' Numver of bytes in the buffer.
72 * Zero upon success or non-zero if an error occured. `errno' is set in this
75 ssize_t swrite (int fd, const void *buf, size_t count);
82 * Splits a string into parts and stores pointers to the parts in `fields'.
83 * The characters split at are ` ' (space) and "\t" (tab).
86 * `string' String to split. This string will be modified. `fields' will
87 * contain pointers to parts of this string, so free'ing it
88 * will destroy `fields' as well.
89 * `fields' Array of strings where pointers to the parts will be stored.
90 * `size' Number of elements in the array. No more than `size'
91 * pointers will be stored in `fields'.
94 * Returns the number of parts stored in `fields'.
96 int strsplit (char *string, char **fields, size_t size);
103 * Joins together several parts of a string using `sep' as a seperator. This
104 * is equipollent to the perl buildin `join'.
107 * `dst' Buffer where the result is stored.
108 * `dst_len' Length of the destination buffer. No more than this many
109 * bytes will be written to the memory pointed to by `dst',
110 * including the trailing null-byte.
111 * `fields' Array of strings to be joined.
112 * `fields_num' Number of elements in the `fields' array.
113 * `sep' String to be inserted between any two elements of `fields'.
114 * This string is neither prepended nor appended to the result.
115 * Instead of passing "" (empty string) one can pass NULL.
118 * Returns the number of characters in `dst', NOT including the trailing
119 * null-byte. If an error occured (empty array or `dst' too small) a value
120 * smaller than zero will be returned.
122 int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const char *sep);
129 * Removes slashes from the string `buf' and substitutes them with something
130 * appropriate. This function should be used whenever a path is to be used as
131 * (part of) an instance.
134 * `buf' String to be escaped.
135 * `buf_len' Length of the buffer. No more then this many bytes will be
136 * written to `buf', including the trailing null-byte.
139 * Returns zero upon success and a value smaller than zero upon failure.
141 int escape_slashes (char *buf, int buf_len);
143 /* FIXME: `timeval_sub_timespec' needs a description */
144 int timeval_sub_timespec (struct timeval *tv0, struct timeval *tv1, struct timespec *ret);
146 int check_create_dir (const char *file_orig);
149 int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name);
150 long long get_kstat_value (kstat_t *ksp, char *name);
153 unsigned long long ntohll (unsigned long long n);
154 unsigned long long htonll (unsigned long long n);
156 #endif /* COMMON_H */