+ status = rrd_lastupdate_r (argv[optind],
+ &last_update, &ds_count, &ds_names, &last_ds);
+ if (status != 0)
+ return (status);
+
+ for (i = 0; i < ds_count; i++)
+ printf(" %s", ds_names[i]);
+ printf ("\n\n");
+
+ printf ("%10lu:", last_update);
+ for (i = 0; i < ds_count; i++) {
+ printf(" %s", last_ds[i]);
+ free(last_ds[i]);
+ free(ds_names[i]);
+ }
+ printf("\n");
+
+ free(last_ds);
+ free(ds_names);
+
+ return (0);
+} /* int rrd_lastupdate */
+
+int rrd_lastupdate_r(const char *filename,
+ time_t *ret_last_update,
+ unsigned long *ret_ds_count,
+ char ***ret_ds_names,
+ char ***ret_last_ds)
+{
+ unsigned long i = 0;
+ rrd_t rrd;
+ rrd_file_t *rrd_file;
+
+ rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
+ if (rrd_file == NULL) {
+ rrd_free(&rrd);
+ return (-1);
+ }
+
+ *ret_last_update = rrd.live_head->last_up;
+ *ret_ds_count = rrd.stat_head->ds_cnt;
+ *ret_ds_names = (char **) malloc (rrd.stat_head->ds_cnt * sizeof(char *));
+ if (*ret_ds_names == NULL) {
+ rrd_set_error ("malloc fetch ret_ds_names array");
+ rrd_close (rrd_file);
+ rrd_free (&rrd);
+ return (-1);
+ }
+ memset (*ret_ds_names, 0, rrd.stat_head->ds_cnt * sizeof(char *));
+
+ *ret_last_ds = (char **) malloc (rrd.stat_head->ds_cnt * sizeof(char *));
+ if (*ret_last_ds == NULL) {
+ rrd_set_error ("malloc fetch ret_last_ds array");
+ free (*ret_ds_names);
+ *ret_ds_names = NULL;
+ rrd_close (rrd_file);
+ rrd_free (&rrd);
+ return (-1);
+ }
+ memset (*ret_last_ds, 0, rrd.stat_head->ds_cnt * sizeof(char *));
+
+ for (i = 0; i < rrd.stat_head->ds_cnt; i++) {
+ (*ret_ds_names)[i] = sprintf_alloc("%s", rrd.ds_def[i].ds_nam);
+ (*ret_last_ds)[i] = sprintf_alloc("%s", rrd.pdp_prep[i].last_ds);
+
+ if (((*ret_ds_names)[i] == NULL) || ((*ret_last_ds)[i] == NULL))
+ break;
+ }