diff --git a/System/IO/Encoding.hs b/System/IO/Encoding.hs index e0c42b0..0e93eb7 100644 --- a/System/IO/Encoding.hs +++ b/System/IO/Encoding.hs @@ -131,12 +131,19 @@ interact f = do line <- hGetLine stdin hPutStrLn stdout (f line) +#ifdef SYSTEM_ENCODING foreign import ccall "system_encoding.h get_system_encoding" get_system_encoding :: IO CString +#endif --- | Returns the encoding used on the current system. +-- | Returns the encoding used on the current system. Currently only supported +-- on Linux-alikes. getSystemEncoding :: IO DynEncoding getSystemEncoding = do +#ifdef SYSTEM_ENCODING enc <- get_system_encoding str <- peekCString enc - return $ encodingFromString str \ No newline at end of file + return $ encodingFromString str +#else + error "getSystemEncoding is not supported on this platform" +#endif diff --git a/encoding.cabal b/encoding.cabal index d4af523..24b0b8a 100644 --- a/encoding.cabal +++ b/encoding.cabal @@ -18,11 +18,15 @@ Extra-Source-Files: Data/CharMap/Builder.hs Data/Array/Static/Builder.hs Data/Map/Static/Builder.hs + system_encoding.h + system_encoding.c Flag splitBase description: Choose the new smaller, split-up base package. Flag newGHC description: Use ghc version > 6.10 +Flag systemEncoding + description: Provide the getSystemEncoding action to query the locale. Library Build-Depends: binary, extensible-exceptions, HaXml >= 1.22 && < 1.24 @@ -35,6 +39,8 @@ Library else Build-Depends: base < 3 + Extensions: CPP + Exposed-Modules: Data.Encoding Data.Encoding.ByteSource @@ -102,9 +108,11 @@ Library Data.Map.Static Data.Static Data.CharMap - Includes: - system_encoding.h - Install-Includes: - system_encoding.h - C-Sources: - system_encoding.c \ No newline at end of file + if flag(systemEncoding) + Includes: + system_encoding.h + Install-Includes: + system_encoding.h + C-Sources: + system_encoding.c + CPP-Options: -DSYSTEM_ENCODING