]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/utf-8-conv.c
Happy New Year!
[openldap] / libraries / libldap / utf-8-conv.c
index 80503155882f9235025e3cf2bdd4fdb227c0d212..df477822f7f3dc1a361f3cb4fa17b6a8e933c48e 100644 (file)
@@ -1,12 +1,18 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 2000 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2005 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
-
-/* $Novell: /ldap/src/cldap/libraries/libldap/utfconv.c,v 1.3 2000/12/11 19:35:37 dsteck Exp $ */
-/******************************************************************************
- * Copyright (C) 1999, 2000 Novell, Inc. All Rights Reserved.
+/* Portions Copyright (C) 1999, 2000 Novell, Inc. All Rights Reserved.
  * 
  * THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
  * TREATIES. USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT
  * OF THIS WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP
  * PUBLIC LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT
  * THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY. 
- ******************************************************************************/
+ *---
+ * Note: A verbatim copy of version 2.0.1 of the OpenLDAP Public License 
+ * can be found in the file "build/LICENSE-2.0.1" in this distribution
+ * of OpenLDAP Software.
+ */
 
 /*
  * UTF-8 Conversion Routines
@@ -30,6 +40,9 @@
 
 #include "portable.h"
 
+#if SIZEOF_WCHAR_T >= 4
+/* These routines assume ( sizeof(wchar_t) >= 4 ) */
+
 #include <stdio.h>
 #include <ac/stdlib.h>         /* For wctomb, wcstombs, mbtowc, mbstowcs */
 #include <ac/string.h>
@@ -70,7 +83,7 @@ Note:  This code does not prevent UTF-8 sequences which are longer than
           necessary from being decoded.
 */
 
-/*------------------------------------------------------------------------------ 
+/*----------------------------------------------------------------------------- 
    Convert a UTF-8 character to a wide char. 
    Return the length of the UTF-8 input character in bytes.
 */
@@ -85,9 +98,9 @@ ldap_x_utf8_to_wc ( wchar_t *wchar, const char *utf8char )
                utf8char = "";
 
        /* Get UTF-8 sequence length from 1st byte */
-       utflen = LDAP_UTF8_CHARLEN(utf8char);
+       utflen = LDAP_UTF8_CHARLEN2(utf8char, utflen);
        
-       if( utflen==0 || utflen > LDAP_MAX_UTF8_LEN )
+       if( utflen==0 || utflen > (int)LDAP_MAX_UTF8_LEN )
                return -1;                                                                      /* Invalid input */
 
        /* First byte minus length tag */
@@ -130,9 +143,9 @@ ldap_x_utf8s_to_wcs ( wchar_t *wcstr, const char *utf8str, size_t count )
        while ( *utf8str && (wcstr==NULL || wclen<count) )
        {
                /* Get UTF-8 sequence length from 1st byte */
-               utflen = LDAP_UTF8_CHARLEN(utf8str);
+               utflen = LDAP_UTF8_CHARLEN2(utf8str, utflen);
                
-               if( utflen==0 || utflen > LDAP_MAX_UTF8_LEN )
+               if( utflen==0 || utflen > (int)LDAP_MAX_UTF8_LEN )
                        return -1;                                                                      /* Invalid input */
 
                /* First byte minus length tag */
@@ -163,7 +176,7 @@ ldap_x_utf8s_to_wcs ( wchar_t *wcstr, const char *utf8str, size_t count )
 }
 
 
-/*------------------------------------------------------------------------------ 
+/*----------------------------------------------------------------------------- 
    Convert one wide char to a UTF-8 character.
    Return the length of the converted UTF-8 character in bytes.
    No more than 'count' bytes will be written to the output buffer.
@@ -462,3 +475,5 @@ ldap_x_mbs_to_utf8s ( char *utf8str, const char *mbstr, size_t count,
 
        return n;       
 }
+
+#endif