Funtion getlogin_r()'s protoype
Polytropon
freebsd at edvax.de
Mon Jun 1 19:10:22 UTC 2020
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, ...
More information about the freebsd-questions
mailing list