InsaneCoder
InsaneCoder

Reputation: 8268

readdir() in linux sometimes not returning correct string utf8

I have a file in a folder with name as

01一千个伤心的理由 张学友

but sometimes readdir() is simply returning all ????????? as the name of the file.

I searched for this on google and found that readdir has some utf-8 issue on some systems (like this one). Did I read correct? If on linux, this is the problem then is there any solution?

EDIT The problem is that there are actually two scripts (one is mine and there is another also) which are mounting the same device on two different paths. I am mounting as utf-8 but the other one is not mounting it as utf-8 (its probably in default mode). So if mine script runs first on reboot or device insert, everything is fine. Otherwise the problem comes.

So the question is why the two mounts are affecting the other one and how can I correct it?

Upvotes: 2

Views: 200

Answers (1)

janneb
janneb

Reputation: 37188

On Linux (or more generally, POSIX), pathnames are just a bunch of arbitrary bytes terminated by a '\0' (ASCII NULL) character, with pathname components separated by '/'. Every other byte value is allowed. How to interpret those bytes is up to the application. So most likely your problem has to do with different locale settings etc. E.g. "script 1" creates a pathname which contains invalid UTF-8 but happens to be correctly printable characters in whatever locale that "script 1" is running in.

Upvotes: 1

Related Questions