13 static int foreach_rrd_file (const char *dir, /* {{{ */
14 int (*callback) (const char *, void *),
28 while ((entry = readdir (dh)) != NULL)
31 char abspath[PATH_MAX + 1];
34 if (entry->d_name[0] == '.')
37 d_name_len = strlen (entry->d_name);
41 if (strcasecmp (".rrd", entry->d_name + (d_name_len - 4)) != 0)
44 snprintf (abspath, sizeof (abspath), "%s/%s", dir, entry->d_name);
45 abspath[sizeof (abspath) - 1] = 0;
47 memset (&statbuf, 0, sizeof (statbuf));
49 status = stat (abspath, &statbuf);
53 if (!S_ISREG (statbuf.st_mode))
56 entry->d_name[d_name_len - 4] = 0;
58 status = (*callback) (entry->d_name, user_data);
61 } /* while (readdir) */
65 } /* }}} int foreach_rrd_file */
67 static int foreach_dir (const char *dir, /* {{{ */
68 int (*callback) (const char *, void *),
82 while ((entry = readdir (dh)) != NULL)
85 char abspath[PATH_MAX + 1];
87 if (entry->d_name[0] == '.')
90 snprintf (abspath, sizeof (abspath), "%s/%s", dir, entry->d_name);
91 abspath[sizeof (abspath) - 1] = 0;
93 memset (&statbuf, 0, sizeof (statbuf));
95 status = stat (abspath, &statbuf);
99 if (!S_ISDIR (statbuf.st_mode))
102 status = (*callback) (entry->d_name, user_data);
105 } /* while (readdir) */
109 } /* }}} int foreach_dir */
111 int foreach_type (const char *host, const char *plugin, /* {{{ */
112 callback_type_t callback, void *user_data)
114 char abspath[PATH_MAX + 1];
116 if ((host == NULL) || (plugin == NULL))
119 snprintf (abspath, sizeof (abspath), "%s/%s/%s", DATA_DIR, host, plugin);
120 abspath[sizeof (abspath) - 1] = 0;
122 return (foreach_rrd_file (abspath, callback, user_data));
123 } /* }}} int foreach_type */
125 int foreach_plugin (const char *host, /* {{{ */
126 callback_plugin_t callback,
129 char abspath[PATH_MAX + 1];
134 snprintf (abspath, sizeof (abspath), "%s/%s", DATA_DIR, host);
135 abspath[sizeof (abspath) - 1] = 0;
137 return (foreach_dir (abspath, callback, user_data));
138 } /* }}} int foreach_plugin */
140 int foreach_host (callback_host_t callback, /* {{{ */
143 return (foreach_dir (DATA_DIR, callback, user_data));
144 } /* }}} int foreach_host */
146 size_t c_strlcat (char *dst, const char *src, size_t size) /* {{{ */
152 dst_len = strlen (dst);
153 src_len = strlen (src);
154 retval = dst_len + src_len;
156 if ((dst_len + 1) >= size)
163 /* Result will be truncated. */
167 memcpy (dst, src, src_len);
171 } /* }}} size_t c_strlcat */
175 /* vim: set sw=2 sts=2 et fdm=marker : */