On 2/11/2020 6:04 AM, Richard Cochran wrote:
> The name field of the interface is set in different ways by different
> callers. In order to prevent users from open coding the logic that sets
> the name, this patch adds an appropriate method.
>
> Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.kel...@intel.com>
> ---
> interface.c | 5 +++++
> interface.h | 8 +++++++-
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/interface.c b/interface.c
> index 662552d..3811679 100644
> --- a/interface.c
> +++ b/interface.c
> @@ -27,3 +27,8 @@ const char *interface_name(struct interface *iface)
> {
> return iface->name;
> }
> +
> +void interface_set_name(struct interface *iface, const char *name)
> +{
> + strncpy(iface->name, name, MAX_IFNAME_SIZE);
> +}
Good, the name is marked as constant. Side note, for those interface_*
functions that don't modify the interface, does it make sense to mark
them as taking a const interface pointer?
> diff --git a/interface.h b/interface.h
> index 371185d..5f449ae 100644
> --- a/interface.h
> +++ b/interface.h
> @@ -53,5 +53,11 @@ const char *interface_label(struct interface *iface);
> */
> const char *interface_name(struct interface *iface);
>
> -#endif
> +/**
> + * Set the name of a given interface.
> + * @param iface The interface of interest.
> + * @param name The desired name for the interface.
> + */
> +void interface_set_name(struct interface *iface, const char *name);
>
> +#endif
>
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel