ldap_err2string

Converts a numeric LDAP error code into a character string.

LDAP Version:v2 or higher
Library:*ldapsdk.*
NDS Version:7.xx or higher
Platform:NLM, Windows (NT, 95, 98, 2000, XP, Vista 32-bit and 64-bit ), Linux (32-bit and 64-bit), Solaris, AIX, and HP-UX

Syntax

  #include <ldap.h>
  
  char *ldap_err2string (
     int   err);
  
  

Parameters

err

(IN) Specifies an LDAP error code returned by an LDAP function.

Return Values

>0

Pointer to a zero-terminated character string.

Remarks

The ldap_err2string function converts LDAP error codes returned by the following functions:

  • ldap_parse_result

  • ldap_parse_sasl_bind_result

  • ldap_parse_extended_result

  • synchronous LDAP operation functions

The LDAP error code is converted to a zero-terminated character string which describes the error.

The return value points to a string contained in static data. Be aware of the following:

  • It should be used or copied before another call to ldap_err2string is made.

  • The pointer should not be used to modify the original string.

  • The string should not be freed by the application program.

  • The returned string is UTF-8 encoded if the API succeeds.

If the API succeeds, errno is set to 0. Else, the returned string will be in local codepage.

If the retuned string is UTF-8 encoded then it has to be converted into the local codepage before you can print it. Otherwise, the returned pointer can be used directly in a printf statement as displayed in the following example:

  err=ldap_search(...);if (err)   {    char *s;    s= ldap_err2string(err);    if (errno==0) // returned string is utf8 encoded        {     //convert to local codepage and print it        }     else // returned string is not utf8 encoded, it is in local codepage          printf("Search error: %s\n",s);    }
  

For information on converting utf8 to local code page, refer to the utf8bind.c sample code.

NOTE:If the locale is a single byte charset (for example, English), you do not need to convert from UTF-8 to local charset, since UTF-8 charset is the same as the local charset for a single byte charset.

See Also

ldap_parse_result, ldap_parse_extended_result, ldap_parse_sasl_bind_result