From 4d0344cf0ca59b3d0e8e8396af65de1c50e06d9e Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 8 Mar 2009 03:18:26 +0100
Subject: [PATCH] Adjust u*_normcmp, u*_normcoll API.

---
 ChangeLog                |  9 +++++++++
 lib/uninorm.h            |  4 ++--
 lib/uninorm/u-normcmp.h  | 12 ++++++++----
 lib/uninorm/u-normcoll.h | 12 ++++++++----
 4 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4f87a95699..36bba2dc8a 100644
--- 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'.
diff --git a/lib/uninorm.h b/lib/uninorm.h
index e4153cf63a..ec14e09f6d 100644
--- a/lib/uninorm.h
+++ b/lib/uninorm.h
@@ -152,7 +152,7 @@ extern uint32_t *
 /* 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 @@ extern char *
    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);
diff --git a/lib/uninorm/u-normcmp.h b/lib/uninorm/u-normcmp.h
index 33d1e6252b..0305fbce31 100644
--- a/lib/uninorm/u-normcmp.h
+++ b/lib/uninorm/u-normcmp.h
@@ -31,17 +31,21 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
   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.  */
diff --git a/lib/uninorm/u-normcoll.h b/lib/uninorm/u-normcoll.h
index 5af764eba1..a8bf29ca8e 100644
--- a/lib/uninorm/u-normcoll.h
+++ b/lib/uninorm/u-normcoll.h
@@ -31,17 +31,21 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
   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.  */
-- 
2.39.5