Add -lole32 to link libraries.
This fixes a problem when compiling with mingw-headers version 3.3
where the use of SHGetFolderPath() expands to a call to CoTaskMemFree()
which is defined in libole32.dll:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/shobjidl.h:29954: undefined reference to `__imp_CoTaskMemFree'
2 * Copyright (C) 2014 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "razor-internal.h"
26 * razor_path_add_root:
28 * Adds a root to a path. path must be an absolute pathname. In POSIX
29 * environments this is equivalent to the concationation of root and path.
30 * In Microsoft Windows an adjustment may need to be made for a drive letter
31 * in path (which will be dropped).
33 * Returns: The new pathname.
35 RAZOR_EXPORT char *razor_path_add_root(const char *path, const char *root)
38 return razor_concat(root, SKIP_DRIVE_LETTER(path), NULL);
46 * This should work, but for some reason PathCreateFromUrlW()
47 * treats the percent-encoded bytes as being in CP 850 rather
48 * than UTF-8 as expected even if we set the codepage.
50 RAZOR_EXPORT char *razor_path_from_url(const char *url)
56 wchar_t path16[MAX_PATH];
59 url16 = razor_utf8_to_utf16(url, -1);
61 saved_cp = GetConsoleCP();
62 SetConsoleCP(CP_UTF8);
64 result = PathCreateFromUrlW(url16, path16, &len, NULL);
66 SetConsoleCP(saved_cp);
69 path = razor_utf16_to_utf8(path16, len);
81 static int is_ascii_letter(char c)
83 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
87 static int xdigit_value(char c)
89 if (c >= '0' && c <= '9')
92 return (c | 0x20) - 'a' + 10;
95 static int valid_unicode(unsigned unicode)
98 * Within the U+0000..U+10FFFF range defined by RFC3629
99 * but not in the U+D800..U+DFFF range prohibited in UTF-8.
101 return unicode < 0xD800 || (unicode >= 0xE000 && unicode < 0x110000);
104 RAZOR_EXPORT char *razor_path_from_url(const char *url)
106 int continuation_bytes = 0;
111 if (strncmp(url, "file://", 7) == 0)
116 if (strncmp(url, "localhost/", 10) == 0)
118 else if (strncmp(url, "/", 1) != 0)
123 * Under MS-Windows, file:///c:/xxx maps to c:/xxx
124 * Note that PathCreateFromUrl converts / to \ as well.
126 if (is_ascii_letter(url[1]) && url[2] == ':' && url[3] == '/')
130 p = path = malloc(strlen(url) + 1);
133 if (*url >= 0x7F || *url < 0x20) {
136 } else if (*url != '%') {
137 if (continuation_bytes) {
142 } else if (isxdigit(url[1]) && isxdigit(url[2])) {
143 c = xdigit_value(url[1]) * 16 + xdigit_value(url[2]);
147 } else if (!continuation_bytes) {
148 if (c >= 0xF5 || c == 0xC0 || c == 0xC1) {
151 } else if (c >= 0xF0) {
153 continuation_bytes = 3;
154 } else if (c >= 0xE0) {
156 continuation_bytes = 2;
157 } else if (c >= 0xC0) {
159 continuation_bytes = 1;
161 } else if ((c & 0xC0) != 0x80) {
166 unicode |= (c & 0x3F);
168 if (!--continuation_bytes &&
169 !valid_unicode(unicode)) {
183 if (continuation_bytes) {
190 return realloc(path, p - path);