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

file: Support unicode urls on windows #6501

Closed
wants to merge 1 commit into from

Conversation

foopoiuyt
Copy link
Contributor

Support file: urls with utf-8 filenames on Windows when _UNICODE is defined.

@jay jay added the Windows Windows-specific label Jan 21, 2021
@jay
Copy link
Member

jay commented Jan 21, 2021

https://dev.azure.com/daniel0244/5571c33c-81e1-43d7-93ee-d3d4152f27b2/_apis/build/builds/4396/logs/99

2021-01-21T00:23:08.4699191Z file.c: In function 'file_upload':
2021-01-21T00:23:08.4700646Z file.c:280:55: error: macro "open" passed 3 arguments, but takes just 2
2021-01-21T00:23:08.4701344Z    fd = open(file->path, mode, data->set.new_file_perms);
2021-01-21T00:23:08.4701886Z                                                        ^
2021-01-21T00:23:08.4704068Z file.c:280:6: error: assignment to 'int' from 'int (__attribute__((cdecl)) *)(const char *, int,  ...)' {aka 'int (*)(const char *, int,  ...)'} makes integer from pointer without a cast [-Wint-conversion]
2021-01-21T00:23:08.4705100Z    fd = open(file->path, mode, data->set.new_file_perms);
2021-01-21T00:23:08.4705770Z       ^

That is because open takes 2 or 3 arguments. To fix it you could do # define open curlx_win32_open and then make curlx_win32_open variadic. The alternative is a variadic macro but I don't think that's supported with all compilers.

lib/curl_setup.h Outdated
@@ -356,9 +358,11 @@
# define fstat(fdes,stp) _fstat(fdes, stp)
# define stat(fname,stp) curlx_win32_stat(fname, stp)
# define struct_stat struct _stat
# define open(fname,oflag) curlx_win32_open(fname, oflag)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't redfine a POSIX syscall

return result;
#endif

return (open)(filename, oflag);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why even define the function on non Windows platforms?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, this is in a #if defined(USE_WIN32_LARGE_FILES) || defined(USE_WIN32_SMALL_FILES) block.

int curlx_win32_open(const char *filename, int oflag)
{
#ifdef _UNICODE
int result = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, totally missed it (and the later check as mentioned below).

@foopoiuyt foopoiuyt force-pushed the windows_unicode_file branch 3 times, most recently from 63585f8 to 1106ff3 Compare January 21, 2021 22:21
@@ -82,6 +82,29 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w)

#if defined(USE_WIN32_LARGE_FILES) || defined(USE_WIN32_SMALL_FILES)

int curlx_win32_open(const char *filename, int oflag, ...)
{
int pmode = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is wrong here.

if(filename_w)
result = _wopen(filename_w, oflag, pmode);
free(filename_w);
if(result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be if(result != -1) now.

lib/curl_setup.h Outdated
@@ -356,9 +359,12 @@
# define fstat(fdes,stp) _fstat(fdes, stp)
# define stat(fname,stp) curlx_win32_stat(fname, stp)
# define struct_stat struct _stat
# define open(fname,oflag,...) curlx_win32_open(fname, oflag \
, ## __VA_ARGS__)
Copy link
Member

@jay jay Jan 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do away with __VA_ARGS__ I don't think all compilers support it

@foopoiuyt foopoiuyt force-pushed the windows_unicode_file branch 5 times, most recently from 9a9a4fc to cf951b5 Compare January 22, 2021 21:17
@jay jay added the feature-window A merge of this requires an open feature window label Jan 24, 2021
@jay jay changed the title WIP: file: Support unicode urls on windows file: Support unicode urls on windows Jan 24, 2021
@jay jay closed this in 1269c80 Feb 9, 2021
@jay jay removed the feature-window A merge of this requires an open feature window label Feb 9, 2021
@jay
Copy link
Member

jay commented Feb 9, 2021

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Windows Windows-specific
Development

Successfully merging this pull request may close these issues.

None yet

5 participants