Re: [Linuxptp-devel] [PATCH RFC 14/30] interface: Introduce a method to set the name.
On 3/4/2020 9:06 AM, Richard Cochran wrote: > On Tue, Feb 18, 2020 at 01:07:52PM -0800, Jacob Keller wrote: >> >> 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? > > I have heard C++ people insisting on this, but frankly IMHO it doesn't > make any sense. If the implementation of the "class" is completely > hidden, as it should be, then the caller should not care what happens > offstage. That is none of the caller's business. > > Thanks, > Richard > Sure. Thanks, Jake ___ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
Re: [Linuxptp-devel] [PATCH RFC 14/30] interface: Introduce a method to set the name.
On Tue, Feb 18, 2020 at 01:07:52PM -0800, Jacob Keller wrote: > > 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? I have heard C++ people insisting on this, but frankly IMHO it doesn't make any sense. If the implementation of the "class" is completely hidden, as it should be, then the caller should not care what happens offstage. That is none of the caller's business. Thanks, Richard ___ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
Re: [Linuxptp-devel] [PATCH RFC 14/30] interface: Introduce a method to set the name.
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 Reviewed-by: Jacob Keller > --- > 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