Skip to content

Commit

Permalink
cast bytes to char* first, then to wchar_t
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBarker-NOAA committed Mar 12, 2024
1 parent 9d101da commit e484e69
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions py_gd/py_gd.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ cdef FILE* open_file(file_path) except *:

IF UNAME_SYSNAME == 'Windows':
# convert pystring to wchar
cdef wchar_t* windows_filename
cdef wchar_t* flag = <wchar_t*> "wb".encode('utf-16')
windows_filename = <wchar_t*> file_path.encode('utf-16')
fp = _wfopen(windows_filename, flag)
# doing in two steps -- neccesary? it seems so.
# (Cython knows how to cast a bytes to a char*)
cdef char* windows_filename = file_path.encode('utf-16')
cdef char* flag = "wb".encode('utf-16')
fp = _wfopen(<wchar_t*> windows_filename, <wchar_t*> flag)
ELSE:
fp = fopen(file_path.encode('utf-8'), 'wb')

Expand Down

0 comments on commit e484e69

Please sign in to comment.