/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2006 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
wchar_t ch;
- /* If input ptr is NULL, treat it as empty string. */
- if (utf8str == NULL) {
+ /* If input ptr is NULL or empty... */
+ if (utf8str == NULL || !*utf8str) {
if ( wcstr )
*wcstr = 0;
return 0;
return 4;
if( wchar < 0x4000000 )
return 5;
- if( wchar < 0x80000000 )
+#if SIZEOF_WCHAR_T > 4
+ /* UL is not strictly needed by ANSI C */
+ if( wchar < (wchar_t)0x80000000UL )
+#endif /* SIZEOF_WCHAR_T > 4 */
return 6;
return -1;
}
utf8char[len++] = 0x80 | ( wchar & 0x3f );
}
- } else if( wchar < 0x80000000 ) {
+ } else
+#if SIZEOF_WCHAR_T > 4
+ /* UL is not strictly needed by ANSI C */
+ if( wchar < (wchar_t)0x80000000UL )
+#endif /* SIZEOF_WCHAR_T > 4 */
+ {
if (count >= 6) {
utf8char[len++] = 0xfc | ( wchar >> 30 );
utf8char[len++] = 0x80 | ( (wchar >> 24) & 0x3f );
utf8char[len++] = 0x80 | ( wchar & 0x3f );
}
- } else
+#if SIZEOF_WCHAR_T > 4
+ } else {
len = -1;
+#endif /* SIZEOF_WCHAR_T > 4 */
+ }
return len;
return n;
}
-#endif
+#endif /* SIZEOF_WCHAR_T >= 4 */