Date: Mon, 1 Jun 2020 21:10:19 +0200 From: Polytropon <freebsd@edvax.de> To: Bertram Scharpf <lists@bertram-scharpf.de> Cc: freebsd-questions@freebsd.org Subject: Re: Funtion getlogin_r()'s protoype Message-ID: <20200601211019.b262da3e.freebsd@edvax.de> In-Reply-To: <20200601172103.d4ellm6wparwm3fb@becker.bs.l> References: <20200601172103.d4ellm6wparwm3fb@becker.bs.l>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 1 Jun 2020 19:21:03 +0200, Bertram Scharpf wrote: > I tried to build the newest Ruby. The compilation breaks > because a function is declared differently in Linux and in > FreeBSD. The Ruby crew doesn't seem to have noticed this > yet. > > int getlogin_r(char *, size_t); /* Linux */ > int getlogin_r(char *, int); /* FreeBSD */ > > The longer I think about it I get convinced this is a > problem of FreeBSD rather than of Ruby. > > What do you think? What solution do you propose? >From what I understand, I agree. The 2nd parameter is the length parameter, which should be of size_t (as many other length and amount parameters already are). Maybe a bug report plus a suggestion for a fix is helpful? >From "man getlogin_r": int getlogin_r(char *name, int len); Implementation in /usr/src/lib/libc/gen/getlogin.c: int getlogin_r(char *logname, int namelen) { char tmpname[MAXLOGNAME]; int len; if (namelen < 1) return (ERANGE); logname[0] = '\0'; if (_getlogin(tmpname, sizeof(tmpname)) < 0) return (errno); len = strlen(tmpname) + 1; if (len > namelen) return (ERANGE); strlcpy(logname, tmpname, len); return (0); } This looks like a perfect place to use size_t instead of int (note the range check). -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200601211019.b262da3e.freebsd>