Ticket #5666 (new bug)

Opened 18 months ago

Last modified 4 months ago

Can't use writeFile to write unicode characters.

Reported by: tsou Owned by:
Priority: normal Milestone: 7.6.2
Component: libraries (other) Version: 7.4.2
Keywords: unicode writeFile Cc:
Operating System: OpenBSD Architecture: x86_64 (amd64)
Type of failure: Runtime crash Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I tried to the "locale" environmental variables to "en_US.utf8", but still I cannot write unicode characters.

source:

main = do
    hSetEncoding stdout utf8
    putStrLn "αρχίδια"
    writeFile "hello.txt" "σκατούλες"

output:

αρχίδια
commitBuffer: invalid argument (Illegal byte sequence)

without manually hSetEncoding stdin, putStrLn also fails with the same error message.

From what I was told on #haskell, on linux ghc uses setlocale to figure out what encoding to use, but this is not present in OpenBSD.

Simply making those functions read $LANG (I think) would solve this for OpenBSD, but I might be wrong.

Change History

Changed 17 months ago by igloo

  • status changed from new to infoneeded
  • difficulty set to Unknown
  • milestone set to 7.6.1

What exactly do you mean by 'the "locale" environmental variables'?

Also, do you have a "locale" program? If so, what is the output when you run it?

Changed 9 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2

Changed 4 months ago by igloo

  • status changed from infoneeded to closed
  • resolution set to worksforme

No response from submitter, so closing.

Changed 4 months ago by tsou

  • keywords unicode writeFile added
  • status changed from closed to new
  • version changed from 7.0.4 to 7.4.2
  • resolution worksforme deleted

What exactly do you mean by 'the "locale" environmental variables'?

I meant LANG and LC_ALL, etc.

Also, do you have a "locale" program? If so, what is the output when you run it?

There's no locale program. Only a setlocale(3) function..  http://www.openbsd.org/cgi-bin/man.cgi?query=setlocale&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html

Usually, applications (for example tmux, mutt, etc.) that may need to output unicode characters, understand the locale by reading those enviromental variables I mentioned above. I thought it would work like that with haskell, but I was wrong.

Let me know if you need anything else.

Thanks!

Note: See TracTickets for help on using tickets.