1
/* Copyright (C) 2002, 2004 MySQL AB
3
This library is free software; you can redistribute it and/or
4
modify it under the terms of the GNU Library General Public
5
License as published by the Free Software Foundation; version 2
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public
14
License along with this library; if not, write to the Free
15
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18
/* Thread safe version of gethostbyname_r() */
20
#include "mysys_priv.h"
26
/* This file is not needed if my_gethostbyname_r is a macro */
27
#if !defined(my_gethostbyname_r)
30
Emulate SOLARIS style calls, not because it's better, but just to make the
31
usage of getbostbyname_r simpler.
34
#if defined(HAVE_GETHOSTBYNAME_R)
36
#if defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
38
struct hostent *my_gethostbyname_r(const char *name,
39
struct hostent *result, char *buffer,
40
int buflen, int *h_errnop)
43
DBUG_ASSERT((size_t) buflen >= sizeof(*result));
44
if (gethostbyname_r(name,result, buffer, (size_t) buflen, &hp, h_errnop))
49
#elif defined(HAVE_GETHOSTBYNAME_R_RETURN_INT)
51
struct hostent *my_gethostbyname_r(const char *name,
52
struct hostent *result, char *buffer,
53
int buflen, int *h_errnop)
55
if (gethostbyname_r(name,result,(struct hostent_data *) buffer) == -1)
65
/* gethostbyname_r with similar interface as gethostbyname() */
67
struct hostent *my_gethostbyname_r(const char *name,
68
struct hostent *result, char *buffer,
69
int buflen, int *h_errnop)
72
DBUG_ASSERT(buflen >= sizeof(struct hostent_data));
73
hp= gethostbyname_r(name,result,(struct hostent_data *) buffer);
77
#endif /* GLIBC2_STYLE_GETHOSTBYNAME_R */
79
#else /* !HAVE_GETHOSTBYNAME_R */
82
extern pthread_mutex_t LOCK_gethostbyname_r;
86
No gethostbyname_r() function exists.
87
In this case we have to keep a mutex over the call to ensure that no
88
other thread is going to reuse the internal memory.
90
The user is responsible to call my_gethostbyname_r_free() when he
91
is finished with the structure.
94
struct hostent *my_gethostbyname_r(const char *name,
95
struct hostent *result, char *buffer,
96
int buflen, int *h_errnop)
99
pthread_mutex_lock(&LOCK_gethostbyname_r);
100
hp= gethostbyname(name);
105
void my_gethostbyname_r_free()
107
pthread_mutex_unlock(&LOCK_gethostbyname_r);
110
#endif /* !HAVE_GETHOSTBYNAME_R */
111
#endif /* !my_gethostbyname_r */