Don't throw an error if the output buffer had no room
[ghc-base.git] / GHC / IO / Encoding / Iconv.hs
index fd35fc6..faf58e9 100644 (file)
@@ -30,7 +30,7 @@ module GHC.IO.Encoding.Iconv (
 
 #if !defined(mingw32_HOST_OS)
 
-import Foreign
+import Foreign hiding (unsafePerformIO)
 import Foreign.C
 import Data.Maybe
 import GHC.Base
@@ -39,6 +39,7 @@ import GHC.IO.Encoding.Types
 import GHC.Num
 import GHC.Show
 import GHC.Real
+import System.IO.Unsafe (unsafePerformIO)
 import System.Posix.Internals
 
 c_DEBUG_DUMP :: Bool
@@ -131,6 +132,7 @@ char_shift | charSize == 2 = 1
 mkTextEncoding :: String -> IO TextEncoding
 mkTextEncoding charset = do
   return (TextEncoding { 
+                textEncodingName = charset,
                mkTextDecoder = newIConv charset haskellChar iconvDecode,
                mkTextEncoder = newIConv haskellChar charset iconvEncode})
 
@@ -192,11 +194,10 @@ iconvRecode iconv_t
        else do
       errno <- getErrno
       case errno of
-       e |  e == eINVAL 
-          || (e == e2BIG || e == eILSEQ) && new_inleft' /= (iw-ir) -> do
+        e |  e == eINVAL || e == e2BIG
+          || e == eILSEQ && new_inleft' /= (iw-ir) -> do
             iconv_trace ("iconv ignoring error: " ++ show (errnoToIOError "iconv" e Nothing Nothing))
-               -- Output overflow is relatively harmless, unless
-               -- we made no progress at all.  
+                -- Output overflow is harmless
                 --
                 -- Similarly, we ignore EILSEQ unless we converted no
                 -- characters.  Sometimes iconv reports EILSEQ for a
@@ -209,8 +210,9 @@ iconvRecode iconv_t
                 -- the buffer have been drained.
             return (new_input, new_output)
 
-       _other -> 
-               throwErrno "iconvRecoder" 
+        e -> do
+                iconv_trace ("iconv returned error: " ++ show (errnoToIOError "iconv" e Nothing Nothing))
+                throwErrno "iconvRecoder"
                        -- illegal sequence, or some other error
 
 #endif /* !mingw32_HOST_OS */