common: provide parsing multiple data types
[platform/core/system/resourced.git] / src / common / config-parser.c
index 5b851eb..e1b4aed 100644 (file)
@@ -385,26 +385,30 @@ int config_parse_bool(const char *filename,
        return 0;
 }
 
+#define DEFINE_PARSER(type, vartype, conv_func)          \
+       int config_parse_##type(                                        \
+                               const char *filename,                   \
+                               unsigned line,                          \
+                               const char *section,                    \
+                               const char *lvalue,                     \
+                               int ltype,                              \
+                               const char *rvalue,                     \
+                               void *data) {                           \
+                                                                                                               \
+               vartype *i = data;                                      \
+                                                                       \
+               assert(filename);                                       \
+               assert(lvalue);                                         \
+               assert(rvalue);                                         \
+               assert(data);                                           \
+                                                                       \
+               *i = conv_func(rvalue);                          \
+               return 0;                                               \
+               }
 
-int config_parse_int(const char *filename,
-                    unsigned line,
-                    const char *section,
-                    const char *lvalue,
-                    int ltype,
-                    const char *rvalue,
-                    void *data)
-{
-       int *i = data;
-
-       assert(filename);
-       assert(lvalue);
-       assert(rvalue);
-       assert(data);
-
-       *i = atoi(rvalue);
-
-       return 0;
-}
+DEFINE_PARSER(int, int, atoi)
+DEFINE_PARSER(float, float, atof)
+DEFINE_PARSER(long, long, atol)
 
 int config_parse_string(const char *filename,
                        unsigned line,