[Github-comments] [geany/geany] Windows: Convert working directory to locale encoding before spawning commands (#1095)

Enrico Tröger notifications at xxxxx
Tue Jun 28 15:02:39 UTC 2016


I completely agree on current state about encodings is far from what it should be. Though I guess we won't get it in a much better shape so close to a release.

Regarding the correct place in spawn.c:spawn_async_with_pipes():
I just added a commit which also converts the command string to be executed, as it is affected in the same way.
But also a check to perform the conversion only if the input string is valid UTF-8. Consider this as some kind of compability layer, if any caller passes an already locale-encoded string in, it won't be touched.
Still I think, this place is not that wrong, at least on Windows, because usually we say: "use `utils_get_locale_from_utf8` everywhere!" and on Windows this is just a no-op. This is OK for almost all places, especially when dealing with filenames and the GLib file API.
*But* it is wrong when using the Windows API directly which we do here (`CreateProcess`) and why should a caller think about this?
The caller just puts the string as returned from `utils_get_locale_from_utf8` into the spawn_ API and doesn't need to know about the fact that on Windows here we actually need real locale encoding and not just UTF-8.
The only drawback is probably a few unnecessary string duplications but I could live with this.


Regarding cmd.exe and the generated batch script:
> (same in the batch script, if a locale-encoded directory name can work, better use that than play with the codepage I guess)
Agreed. Unfortunately, a locale-encoded directory won't work here. For some reason, there is a difference with cmd.exe. On my system, the system locale is Windows-1252 but cmd.exe uses CP850. So if I would encode the directory into the system locale, cmd.exe won't accept it.
But if I convert the whole script content into the system codepage, it works fine. This is what I did in a95f174 to get rid of the ugly `chcp` thing. So we also convert the program/script filename which is to be executed, as it is affected in the same way, as mentioned above.
And as in the changes mentioned above for spawn.c, here the codepage conversion is also only performed if the input string is valid UTF-8.

While this is all far from perfect and need to be solved more generally, I think it's a first step in getting solved known problems (#1076).

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/1095#issuecomment-229077233
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20160628/eaa6ce95/attachment.html>


More information about the Github-comments mailing list