]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
condition: introduce generic function type for condition_to_string()-like functions
authorLennart Poettering <lennart@poettering.net>
Thu, 14 May 2020 16:40:16 +0000 (18:40 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 15 May 2020 13:50:09 +0000 (15:50 +0200)
Let's add a typedef for a function type we use at multiple places.

src/shared/condition.c
src/shared/condition.h

index 2dbc14938acf08d9f293da730ac05621feb3ae06..fef37057db9dadbd4bdd77e041e61e2759ce1ce2 100644 (file)
@@ -779,7 +779,12 @@ int condition_test(Condition *c) {
         return b;
 }
 
-bool condition_test_list(Condition *first, const char *(*to_string)(ConditionType t), condition_test_logger_t logger, void *userdata) {
+bool condition_test_list(
+                Condition *first,
+                condition_to_string_t to_string,
+                condition_test_logger_t logger,
+                void *userdata) {
+
         Condition *c;
         int triggered = -1;
 
@@ -828,9 +833,10 @@ bool condition_test_list(Condition *first, const char *(*to_string)(ConditionTyp
         return triggered != 0;
 }
 
-void condition_dump(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t)) {
+void condition_dump(Condition *c, FILE *f, const char *prefix, condition_to_string_t to_string) {
         assert(c);
         assert(f);
+        assert(to_string);
 
         prefix = strempty(prefix);
 
@@ -844,7 +850,7 @@ void condition_dump(Condition *c, FILE *f, const char *prefix, const char *(*to_
                 condition_result_to_string(c->result));
 }
 
-void condition_dump_list(Condition *first, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t)) {
+void condition_dump_list(Condition *first, FILE *f, const char *prefix, condition_to_string_t to_string) {
         Condition *c;
 
         LIST_FOREACH(conditions, c, first)
index 6064ccdaed56eaef2691c7ee12865a8885ffd22b..fa00f6ea983674721cabb80884c6500eac892b27 100644 (file)
@@ -74,11 +74,13 @@ static inline Condition* condition_free_list(Condition *first) {
 }
 
 int condition_test(Condition *c);
+
 typedef int (*condition_test_logger_t)(void *userdata, int level, int error, const char *file, int line, const char *func, const char *format, ...) _printf_(7, 8);
-bool condition_test_list(Condition *first, const char *(*to_string)(ConditionType t), condition_test_logger_t logger, void *userdata);
+typedef const char* (*condition_to_string_t)(ConditionType t);
+bool condition_test_list(Condition *first, condition_to_string_t, condition_test_logger_t logger, void *userdata);
 
-void condition_dump(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t));
-void condition_dump_list(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t));
+void condition_dump(Condition *c, FILE *f, const char *prefix, condition_to_string_t to_string);
+void condition_dump_list(Condition *c, FILE *f, const char *prefix, condition_to_string_t to_string);
 
 const char* condition_type_to_string(ConditionType t) _const_;
 ConditionType condition_type_from_string(const char *s) _pure_;