/* * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ /* * util-int.c Various functions to replace missing threadsafe ones. * Without the real *_r funcs, things will work, but won't be * threadsafe. * * Written by Bart Hartgers. * * Copyright 1998, A. Hartgers, All rights reserved. * This software is not subject to any license of Eindhoven University of * Technology, since it was written in my spare time. * * Redistribution and use in source and binary forms are permitted only * as authorized by the OpenLDAP Public License. A copy of this * license is available at http://www.OpenLDAP.org/license.html or * in file LICENSE in the top-level directory of the distribution. */ #include "portable.h" #include #include #include #include #include #include "ldap-int.h" char *ldap_int_strtok( char *str, const char *delim, char **pos ) { #ifdef HAVE_STRTOK_R return strtok_r(str, delim, pos); #else return strtok(str, delim); #endif } char *ldap_int_ctime( const time_t *tp, char *buf ) { #if defined( HAVE_CTIME_R ) && defined( CTIME_R_NARGS ) # if (CTIME_R_NARGS > 3) || (CTIME_R_NARGS < 2) choke me! nargs should have 2 or 3 # elif CTIME_R_NARGS > 2 return ctime_r(tp,buf,26); # else return ctime_r(tp,buf); # endif #else return ctime(tp); #endif } #define BUFSTART 1024 #define BUFMAX (32*1024) static char *safe_realloc( char **buf, int len ) { char *tmpbuf; tmpbuf = realloc( *buf, len ); if (tmpbuf) { *buf=tmpbuf; } return tmpbuf; } int ldap_int_gethostbyname_a( const char *name, struct hostent *resbuf, char **buf, struct hostent **result, int *herrno_ptr ) { #ifdef HAVE_GETHOSTBYNAME_R int r; int buflen=BUFSTART; if (safe_realloc( buf, buflen)) { for(;buflen