2 * util-int.c Various functions to replace missing threadsafe ones.
3 * Without the real *_r funcs, things will work, but won't be
6 * Written by Bart Hartgers.
8 * Copyright 1998, A. Hartgers, All rights reserved.
9 * This software is not subject to any license of Eindhoven University of
10 * Technology, since it was written in my spare time.
12 * Redistribution and use in source and binary forms are permitted only
13 * as authorized by the OpenLDAP Public License. A copy of this
14 * license is available at http://www.OpenLDAP.org/license.html or
15 * in file LICENSE in the top-level directory of the distribution.
23 #include <ac/socket.h>
24 #include <ac/string.h>
29 char *ldap_int_strtok( char *str, const char *delim, char **pos )
32 return strtok_r(str, delim, pos);
34 return strtok(str, delim);
38 char *ldap_int_ctime( const time_t *tp, char *buf )
41 return ctime_r(tp,buf);
48 #define BUFMAX (32*1024)
50 static char *safe_realloc( char **buf, int len )
53 tmpbuf = realloc( *buf, len );
60 int ldap_int_gethostbyname_a(
62 struct hostent *resbuf,
64 struct hostent **result,
67 #ifdef HAVE_GETHOSTBYNAME_R
71 if (safe_realloc( buf, buflen)) {
72 for(;buflen<BUFMAX;) {
73 r = gethostbyname_r( name, resbuf, *buf,
74 buflen, result, herrno_ptr );
77 (*herrno_ptr==NETDB_INTERNAL) &&
80 if (safe_realloc( buf, buflen*=2 )) {
89 #else /* gethostbyname() */
90 *result = gethostbyname( name );
96 *herrno_ptr = h_errno;
102 int ldap_int_gethostbyaddr_a(
106 struct hostent *resbuf,
108 struct hostent **result,
111 #ifdef HAVE_GETHOSTBYADDR_R
114 if (safe_realloc( buf, buflen)) {
115 for(;buflen<BUFMAX;) {
116 r = gethostbyaddr_r( addr, len, type,
117 resbuf, *buf, buflen,
118 result, herrno_ptr );
119 #ifdef NETDB_INTERNAL
121 (*herrno_ptr==NETDB_INTERNAL) &&
124 if (safe_realloc( buf, buflen*=2))
132 #else /* gethostbyaddr() */
133 *result = gethostbyaddr( addr, len, type );