xref: /third_party/libsnd/src/windows.c (revision b815c7f3)
1/*
2** Copyright (C) 2009-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
3**
4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU Lesser General Public License as published by
6** the Free Software Foundation; either version 2.1 of the License, or
7** (at your option) any later version.
8**
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 Lesser General Public License for more details.
13**
14** You should have received a copy of the GNU Lesser General Public License
15** along with this program; if not, write to the Free Software
16** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19/*
20**	This needs to be a separate file so that we don't have to include
21**	<windows.h> elsewhere (too many symbol clashes).
22*/
23
24
25#include "sfconfig.h"
26
27#if OS_IS_WIN32
28#include <windows.h>
29
30#include "sndfile.h"
31#include "common.h"
32
33extern int sf_errno ;
34
35SNDFILE*
36sf_wchar_open (LPCWSTR wpath, int mode, SF_INFO *sfinfo)
37{	SF_PRIVATE 	*psf ;
38	char utf8name [SF_BUFFER_LEN] ;
39	DWORD dwError ;
40
41	if ((psf = psf_allocate ()) == NULL)
42	{	sf_errno = SFE_MALLOC_FAILED ;
43		return	NULL ;
44		} ;
45
46	psf_init_files (psf) ;
47
48	if (WideCharToMultiByte (CP_UTF8, 0, wpath, -1, utf8name, sizeof (utf8name), NULL, NULL) == 0)
49	{	dwError = GetLastError () ;
50		if (dwError == ERROR_INSUFFICIENT_BUFFER)
51			sf_errno = SFE_FILENAME_TOO_LONG ;
52		else
53			sf_errno = SF_ERR_UNSUPPORTED_ENCODING ;
54
55		sf_close (psf) ;
56
57		return NULL ;
58		} ;
59
60	psf_log_printf (psf, "File : '%s' (utf-8 converted from ucs-2)\n", utf8name) ;
61
62	psf_copy_filename (psf, utf8name) ;
63	psf->file.mode = mode ;
64
65	psf->error = psf_fopen (psf) ;
66
67	return psf_open_file (psf, sfinfo) ;
68} /* sf_wchar_open */
69
70#endif
71