12 static int foreach_rrd_file (const char *dir, /* {{{ */
13 int (*callback) (const char *, void *),
27 while ((entry = readdir (dh)) != NULL)
30 char abspath[PATH_MAX + 1];
33 if (entry->d_name[0] == '.')
36 d_name_len = strlen (entry->d_name);
40 if (strcasecmp (".rrd", entry->d_name + (d_name_len - 4)) != 0)
43 snprintf (abspath, sizeof (abspath), "%s/%s", dir, entry->d_name);
44 abspath[sizeof (abspath) - 1] = 0;
46 memset (&statbuf, 0, sizeof (statbuf));
48 status = stat (abspath, &statbuf);
52 if (!S_ISREG (statbuf.st_mode))
55 entry->d_name[d_name_len - 4] = 0;
57 status = (*callback) (entry->d_name, user_data);
60 } /* while (readdir) */
64 } /* }}} int foreach_rrd_file */
66 static int foreach_dir (const char *dir, /* {{{ */
67 int (*callback) (const char *, void *),
81 while ((entry = readdir (dh)) != NULL)
84 char abspath[PATH_MAX + 1];
86 if (entry->d_name[0] == '.')
89 snprintf (abspath, sizeof (abspath), "%s/%s", dir, entry->d_name);
90 abspath[sizeof (abspath) - 1] = 0;
92 memset (&statbuf, 0, sizeof (statbuf));
94 status = stat (abspath, &statbuf);
98 if (!S_ISDIR (statbuf.st_mode))
101 status = (*callback) (entry->d_name, user_data);
104 } /* while (readdir) */
108 } /* }}} int foreach_dir */
110 int foreach_type (const char *host, const char *plugin, /* {{{ */
111 callback_type_t callback, void *user_data)
113 char abspath[PATH_MAX + 1];
115 if ((host == NULL) || (plugin == NULL))
118 snprintf (abspath, sizeof (abspath), "%s/%s/%s", DATA_DIR, host, plugin);
119 abspath[sizeof (abspath) - 1] = 0;
121 return (foreach_rrd_file (abspath, callback, user_data));
122 } /* }}} int foreach_type */
124 int foreach_plugin (const char *host, /* {{{ */
125 callback_plugin_t callback,
128 char abspath[PATH_MAX + 1];
133 snprintf (abspath, sizeof (abspath), "%s/%s", DATA_DIR, host);
134 abspath[sizeof (abspath) - 1] = 0;
136 return (foreach_dir (abspath, callback, user_data));
137 } /* }}} int foreach_plugin */
139 int foreach_host (callback_host_t callback, /* {{{ */
142 return (foreach_dir (DATA_DIR, callback, user_data));
143 } /* }}} int foreach_host */
145 /* vim: set sw=2 sts=2 et fdm=marker : */