387afddafeb1b89a1a3aa5347e50d7661d1be04e
2 ** Copyright (C) 2009-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
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.
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.
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.
20 ** This needs to be a separate file so that we don't have to include
21 ** <windows.h> elsewhere (too many symbol clashes).
30 #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
36 static void copy_filename (SF_PRIVATE
* psf
, LPCWSTR wpath
) ;
39 sf_wchar_open (LPCWSTR wpath
, int mode
, SF_INFO
*sfinfo
)
43 if ((psf
= calloc (1, sizeof (SF_PRIVATE
))) == NULL
)
44 { sf_errno
= SFE_MALLOC_FAILED
;
48 memset (psf
, 0, sizeof (SF_PRIVATE
)) ;
49 psf_init_files (psf
) ;
51 if (WideCharToMultiByte (CP_UTF8
, 0, wpath
, -1, utf8name
, sizeof (utf8name
), NULL
, NULL
) == 0)
52 psf
->file
.path
.wc
[0] = 0 ;
54 psf_log_printf (psf
, "File : '%s' (utf-8 converted from ucs-2)\n", utf8name
) ;
56 copy_filename (psf
, wpath
) ;
57 psf
->file
.use_wchar
= SF_TRUE
;
58 psf
->file
.mode
= mode
;
60 psf
->error
= psf_fopen (psf
) ;
62 return psf_open_file (psf
, sfinfo
) ;
67 copy_filename (SF_PRIVATE
*psf
, LPCWSTR wpath
)
68 { const wchar_t *cwcptr
;
71 wcsncpy (psf
->file
.path
.wc
, wpath
, ARRAY_LEN (psf
->file
.path
.wc
)) ;
72 psf
->file
.path
.wc
[ARRAY_LEN (psf
->file
.path
.wc
) - 1] = 0 ;
73 if ((cwcptr
= wcsrchr (wpath
, '/')) || (cwcptr
= wcsrchr (wpath
, '\\')))
78 wcsncpy (psf
->file
.name
.wc
, cwcptr
, ARRAY_LEN (psf
->file
.name
.wc
)) ;
79 psf
->file
.name
.wc
[ARRAY_LEN (psf
->file
.name
.wc
) - 1] = 0 ;
81 /* Now grab the directory. */
82 wcsncpy (psf
->file
.dir
.wc
, wpath
, ARRAY_LEN (psf
->file
.dir
.wc
)) ;
83 psf
->file
.dir
.wc
[ARRAY_LEN (psf
->file
.dir
.wc
) - 1] = 0 ;
85 if ((wcptr
= wcsrchr (psf
->file
.dir
.wc
, '/')) || (wcptr
= wcsrchr (psf
->file
.dir
.wc
, '\\')))
88 psf
->file
.dir
.wc
[0] = 0 ;