Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with unicode characters in filenames on Windows 10 (Unix-like situation is currently unknown to me). #35

Open
thalassocracy opened this issue Dec 17, 2020 · 1 comment

Comments

@thalassocracy
Copy link

https://github.com/JuliaAudio/LibSndFile.jl/blob/master/src/libsndfile_h.jl#L122

function sf_open(fname::String, mode, sfinfo)
    filePtr = ccall((:sf_open, libsndfile), Ptr{Cvoid},
                    (Cstring, Int32, Ref{SF_INFO}),
                    fname, mode, sfinfo)

    if filePtr == C_NULL
        error("LibSndFile.jl error while opening $fname: ", sf_strerror(C_NULL))
    end

    filePtr
end

Fixed on Windows 10 by changing Cstring to Cwstring and sf_open to sf_wchar_open.

The sf_wchar_open change is definitely Windows-specific, but there's a chance that opening filenames with wide characters in them on Unix-like systems will also benefit from changing Cstring to Cwstring. I will experiment with this at some point in the near future on Linux.

If I find that Linux also requires Cwstring, I will open a pull req with that change (but not the Windows-specific sf_wchar_open).

@thalassocracy thalassocracy changed the title Issues with unicode characters in filenames on Windows 10 (Unix-like situation is currently unknown). Issues with unicode characters in filenames on Windows 10 (Unix-like situation is currently unknown to me). Dec 17, 2020
nantonel added a commit to nantonel/LibSndFile.jl that referenced this issue Oct 27, 2021
@nantonel
Copy link
Collaborator

I partially fixed the problem in Julia 1.6 using the following:

  if Sys.iswindows()
    ptr = pointer(transcode(Cwchar_t,fname))
    filePtr = ccall((:sf_wchar_open, libsndfile), Ptr{Cvoid},
                    (Cwstring, Int32, Ref{SF_INFO}),
                    Cwstring(ptr), mode, sfinfo)
  else
    filePtr = ccall((:sf_open, libsndfile), Ptr{Cvoid},
                    (Cstring, Int32, Ref{SF_INFO}),
                    fname, mode, sfinfo)
  end

however some tests are randomly breaking with the message The filename, directory name, or volume label syntax is incorrect.. This seems to be a Windows string encoding problem. Possibly it'll be fixed in newer Julia versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants