/**
* collectd - src/common.h
- * Copyright (C) 2005-2014 Florian octo Forster
+ * Copyright (C) 2005-2015 Florian octo Forster
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
*/
ssize_t sread (int fd, void *buf, size_t count);
+/* read_file reads the contents of "file" into memory and stores a pointer in
+ * "ret_data", which must be freed by the caller. The number of bytes read is
+ * stored in "ret_data_size". On success, 0 is returned. On failure, an error
+ * code is stored in "errno" and -1 is returned; "ret_data" and "ret_data_size"
+ * are left unmodified. */
+int read_file (char const *file, void **ret_data, size_t *ret_data_size);
+
/*
* NAME
* swrite
*/
int escape_slashes (char *buffer, size_t buffer_size);
+/**
+ * NAME
+ * escape_string
+ *
+ * DESCRIPTION
+ * escape_string quotes and escapes a string to be usable with collectd's
+ * plain text protocol. "simple" strings are left as they are, for example if
+ * buffer is 'simple' before the call, it will remain 'simple'. However, if
+ * buffer contains 'more "complex"' before the call, the returned buffer will
+ * contain '"more \"complex\""'.
+ *
+ * If the buffer is too small to contain the escaped string, the string will
+ * be truncated. However, leading and trailing double quotes, as well as an
+ * ending null byte are guaranteed.
+ *
+ * RETURN VALUE
+ * Returns zero on success, even if the string was truncated. Non-zero on
+ * failure.
+ */
+int escape_string (char *buffer, size_t buffer_size);
+
/*
* NAME
* replace_special