From 42d7238925c9651507b4bd6bbae71561fdd7f20b Mon Sep 17 00:00:00 2001 From: Brett Sheffield Date: Mon, 20 Feb 2017 13:37:56 +0000 Subject: [PATCH] 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. --- configure.in | 1 + include/ldif.h | 4 ++++ libraries/libldap/ldif.c | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/configure.in b/configure.in index 1e681bca31..118fffae85 100644 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/include/ldif.h b/include/ldif.h index 8140c914de..5cb410069b 100644 --- a/include/ldif.h +++ b/include/ldif.h @@ -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 * )); diff --git a/libraries/libldap/ldif.c b/libraries/libldap/ldif.c index 1c29619cf3..860a975329 100644 --- a/libraries/libldap/ldif.c +++ b/libraries/libldap/ldif.c @@ -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