SNDFILE* sf_wchar_open (LPCWSTR wpath, int mode, SF_INFO *sfinfo) { SF_PRIVATE *psf ; char utf8name [512] ; if ((psf = psf_allocate ()) == NULL) { sf_errno = SFE_MALLOC_FAILED ; return NULL ; } ; psf_init_files (psf) ; if (WideCharToMultiByte (CP_UTF8, 0, wpath, -1, utf8name, sizeof (utf8name), NULL, NULL) == 0) psf->file.path.wc [0] = 0 ; psf_log_printf (psf, "File : '%s' (utf-8 converted from ucs-2)\n", utf8name) ; copy_filename (psf, wpath) ; psf->file.use_wchar = SF_TRUE ; psf->file.mode = mode ; psf->error = psf_fopen (psf) ; return psf_open_file (psf, sfinfo) ; } /* sf_wchar_open */
static void test_open_or_die (SF_PRIVATE *psf, int linenum) { int error ; /* Test that open for read fails if the file doesn't exist. */ error = psf_fopen (psf, psf->filename, psf->mode) ; if (error) { printf ("\n\nLine %d: psf_fopen() failed : %s\n\n", linenum, strerror (errno)) ; exit (1) ; } ; } /* test_open_or_die */
static void file_open_test (const char *filename) { SF_PRIVATE sf_data, *psf ; int error ; printf (" %-24s : ", "file_open_test") ; fflush (stdout) ; memset (&sf_data, 0, sizeof (sf_data)) ; psf = &sf_data ; /* Ensure that the file doesn't already exist. */ if (unlink (filename) != 0 && errno != ENOENT) { printf ("\n\nLine %d: unlink failed (%d) : %s\n\n", __LINE__, errno, strerror (errno)) ; exit (1) ; } ; strncpy (psf->filename, filename, sizeof (psf->filename)) ; /* Test that open for read fails if the file doesn't exist. */ error = psf_fopen (psf, psf->filename, SFM_READ) ; if (error == 0) { printf ("\n\nLine %d: psf_fopen() should have failed.\n\n", __LINE__) ; exit (1) ; } ; /* Reset error to zero. */ psf->error = SFE_NO_ERROR ; /* Test file open in write mode. */ psf->mode = SFM_WRITE ; test_open_or_die (psf, __LINE__) ; test_close_or_die (psf, __LINE__) ; unlink (psf->filename) ; /* Test file open in read/write mode for a non-existant file. */ psf->mode = SFM_RDWR ; test_open_or_die (psf, __LINE__) ; test_close_or_die (psf, __LINE__) ; /* Test file open in read/write mode for an existing file. */ psf->mode = SFM_RDWR ; test_open_or_die (psf, __LINE__) ; test_close_or_die (psf, __LINE__) ; unlink (psf->filename) ; puts ("ok") ; } /* file_open_test */