libnm: relax asserting argument for nm_utils_hwaddr_len()

nm_utils_hwaddr_len() isn't very useful. It's documented to
only accept two possible input values (ARPHRD_ETHER and ARPHRD_INFINIBAND)
for which the respective return values are well known.

In particular, asserting that the input value is one of the two values
means it becomes harder to extend the function (and make it more useful).
Because, then the user would need to call:

     #if NM_VERSION > NM_VERSION_1_XX
     len = nm_utils_hwaddr_len (ARPHDR_FOO);
     #else
     len = 0
     #endif

and then it would introduce an unnecessary run time dependency on
NM_VERSION_1_XX.

Instead, just document to return 0 if the value is not supported.
This commit is contained in:
Thomas Haller 2020-09-23 12:24:56 +02:00
parent 2d360d8293
commit 2fdc713e92
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -4001,20 +4001,22 @@ nm_utils_wifi_strength_bars (guint8 strength)
*
* Returns the length in octets of a hardware address of type @type.
*
* It is an error to call this function with any value other than
* Before 1.28, it was an error to call this function with any value other than
* <literal>ARPHRD_ETHER</literal> or <literal>ARPHRD_INFINIBAND</literal>.
*
* Return value: the length.
* Return value: the length or zero if the type is unrecognized.
*/
gsize
nm_utils_hwaddr_len (int type)
{
if (type == ARPHRD_ETHER)
switch (type) {
case ARPHRD_ETHER:
return ETH_ALEN;
else if (type == ARPHRD_INFINIBAND)
case ARPHRD_INFINIBAND:
return INFINIBAND_ALEN;
g_return_val_if_reached (0);
default:
return 0;
}
}
/**