changeset 11300:8ac7c72b439b

Adjust u*_normcmp, u*_normcoll API.
author Bruno Haible <bruno@clisp.org>
date Sun, 08 Mar 2009 03:18:26 +0100
parents 16dbbe72b817
children fb09a686a3f1
files ChangeLog lib/uninorm.h lib/uninorm/u-normcmp.h lib/uninorm/u-normcoll.h
diffstat 4 files changed, 27 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-03-07  Bruno Haible  <bruno@clisp.org>
+
+	Adjust u*_normcmp, u*_normcoll API.
+	* lib/uninorm.h (u8_normcmp, u16_normcmp, u32_normcmp, u8_normcoll,
+	u16_normcoll, u32_normcoll): Change failure conventions.
+	* lib/uninorm/u-normcmp.h (FUNC): Upon failure, store the error code in
+	errno and return -1.
+	* lib/uninorm/u-normcoll.h (FUNC): Likewise.
+
 2009-03-07  Bruno Haible  <bruno@clisp.org>
 
 	Tests for module 'uninorm/u32-normcoll'.
--- a/lib/uninorm.h
+++ b/lib/uninorm.h
@@ -152,7 +152,7 @@
 /* Compare S1 and S2, ignoring differences in normalization.
    NF must be either UNINORM_NFD or UNINORM_NFKD.
    If successful, set *RESULT to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
-   return 0.  Upon failure, return the error number.  */
+   return 0.  Upon failure, return -1 with errno set.  */
 extern int
        u8_normcmp (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2,
 		   uninorm_t nf, int *result);
@@ -183,7 +183,7 @@
    collation rules of the current locale.
    NF must be either UNINORM_NFC or UNINORM_NFKC.
    If successful, set *RESULT to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
-   return 0.  Upon failure, return the error number.  */
+   return 0.  Upon failure, return -1 with errno set.  */
 extern int
        u8_normcoll (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2,
 		    uninorm_t nf, int *result);
--- a/lib/uninorm/u-normcmp.h
+++ b/lib/uninorm/u-normcmp.h
@@ -31,17 +31,21 @@
   norms1_length = sizeof (buf1) / sizeof (UNIT);
   norms1 = U_NORMALIZE (nf, s1, n1, buf1, &norms1_length);
   if (norms1 == NULL)
-    return errno;
+    /* errno is set here.  */
+    return -1;
 
   /* Normalize S2.  */
   norms2_length = sizeof (buf2) / sizeof (UNIT);
   norms2 = U_NORMALIZE (nf, s2, n2, buf2, &norms2_length);
   if (norms2 == NULL)
     {
-      int saved_errno = errno;
       if (norms1 != buf1)
-	free (norms1);
-      return saved_errno;
+	{
+	  int saved_errno = errno;
+	  free (norms1);
+	  errno = saved_errno;
+	}
+      return -1;
     }
 
   /* Compare the normalized strings.  */
--- a/lib/uninorm/u-normcoll.h
+++ b/lib/uninorm/u-normcoll.h
@@ -31,17 +31,21 @@
   transformed1_length = sizeof (buf1);
   transformed1 = U_NORMXFRM (s1, n1, nf, buf1, &transformed1_length);
   if (transformed1 == NULL)
-    return errno;
+    /* errno is set here.  */
+    return -1;
 
   /* Normalize and transform S2.  */
   transformed2_length = sizeof (buf2);
   transformed2 = U_NORMXFRM (s2, n2, nf, buf2, &transformed2_length);
   if (transformed2 == NULL)
     {
-      int saved_errno = errno;
       if (transformed1 != buf1)
-	free (transformed1);
-      return saved_errno;
+	{
+	  int saved_errno = errno;
+	  free (transformed1);
+	  errno = saved_errno;
+	}
+      return -1;
     }
 
   /* Compare the transformed strings.  */