2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * util-int.c Various functions to replace missing threadsafe ones.
7 * Without the real *_r funcs, things will work, but won't be
10 * Written by Bart Hartgers.
12 * Copyright 1998, A. Hartgers, All rights reserved.
13 * This software is not subject to any license of Eindhoven University of
14 * Technology, since it was written in my spare time.
16 * Redistribution and use in source and binary forms are permitted only
17 * as authorized by the OpenLDAP Public License. A copy of this
18 * license is available at http://www.OpenLDAP.org/license.html or
19 * in file LICENSE in the top-level directory of the distribution.
27 #include <ac/socket.h>
28 #include <ac/string.h>
33 char *ldap_int_strtok( char *str, const char *delim, char **pos )
36 return strtok_r(str, delim, pos);
38 return strtok(str, delim);
42 char *ldap_int_ctime( const time_t *tp, char *buf )
45 return ctime_r(tp,buf);
52 #define BUFMAX (32*1024)
54 static char *safe_realloc( char **buf, int len )
57 tmpbuf = realloc( *buf, len );
64 int ldap_int_gethostbyname_a(
66 struct hostent *resbuf,
68 struct hostent **result,
71 #ifdef HAVE_GETHOSTBYNAME_R
75 if (safe_realloc( buf, buflen)) {
76 for(;buflen<BUFMAX;) {
77 r = gethostbyname_r( name, resbuf, *buf,
78 buflen, result, herrno_ptr );
81 (*herrno_ptr==NETDB_INTERNAL) &&
84 if (safe_realloc( buf, buflen*=2 )) {
93 #else /* gethostbyname() */
94 *result = gethostbyname( name );
100 *herrno_ptr = h_errno;
106 int ldap_int_gethostbyaddr_a(
110 struct hostent *resbuf,
112 struct hostent **result,
115 #ifdef HAVE_GETHOSTBYADDR_R
118 if (safe_realloc( buf, buflen)) {
119 for(;buflen<BUFMAX;) {
120 r = gethostbyaddr_r( addr, len, type,
121 resbuf, *buf, buflen,
122 result, herrno_ptr );
123 #ifdef NETDB_INTERNAL
125 (*herrno_ptr==NETDB_INTERNAL) &&
128 if (safe_realloc( buf, buflen*=2))
136 #else /* gethostbyaddr() */
137 *result = gethostbyaddr( addr, len, type );