Updated MediaInfo binaries to v19.07 (2019-07-16), compiled with ICL 19.0 and MSVC...
[LameXP.git] / etc / Patches / SoX-v14.4.2-Win32-UTF8.V2.diff
blob60bf9486a29c9fc6a6af0ba47d15ade3fdcafa6a
1 src/effects_i.c | 3 +-
2 src/formats.c | 9 ++-
3 src/libsox_i.c | 7 +-
4 src/noiseprof.c | 3 +-
5 src/sox.c | 30 ++++++--
6 src/unicode_support.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++
7 src/unicode_support.h | 46 ++++++++++++
8 7 files changed, 282 insertions(+), 15 deletions(-)
10 diff --git a/src/effects_i.c b/src/effects_i.c
11 index 685e962..deee444 100644
12 --- a/src/effects_i.c
13 +++ b/src/effects_i.c
14 @@ -20,6 +20,7 @@
16 #define LSX_EFF_ALIAS
17 #include "sox_i.h"
18 +#include "unicode_support.h"
19 #include <string.h>
20 #include <ctype.h>
22 @@ -463,7 +464,7 @@ FILE * lsx_open_input_file(sox_effect_t * effp, char const * filename, sox_bool
23 effp->global_info->global_info->stdin_in_use_by = effp->handler.name;
24 file = stdin;
26 - else if (!(file = fopen(filename, text_mode ? "r" : "rb"))) {
27 + else if (!(file = lsx_fopen(filename, text_mode ? "r" : "rb"))) {
28 lsx_fail("couldn't open file %s: %s", filename, strerror(errno));
29 return NULL;
31 diff --git a/src/formats.c b/src/formats.c
32 index 724a4cd..a5b65d9 100644
33 --- a/src/formats.c
34 +++ b/src/formats.c
35 @@ -19,6 +19,7 @@
38 #include "sox_i.h"
39 +#include "unicode_support.h"
41 #include <assert.h>
42 #include <ctype.h>
43 @@ -401,7 +402,7 @@ static FILE * xfopen(char const * identifier, char const * mode, lsx_io_type * i
44 #endif
45 return f;
47 - return fopen(identifier, mode);
48 + return lsx_fopen(identifier, mode);
51 /* Hack to rewind pipes (a small amount).
52 @@ -853,8 +854,8 @@ static sox_format_t * open_write(
53 ft->fp = stdout;
55 else {
56 - struct stat st;
57 - if (!stat(path, &st) && (st.st_mode & S_IFMT) == S_IFREG &&
58 + struct _stat st;
59 + if (!lsx_stat(path, &st) && (st.st_mode & S_IFMT) == S_IFREG &&
60 (overwrite_permitted && !overwrite_permitted(path))) {
61 lsx_fail("permission to overwrite `%s' denied", path);
62 goto error;
63 @@ -864,7 +865,7 @@ static sox_format_t * open_write(
64 buffer? fmemopen(buffer, buffer_size, "w+b") :
65 buffer_ptr? open_memstream(buffer_ptr, buffer_size_ptr) :
66 #endif
67 - fopen(path, "w+b");
68 + lsx_fopen(path, "w+b");
69 if (ft->fp == NULL) {
70 lsx_fail("can't open output file `%s': %s", path, strerror(errno));
71 goto error;
72 diff --git a/src/libsox_i.c b/src/libsox_i.c
73 index a5afb8e..f834136 100644
74 --- a/src/libsox_i.c
75 +++ b/src/libsox_i.c
76 @@ -20,6 +20,7 @@
79 #include "sox_i.h"
80 +#include "unicode_support.h"
82 #ifdef HAVE_IO_H
83 #include <io.h>
84 @@ -48,8 +49,8 @@
85 #ifdef WIN32
86 static int check_dir(char * buf, size_t buflen, char const * name)
88 - struct stat st;
89 - if (!name || stat(name, &st) || (st.st_mode & S_IFMT) != S_IFDIR)
90 + struct _stat st;
91 + if (!name || lsx_stat(name, &st) || (st.st_mode & S_IFMT) != S_IFDIR)
93 return 0;
95 @@ -102,7 +103,7 @@ FILE * lsx_tmpfile(void)
96 fildes = mkstemp(name);
97 #ifdef HAVE_UNISTD_H
98 lsx_debug(FAKE_MKSTEMP "mkstemp, name=%s (unlinked)", name);
99 - unlink(name);
100 + lsx_unlink(name);
101 #else
102 lsx_debug(FAKE_MKSTEMP "mkstemp, name=%s (O_TEMPORARY)", name);
103 #endif
104 diff --git a/src/noiseprof.c b/src/noiseprof.c
105 index 8fe6d4f..fd798ca 100644
106 --- a/src/noiseprof.c
107 +++ b/src/noiseprof.c
108 @@ -19,6 +19,7 @@
111 #include "noisered.h"
112 +#include "unicode_support.h"
114 #include <assert.h>
115 #include <string.h>
116 @@ -75,7 +76,7 @@ static int sox_noiseprof_start(sox_effect_t * effp)
117 effp->global_info->global_info->stdout_in_use_by = effp->handler.name;
118 data->output_file = stdout;
120 - else if ((data->output_file = fopen(data->output_filename, "wb")) == NULL) {
121 + else if ((data->output_file = lsx_fopen(data->output_filename, "wb")) == NULL) {
122 lsx_fail("Couldn't open profile file %s: %s", data->output_filename, strerror(errno));
123 return SOX_EOF;
125 diff --git a/src/sox.c b/src/sox.c
126 index fcdac94..ec1dffe 100644
127 --- a/src/sox.c
128 +++ b/src/sox.c
129 @@ -24,6 +24,7 @@
130 #include "soxconfig.h"
131 #include "sox.h"
132 #include "util.h"
133 +#include "unicode_support.h"
135 #include <ctype.h>
136 #include <errno.h>
137 @@ -238,10 +239,10 @@ static void cleanup(void)
138 if (file_count) {
139 if (ofile->ft) {
140 if (!success && ofile->ft->io_type == lsx_io_file) { /* If we failed part way through */
141 - struct stat st; /* writing a normal file, remove it. */
142 - if (!stat(ofile->ft->filename, &st) &&
143 + struct _stat st; /* writing a normal file, remove it. */
144 + if (!lsx_stat(ofile->ft->filename, &st) &&
145 (st.st_mode & S_IFMT) == S_IFREG)
146 - unlink(ofile->ft->filename);
147 + lsx_unlink(ofile->ft->filename);
149 sox_close(ofile->ft); /* Assume we can unlink a file before closing it. */
151 @@ -905,7 +906,7 @@ static char * * strtoargv(char * s, int * argc)
153 static void read_user_effects(char const *filename)
155 - FILE *file = fopen(filename, "r");
156 + FILE *file = lsx_fopen(filename, "r");
157 const size_t buffer_size_step = 1024;
158 size_t buffer_size = buffer_size_step;
159 char *s = lsx_malloc(buffer_size); /* buffer for one input line */
160 @@ -2136,7 +2137,7 @@ static void read_comment_file(sox_comments_t * comments, char const * const file
161 int c;
162 size_t text_length = 100;
163 char * text = lsx_malloc(text_length + 1);
164 - FILE * file = fopen(filename, "r");
165 + FILE * file = lsx_fopen(filename, "r");
167 if (file == NULL) {
168 lsx_fail("Cannot open comment file `%s'", filename);
169 @@ -2848,7 +2849,7 @@ static sox_bool cmp_comment_text(char const * c1, char const * c2)
170 return c1 && c2 && !strcasecmp(c1, c2);
173 -int main(int argc, char **argv)
174 +static int sox_main(int argc, char **argv)
176 size_t i;
177 char mybase[6];
178 @@ -3051,3 +3052,20 @@ int main(int argc, char **argv)
180 return 0;
183 +int main(int argc, char **argv)
185 + int sox_argc;
186 + char **sox_argv;
187 + int exit_code;
189 + lsx_init_console();
190 + lsx_init_commandline_arguments(&sox_argc, &sox_argv);
192 + exit_code = sox_main(sox_argc, sox_argv);
194 + lsx_uninit_console();
195 + lsx_free_commandline_arguments(&sox_argc, &sox_argv);
197 + return exit_code;
199 diff --git a/src/unicode_support.c b/src/unicode_support.c
200 new file mode 100644
201 index 0000000..f89aa7b
202 --- /dev/null
203 +++ b/src/unicode_support.c
204 @@ -0,0 +1,199 @@
205 +/* Copyright (c) 2004-2015 LoRd_MuldeR <mulder2@gmx.de>
206 + File: unicode_support.c
208 + This file was originally part of a patch included with LameXP,
209 + released under the same license as the original audio tools.
211 + Redistribution and use in source and binary forms, with or without
212 + modification, are permitted provided that the following conditions
213 + are met:
215 + - Redistributions of source code must retain the above copyright
216 + notice, this list of conditions and the following disclaimer.
218 + - Redistributions in binary form must reproduce the above copyright
219 + notice, this list of conditions and the following disclaimer in the
220 + documentation and/or other materials provided with the distribution.
222 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
223 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
224 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
225 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
226 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
227 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
228 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
229 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
230 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
231 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
232 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
234 +#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
236 +#include "unicode_support.h"
238 +#include <windows.h>
239 +#include <io.h>
241 +static UINT g_old_output_cp = ((UINT)-1);
243 +static char *utf16_to_utf8(const wchar_t *input)
245 + char *Buffer;
246 + int BuffSize = 0, Result = 0;
248 + BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
249 + Buffer = (char*) malloc(sizeof(char) * BuffSize);
250 + if(Buffer)
252 + Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
255 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
258 +static char *utf16_to_ansi(const wchar_t *input)
260 + char *Buffer;
261 + int BuffSize = 0, Result = 0;
263 + BuffSize = WideCharToMultiByte(CP_ACP, 0, input, -1, NULL, 0, NULL, NULL);
264 + Buffer = (char*) malloc(sizeof(char) * BuffSize);
265 + if(Buffer)
267 + Result = WideCharToMultiByte(CP_ACP, 0, input, -1, Buffer, BuffSize, NULL, NULL);
270 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
273 +static wchar_t *utf8_to_utf16(const char *input)
275 + wchar_t *Buffer;
276 + int BuffSize = 0, Result = 0;
278 + BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
279 + Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
280 + if(Buffer)
282 + Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
285 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
288 +void lsx_init_commandline_arguments(int *argc, char ***argv)
290 + int i, nArgs;
291 + LPWSTR *szArglist;
293 + szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
295 + if(NULL == szArglist)
297 + fprintf(stderr, "\nFATAL: CommandLineToArgvW failed\n\n");
298 + exit(-1);
301 + *argv = (char**) malloc(sizeof(char*) * nArgs);
302 + *argc = nArgs;
304 + if(NULL == *argv)
306 + fprintf(stderr, "\nFATAL: Malloc failed\n\n");
307 + exit(-1);
310 + for(i = 0; i < nArgs; i++)
312 + (*argv)[i] = utf16_to_utf8(szArglist[i]);
313 + if(NULL == (*argv)[i])
315 + fprintf(stderr, "\nFATAL: utf16_to_utf8 failed\n\n");
316 + exit(-1);
320 + LocalFree(szArglist);
323 +void lsx_free_commandline_arguments(int *argc, char ***argv)
325 + int i = 0;
327 + if(*argv != NULL)
329 + for(i = 0; i < *argc; i++)
331 + if((*argv)[i] != NULL)
333 + free((*argv)[i]);
334 + (*argv)[i] = NULL;
337 + free(*argv);
338 + *argv = NULL;
342 +FILE *lsx_fopen(const char *filename_utf8, const char *mode_utf8)
344 + FILE *ret = NULL;
345 + wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
346 + wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
348 + if(filename_utf16 && mode_utf16)
350 + FILE *fh = NULL;
351 + int err = _wfopen_s(&fh, filename_utf16, mode_utf16);
352 + if(err == 0) ret = fh;
355 + if(filename_utf16) free(filename_utf16);
356 + if(mode_utf16) free(mode_utf16);
358 + return ret;
361 +int lsx_stat(const char *path_utf8, struct _stat *buf)
363 + int ret = -1;
365 + wchar_t *path_utf16 = utf8_to_utf16(path_utf8);
366 + if(path_utf16)
368 + ret = _wstat(path_utf16, buf);
369 + free(path_utf16);
372 + return ret;
375 +int lsx_unlink(const char *path_utf8)
377 + int ret = -1;
379 + wchar_t *path_utf16 = utf8_to_utf16(path_utf8);
380 + if(path_utf16)
382 + ret = _wunlink(path_utf16);
383 + free(path_utf16);
386 + return ret;
389 +void lsx_init_console(void)
391 + g_old_output_cp = GetConsoleOutputCP();
392 + SetConsoleOutputCP(CP_UTF8);
395 +void lsx_uninit_console(void)
397 + if(g_old_output_cp != ((UINT)-1))
399 + SetConsoleOutputCP(g_old_output_cp);
403 +#endif
404 \ No newline at end of file
405 diff --git a/src/unicode_support.h b/src/unicode_support.h
406 new file mode 100644
407 index 0000000..6abd0b3
408 --- /dev/null
409 +++ b/src/unicode_support.h
410 @@ -0,0 +1,46 @@
411 +/* Copyright (c) 2004-2015 LoRd_MuldeR <mulder2@gmx.de>
412 + File: unicode_support.h
414 + This file was originally part of a patch included with LameXP,
415 + released under the same license as the original audio tools.
417 + Redistribution and use in source and binary forms, with or without
418 + modification, are permitted provided that the following conditions
419 + are met:
421 + - Redistributions of source code must retain the above copyright
422 + notice, this list of conditions and the following disclaimer.
424 + - Redistributions in binary form must reproduce the above copyright
425 + notice, this list of conditions and the following disclaimer in the
426 + documentation and/or other materials provided with the distribution.
428 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
429 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
430 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
431 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
432 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
433 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
434 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
435 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
436 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
437 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
438 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
440 +#ifndef UNICODE_SUPPORT_H_INCLUDED
441 +#define UNICODE_SUPPORT_H_INCLUDED
443 +#include <stdio.h>
444 +#include <sys/stat.h>
446 +#define WIN_UNICODE 1
448 +void lsx_init_commandline_arguments(int *argc, char ***argv);
449 +void lsx_free_commandline_arguments(int *argc, char ***argv);
450 +FILE *lsx_fopen(const char *filename_utf8, const char *mode_utf8);
451 +int lsx_stat(const char *path_utf8, struct _stat *buf);
452 +int lsx_unlink(const char *path_utf8);
453 +void lsx_init_console(void);
454 +void lsx_uninit_console(void);
456 +#endif
457 \ No newline at end of file