/**
* collectd - src/common.c
- * Copyright (C) 2005 Florian octo Forster
+ * Copyright (C) 2005,2006 Florian octo Forster
*
* This program is free software; you can redistribute it and/
* or modify it under the terms of the GNU General Public Li-
}
#endif
+ssize_t sread (int fd, void *buf, size_t count)
+{
+ char *ptr;
+ size_t nleft;
+ ssize_t status;
+
+ ptr = (char *) buf;
+ nleft = count;
+
+ while (nleft > 0)
+ {
+ status = read (fd, (void *) ptr, nleft);
+
+ if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+ continue;
+
+ if (status < 0)
+ return (status);
+
+ if (status == 0)
+ {
+ DBG ("Received EOF from fd %i. "
+ "Closing fd and returning error.",
+ fd);
+ close (fd);
+ return (-1);
+ }
+
+ assert (nleft >= status);
+
+ nleft = nleft - status;
+ ptr = ptr + status;
+ }
+
+ return (0);
+}
+
+
+ssize_t swrite (int fd, const void *buf, size_t count)
+{
+ const char *ptr;
+ size_t nleft;
+ ssize_t status;
+
+ ptr = (const char *) buf;
+ nleft = count;
+
+ while (nleft > 0)
+ {
+ status = write (fd, (const void *) ptr, nleft);
+
+ if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+ continue;
+
+ if (status < 0)
+ return (status);
+
+ nleft = nleft - status;
+ ptr = ptr + status;
+ }
+
+ return (0);
+}
+
int strsplit (char *string, char **fields, size_t size)
{
size_t i;
/* * * * *
* Magic *
* * * * */
-int rra_get (char ***ret)
+#if HAVE_LIBRRD
+static int rra_get (char ***ret)
{
static char **rra_def = NULL;
static int rra_num = 0;
*ret = rra_def;
return (rra_num);
}
+#endif /* HAVE_LIBRRD */
static int log_create_file (char *filename, char **ds_def, int ds_num)
{
FILE *log;
int i;
+ if (check_create_dir (filename))
+ return (-1);
+
log = fopen (filename, "w");
if (log == NULL)
{
/* The `%.*s' is needed because there is no null-byte behind
* the name. */
- fprintf(log, ",%.*s", (tmp - name), name);
+ fprintf(log, ",%.*s", (int) (tmp - name), name);
}
fprintf(log, "\n");
fclose(log);
strncpy (full_file, file, 1024);
tmp = full_file + strlen (full_file) - 4;
- assert (tmp > 0);
+ assert ((tmp != NULL) && (tmp > full_file));
/* Change the filename for logfiles. */
if (strncmp (tmp, ".rrd", 4) == 0)