[PATCH 2/6] lib: fwts_log: add fwts_log_get_filenames()
Colin King
colin.king at canonical.com
Wed Jun 20 11:30:25 UTC 2012
From: Colin Ian King <colin.king at canonical.com>
Add function to return back a string of all the log filenames being
used. For multi-log logging, this returns multiple filenames
separated by a space, e.g. "results.log results.html results.json"
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/include/fwts_log.h | 1 +
src/lib/src/fwts_log.c | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/src/lib/include/fwts_log.h b/src/lib/include/fwts_log.h
index 513bf88..22ec70e 100644
--- a/src/lib/include/fwts_log.h
+++ b/src/lib/include/fwts_log.h
@@ -144,6 +144,7 @@ int fwts_log_line_number(fwts_log *log);
void fwts_log_set_line_width(const int width);
void fwts_log_section_begin(fwts_log *log, const char *name);
void fwts_log_section_end(fwts_log *log);
+char *fwts_log_get_filenames(const char *filename, fwts_log_type type);
fwts_log_filename_type fwts_log_get_filename_type(const char *name);
static inline int fwts_log_type_count(fwts_log_type type)
diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
index 3ab7930..d946c31 100644
--- a/src/lib/src/fwts_log.c
+++ b/src/lib/src/fwts_log.c
@@ -562,6 +562,46 @@ fwts_log_filename_type fwts_log_get_filename_type(const char *filename)
}
/*
+ * fwts_log_filenames()
+ * return string of all the log filenames that will be used
+ */
+char *fwts_log_get_filenames(const char *filename, fwts_log_type type)
+{
+ unsigned int i;
+ char *filenames = NULL;
+ char *tmp;
+ size_t len = 0;
+
+ for (i=0; i<32; i++) {
+ fwts_log_type mask = 1 << i;
+ if (type & mask) {
+ if ((tmp = fwts_log_filename(filename, mask)) == NULL)
+ return NULL;
+
+ if (filenames) {
+ len += strlen(tmp) + 2;
+ if ((filenames = realloc(filenames, len)) == NULL) {
+ free(tmp);
+ return NULL;
+ }
+ strcat(filenames, " ");
+ strcat(filenames, tmp);
+ } else {
+ len = strlen(tmp) + 1;
+ if ((filenames = malloc(len)) == NULL) {
+ free(tmp);
+ return NULL;
+ }
+ strcpy(filenames, tmp);
+ }
+ free(tmp);
+ }
+ }
+
+ return filenames;
+}
+
+/*
* fwts_log_open()
* open a log file. if name is stderr or stdout, then attach log to these
* streams.
--
1.7.10.4
More information about the fwts-devel
mailing list