This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 4/5] linux ttyname and ttyname_r: Make the TTY equivalence tests consistent [BZ #22145]


On Thu, Oct 12, 2017 at 08:18:50AM -0400, Luke Shumaker wrote:
> On Thu, 12 Oct 2017 07:16:15 -0400,
> Christian Brauner wrote:
> > On Wed, Oct 11, 2017 at 11:53:20PM -0400, Luke Shumaker wrote:
> > > +static inline int
> > > +is_mytty(struct stat64 *mytty, struct stat64 *maybe)
> > > +{
> > > +  return 1
> > > +#ifdef _STATBUF_ST_RDEV
> > > +    && S_ISCHR (maybe->st_mode)
> > > +    && maybe->st_rdev == mytty->st_rdev
> > > +#endif
> > > +    && maybe->st_ino == mytty->st_ino
> > > +    && maybe->st_dev == mytty->st_dev;
> > > +}
> >
> > I find that hard to read. At first I thought this would unconditionally return
> > 1. I'd rather prefer something like (In the appropriate GNU coding style
> > eventually of course.):
> >
> > static inline bool is_mytty(struct stat64 *mytty, struct stat64 *maybe)
> > {
> > if (maybe->st_ino == mytty->st_ino && maybe->st_dev == mytty->st_dev
> > #ifdef _STATBUF_ST_RDEV
> >    && S_ISCHR(maybe->st_mode) && maybe->st_rdev == mytty->st_rdev
> > #endif
> >    )
> > return true;
> >
> > return false;
> > }
> >
> > But others might be fine with it.
>
> I'm fine either way.  If the consensus is reformat it, I'll reformat
> it.
>
> >                                   But I think having it return a bool here is
> > perfectly fine since there's no other possible outcome than true or false.
>
> So why doesn't is_pty return a bool?  I was mimicing the style already
> in the file.

Likely because it was overseen as well. I think it makes more sense to have them
return proper bools when they can't return anything else. Seems fine to me since
they're used all over the codebase as well.

>
> --
> Happy hacking,
> ~ Luke Shumaker


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]