ITS#8603 Add ldif_open_mem()

ldif_open_mem() is the fmemopen(3) equivalent of ldif_open() which opens
an ldif steam from memory, rather than from a file.
This commit is contained in:
Brett Sheffield 2017-02-20 13:37:56 +00:00 committed by Ondřej Kuzník
parent 58c978825c
commit 42d7238925
3 changed files with 27 additions and 0 deletions

View File

@ -863,6 +863,7 @@ dnl ----------------------------------------------------------------
dnl Checks for libraries
AC_CHECK_FUNCS( sigaction sigset )
AC_CHECK_FUNCS( fmemopen )
dnl HP-UX requires -lV3
dnl this is not needed on newer versions of HP-UX

View File

@ -99,6 +99,10 @@ typedef struct LDIFFP {
LDAP_LDIF_F( LDIFFP * )
ldif_open LDAP_P(( LDAP_CONST char *file, LDAP_CONST char *mode ));
/* ldif_open equivalent that opens ldif stream in memory rather than from file */
LDAP_LDIF_F( LDIFFP * )
ldif_open_mem LDAP_P(( char *ldif, size_t size, LDAP_CONST char *mode ));
LDAP_LDIF_F( void )
ldif_close LDAP_P(( LDIFFP * ));

View File

@ -740,6 +740,28 @@ ldif_open(
return lfp;
}
LDIFFP *
ldif_open_mem(
char *ldif,
size_t size,
LDAP_CONST char *mode
)
{
#ifdef HAVE_FMEMOPEN
FILE *fp = fmemopen( ldif, size, mode );
LDIFFP *lfp = NULL;
if ( fp ) {
lfp = ber_memalloc( sizeof( LDIFFP ));
lfp->fp = fp;
lfp->prev = NULL;
}
return lfp;
#else /* !HAVE_FMEMOPEN */
return NULL;
#endif /* !HAVE_FMEMOPEN */
}
void
ldif_close(
LDIFFP *lfp