aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-08-28 23:10:16 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2015-08-28 23:10:16 +1200
commit4297c45174964231ccd4177362864545adfdda1c (patch)
tree79acc052b88ccde67eca6eaeaef1d2b6d3f354b5
parent7e647a8b34ede473ea6093b53702211ec4ed6d0a (diff)
downloadparamano-4297c45174964231ccd4177362864545adfdda1c.tar.xz
Created wrapper to get integer from formatted filename
-rw-r--r--common.c24
-rw-r--r--common.h4
2 files changed, 28 insertions, 0 deletions
diff --git a/common.c b/common.c
index ca10543..46a3105 100644
--- a/common.c
+++ b/common.c
@@ -18,6 +18,30 @@
#include "paramano.h"
+#include <stdarg.h>
+
+
+int get_int_value_from_filef(const char* format, ...)
+{
+ int value = 0;
+ va_list a;
+ va_start(a, format);
+ value = vget_int_value_from_filef(format, a);
+ va_end(a);
+
+ return value;
+}
+
+int vget_int_value_from_filef(const char* format, va_list args)
+{
+
+ char filename[1024];
+ if (vsnprintf(filename, sizeof(filename), format, args) == sizeof(filename))
+ fprintf(stderr, "WARN: filename buffer too small");
+ return get_int_value_from_file(filename);
+}
+
+
/***********************************************************************
* Return integer value from first line in file
**********************************************************************/
diff --git a/common.h b/common.h
index 6d55d46..056eddd 100644
--- a/common.h
+++ b/common.h
@@ -19,6 +19,10 @@
#ifndef COMMON_H
#define COMMON_H
+#include <stdarg.h>
+
+int get_int_value_from_filef(const char* format, ...);
+int vget_int_value_from_filef(const char* format, va_list args);
int get_int_value_from_file(const char* filename);
int get_int(const char* string);
bool file_has_line(const char *filename, const char *line);