Converts a numeric LDAP error code into a character string.
#include <ldap.h>
char *ldap_err2string (
int err);
(IN) Specifies an LDAP error code returned by an LDAP function.
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.