]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
agent: simpler code with #ifdef
authorVincent Bernat <vincent@bernat.ch>
Mon, 13 Apr 2020 17:59:24 +0000 (19:59 +0200)
committerVincent Bernat <vincent@bernat.ch>
Mon, 13 Apr 2020 17:59:24 +0000 (19:59 +0200)
The use #ifdef to avoid some line duplications makes the code harder
to read. Prefer duplicating the lines when needed.

src/daemon/agent_priv.c

index 59054ccca797f991d06a5bbc9ebf7905e732dcae..2f9d8da2c3870d529bb8f4f79f6ab967b47b07a7 100644 (file)
@@ -208,23 +208,25 @@ agent_priv_unix_transport(const char *string, int len, int local)
        return t;
 }
 
+#if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW
 netsnmp_transport *
-#if !HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW
-agent_priv_unix_create_tstring(const char *string, int local)
-#else
-agent_priv_unix_create_tstring(const char *string, int local, const char *default_target)
-#endif
+agent_priv_unix_create_tstring_new(const char *string, int local, const char *default_target)
 {
-#if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW
        if ((!string || *string == '\0') && default_target &&
            *default_target != '\0') {
                string = default_target;
        }
-#endif
-       if (!string)
-               return NULL;
+       if (!string) return NULL;
+       return agent_priv_unix_transport(string, strlen(string), local);
+}
+#else
+netsnmp_transport *
+agent_priv_unix_create_tstring(const char *string, int local)
+{
+       if (!string) return NULL;
        return agent_priv_unix_transport(string, strlen(string), local);
 }
+#endif
 
 static netsnmp_transport *
 agent_priv_unix_create_ostring(F_FROM_OSTRING_SIGNATURE)
@@ -239,10 +241,10 @@ agent_priv_register_domain()
        unixDomain.name_length = sizeof(netsnmp_unix) / sizeof(oid);
        unixDomain.prefix = (const char**)calloc(2, sizeof(char *));
        unixDomain.prefix[0] = "unix";
-#if !HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW
-       unixDomain.f_create_from_tstring = agent_priv_unix_create_tstring;
+#if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW
+       unixDomain.f_create_from_tstring_new = agent_priv_unix_create_tstring_new;
 #else
-       unixDomain.f_create_from_tstring_new = agent_priv_unix_create_tstring;
+       unixDomain.f_create_from_tstring = agent_priv_unix_create_tstring;
 #endif
        unixDomain.f_create_from_ostring = agent_priv_unix_create_ostring;
        netsnmp_tdomain_register(&unixDomain);