[rtems commit] dosfs: Correct handling of iconv() return value

Sebastian Huber sebh at rtems.org
Tue Sep 10 12:44:38 UTC 2013


Module:    rtems
Branch:    master
Commit:    3dbb68d99177dc9682ffca3c3d42802c319e4975
Changeset: http://git.rtems.org/rtems/commit/?id=3dbb68d99177dc9682ffca3c3d42802c319e4975

Author:    Ralf Kirchner <ralf.kirchner at embedded-brains.de>
Date:      Tue Sep 10 10:48:23 2013 +0200

dosfs: Correct handling of iconv() return value

---

 cpukit/libfs/src/dosfs/msdos_conv_utf8.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/cpukit/libfs/src/dosfs/msdos_conv_utf8.c b/cpukit/libfs/src/dosfs/msdos_conv_utf8.c
index 18aebc6..1399734 100644
--- a/cpukit/libfs/src/dosfs/msdos_conv_utf8.c
+++ b/cpukit/libfs/src/dosfs/msdos_conv_utf8.c
@@ -52,12 +52,12 @@ static int msdos_utf8_convert_with_iconv(
   size_t     *dst_size
 )
 {
-  int     eno = 0;
+  int     eno;
   size_t  inbytes_left = src_size;
   size_t  outbytes_left = *dst_size;
   char   *inbuf = (void *) (uintptr_t) src;
   char   *outbuf = dst;
-  ssize_t iconv_status;
+  size_t  iconv_status;
 
   iconv_status = iconv(
     desc,
@@ -69,10 +69,21 @@ static int msdos_utf8_convert_with_iconv(
 
   *dst_size -= outbytes_left;
 
-  if ( iconv_status > 0 ) {
-    eno = EINVAL;
-  } else if ( iconv_status < 0 ) {
+  if ( iconv_status == 0 ) {
+    eno = 0;
+  } else if ( iconv_status == (size_t) -1 ) {
+    /*
+     * iconv() has detected an error.  The most likely reason seems to be a too
+     * small outbuf.
+    */
     eno = ENOMEM;
+  } else {
+    /*
+     * The iconv_status contains the number of characters converted in a
+     * non-reversible way.  We want to use reversible conversions only.
+     * Characters permitted within DOSFS names seem to be reversible.
+     */
+    eno = EINVAL;
   }
 
   return eno;




More information about the vc mailing list