Re: [PHP4BETA] *_r -functions
| From: | Sascha Schumann | Date: | Sun, 28 Nov 1999 21:08:46 +0000 |
| Subject: | Re: [PHP4BETA] *_r -functions | ||
| References: | 1 2 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-7006@lists.php.net to get a copy of this message | ||
On Sun, Nov 28, 1999 at 09:14:16PM +0200, Jouni Ahto wrote:
>
>
> On Sun, 28 Nov 1999, Sascha Schumann wrote:
>
> > Yes, the getxxbyzz functions are not so easy to cover. For
> > gethostbyname_r, we should support the three APIs (Solaris,
> > glibc2, HP-UX) by providing a wrapper function, so that our
> > functions can use a php_gethostbyname_r with known semantics.
> >
> > The fallback function you created does not check for error
> > conditions (gethostbyname() may return NULL), nor does it
> > respect the lowest common denominator which is:
> >
> > int gethostbyname_r(const char *host, struct hostent *hostbuf,
> > char *tmphostbuf, size_t tmphostbuflen,
> > int *hosterr);
>
> Very good points. Have to think it over again. And maybe just leave it, I
> don't have enough documentation about the different APIs. Oh, and I just
> left the error checking upper in the function chain. if (result || !hp ||
> !hp->h_addr_list) works,
A result of 0 means 'success', no matter what other variables
say.
> although I forgot to free a buffer. However, it
> doesn't disqualify your points...
Note that the function you posted had another defect. The
statement
memcpy(hostp, &tmp, sizeof(struct hostent));
cannot work, because you copy a pointer to struct hostent,
not the structure itself. A more efficient way would be to
say
*hostp = tmp;
Anyway, I'm working on an improved version right now.
--
Regards,
Sascha Schumann
Consultant