unistr/u*-stpncpy: Fix the return value.
authorBruno Haible <bruno@clisp.org>
Sun, 10 Jan 2010 20:39:12 +0000 (21:39 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 10 Jan 2010 20:39:12 +0000 (21:39 +0100)
ChangeLog
lib/unistr.h
lib/unistr/u-stpncpy.h

index 6a46d149f284ff85d4e098add13cbbd5f3847307..f1f514a1293c897e3c360b7400500fc4ad83491d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-01-10  Bruno Haible  <bruno@clisp.org>
+
+       unistr/u*-stpncpy: Fix the return value.
+       * lib/unistr.h (u8_stpncpy, u16_stpncpy, u32_stpncpy): Make the
+       description of the return value consistent with stpncpy in glibc.
+       * lib/unistr/u-stpncpy.h (FUNC): Return the pointer past the last
+       written non-NUL unit.
+
 2010-01-10  Bruno Haible  <bruno@clisp.org>
 
        unistr/u*-next: Add missing dependencies.
index 1cdf3a8a6027c07d68bfb593acf2fb95f0502aa7..26a3e33e458fa42943924eb90dd6709ad7516e47 100644 (file)
@@ -529,8 +529,8 @@ extern uint16_t *
 extern uint32_t *
        u32_strncpy (uint32_t *dest, const uint32_t *src, size_t n);
 
-/* Copy no more than N units of SRC to DEST, returning the address of
-   the last unit written into DEST.  */
+/* Copy no more than N units of SRC to DEST.  Return a pointer past the last
+   non-NUL unit written into DEST.  */
 /* Similar to stpncpy().  */
 extern uint8_t *
        u8_stpncpy (uint8_t *dest, const uint8_t *src, size_t n);
index 335a8519d868c693e1fe97edb113bc9c2ec113af..4d6dd3c7010a06c78912a2df7837a680babf37dd 100644 (file)
@@ -23,8 +23,12 @@ FUNC (UNIT *dest, const UNIT *src, size_t n)
 
   /* This behavior is rarely useful, but it is here for consistency with
      strncpy and wcsncpy.  */
-  for (; n > 0; n--)
-    *dest++ = 0;
+  {
+    UNIT *destptr = dest;
 
-  return dest - 1;
+    for (; n > 0; n--)
+      *destptr++ = 0;
+  }
+
+  return dest;
 }