| 1 | /* |
| 2 | * This file is part of libdvdread. |
| 3 | * |
| 4 | * libdvdread 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. |
| 8 | * |
| 9 | * libdvdread 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. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with libdvdread; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | */ |
| 18 | |
| 19 | #include <stdlib.h> |
| 20 | #include <windows.h> |
| 21 | |
| 22 | static inline wchar_t *_utf8_to_wchar(const char *utf8) |
| 23 | { |
| 24 | wchar_t *wstr; |
| 25 | int wlen; |
| 26 | |
| 27 | wlen = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0); |
| 28 | if (wlen < 1) { |
| 29 | return NULL; |
| 30 | } |
| 31 | wstr = (wchar_t*)malloc(sizeof(wchar_t) * wlen); |
| 32 | if (!wstr ) { |
| 33 | return NULL; |
| 34 | } |
| 35 | if (!MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, wlen)) { |
| 36 | free(wstr); |
| 37 | return NULL; |
| 38 | } |
| 39 | return wstr; |
| 40 | } |