muxer: Don't duplicate sample entries.
[L-SMASH.git] / common / osdep.c
blobcfd5caccaa10c6aa78800d4916bc15e3080c773a
1 /*****************************************************************************
2 * osdep.c
3 *****************************************************************************
4 * Copyright (C) 2013-2017 L-SMASH project
6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *****************************************************************************/
21 /* This file is available under an ISC license. */
23 #include "internal.h" /* must be placed first */
25 #include <stdlib.h>
27 #ifdef _WIN32
28 #include <windows.h>
29 #endif
31 #ifdef _WIN32
33 int lsmash_string_to_wchar( int cp, const char *from, wchar_t **to )
35 int nc = MultiByteToWideChar( cp, 0, from, -1, 0, 0 );
36 if( nc == 0 )
37 return 0;
38 *to = lsmash_malloc( nc * sizeof(wchar_t) );
39 MultiByteToWideChar( cp, 0, from, -1, *to, nc );
40 return nc;
43 int lsmash_string_from_wchar( int cp, const wchar_t *from, char **to )
45 int nc = WideCharToMultiByte( cp, 0, from, -1, 0, 0, 0, 0 );
46 if( nc == 0 )
47 return 0;
48 *to = lsmash_malloc( nc * sizeof(char) );
49 WideCharToMultiByte( cp, 0, from, -1, *to, nc, 0, 0 );
50 return nc;
53 FILE *lsmash_win32_fopen( const char *name, const char *mode )
55 wchar_t *wname = NULL, *wmode = NULL;
56 lsmash_string_to_wchar( CP_UTF8, name, &wname );
57 lsmash_string_to_wchar( CP_UTF8, mode, &wmode );
58 FILE *fp = _wfopen( wname, wmode );
59 if( !fp )
60 fp = fopen( name, mode );
61 lsmash_free( wname );
62 lsmash_free( wmode );
63 return fp;
66 #endif