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 )
44 #if defined( HAVE_CTIME_R ) && defined( CTIME_R_NARGS )
45 # if (CTIME_R_NARGS > 3) || (CTIME_R_NARGS < 2)
46 choke me! nargs should have 2 or 3
47 # elif CTIME_R_NARGS > 2
48 return ctime_r(tp,buf,26);
50 return ctime_r(tp,buf);
58 #define BUFMAX (32*1024)
60 static char *safe_realloc( char **buf, int len )
63 tmpbuf = realloc( *buf, len );
70 int ldap_int_gethostbyname_a(
72 struct hostent *resbuf,
74 struct hostent **result,
77 #ifdef HAVE_GETHOSTBYNAME_R
81 if (safe_realloc( buf, buflen)) {
82 for(;buflen<BUFMAX;) {
83 r = gethostbyname_r( name, resbuf, *buf,
84 buflen, result, herrno_ptr );
87 (*herrno_ptr==NETDB_INTERNAL) &&
90 if (safe_realloc( buf, buflen*=2 )) {
99 #else /* gethostbyname() */
100 *result = gethostbyname( name );
106 *herrno_ptr = h_errno;
112 int ldap_int_gethostbyaddr_a(
116 struct hostent *resbuf,
118 struct hostent **result,
121 #ifdef HAVE_GETHOSTBYADDR_R
124 if (safe_realloc( buf, buflen)) {
125 for(;buflen<BUFMAX;) {
126 r = gethostbyaddr_r( addr, len, type,
127 resbuf, *buf, buflen,
128 result, herrno_ptr );
129 #ifdef NETDB_INTERNAL
131 (*herrno_ptr==NETDB_INTERNAL) &&
134 if (safe_realloc( buf, buflen*=2))
142 #else /* gethostbyaddr() */
143 *result = gethostbyaddr( addr, len, type );