1b815c7f3Sopenharmony_ci/* 2b815c7f3Sopenharmony_ci** Copyright (C) 2006-2017 Erik de Castro Lopo <erikd@mega-nerd.com> 3b815c7f3Sopenharmony_ci** 4b815c7f3Sopenharmony_ci** This program is free software; you can redistribute it and/or modify 5b815c7f3Sopenharmony_ci** it under the terms of the GNU General Public License as published by 6b815c7f3Sopenharmony_ci** the Free Software Foundation; either version 2 of the License, or 7b815c7f3Sopenharmony_ci** (at your option) any later version. 8b815c7f3Sopenharmony_ci** 9b815c7f3Sopenharmony_ci** This program is distributed in the hope that it will be useful, 10b815c7f3Sopenharmony_ci** but WITHOUT ANY WARRANTY; without even the implied warranty of 11b815c7f3Sopenharmony_ci** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12b815c7f3Sopenharmony_ci** GNU General Public License for more details. 13b815c7f3Sopenharmony_ci** 14b815c7f3Sopenharmony_ci** You should have received a copy of the GNU General Public License 15b815c7f3Sopenharmony_ci** along with this program; if not, write to the Free Software 16b815c7f3Sopenharmony_ci** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17b815c7f3Sopenharmony_ci*/ 18b815c7f3Sopenharmony_ci 19b815c7f3Sopenharmony_ci#include "sfconfig.h" 20b815c7f3Sopenharmony_ci 21b815c7f3Sopenharmony_ci#include <stdio.h> 22b815c7f3Sopenharmony_ci#include <stdlib.h> 23b815c7f3Sopenharmony_ci 24b815c7f3Sopenharmony_ci#if HAVE_UNISTD_H 25b815c7f3Sopenharmony_ci#include <unistd.h> 26b815c7f3Sopenharmony_ci#endif 27b815c7f3Sopenharmony_ci 28b815c7f3Sopenharmony_ci#if (HAVE_DECL_S_IRGRP == 0) 29b815c7f3Sopenharmony_ci#include <sf_unistd.h> 30b815c7f3Sopenharmony_ci#endif 31b815c7f3Sopenharmony_ci 32b815c7f3Sopenharmony_ci#include <string.h> 33b815c7f3Sopenharmony_ci#include <fcntl.h> 34b815c7f3Sopenharmony_ci#ifdef HAVE_DIRECT_H 35b815c7f3Sopenharmony_ci#include <direct.h> 36b815c7f3Sopenharmony_ci#endif 37b815c7f3Sopenharmony_ci#include <sys/types.h> 38b815c7f3Sopenharmony_ci 39b815c7f3Sopenharmony_ci#include "utils.h" 40b815c7f3Sopenharmony_ci 41b815c7f3Sopenharmony_ci#if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__)) 42b815c7f3Sopenharmony_ci#define TEST_WIN32 1 43b815c7f3Sopenharmony_ci#else 44b815c7f3Sopenharmony_ci#define TEST_WIN32 0 45b815c7f3Sopenharmony_ci#endif 46b815c7f3Sopenharmony_ci 47b815c7f3Sopenharmony_ci#if TEST_WIN32 48b815c7f3Sopenharmony_ci#include <windows.h> 49b815c7f3Sopenharmony_ci 50b815c7f3Sopenharmony_ci 51b815c7f3Sopenharmony_cistatic const char * locations [] = 52b815c7f3Sopenharmony_ci{ ".", "../src/", "src/", "../src/.libs/", "src/.libs/", 53b815c7f3Sopenharmony_ci NULL 54b815c7f3Sopenharmony_ci} ; /* locations. */ 55b815c7f3Sopenharmony_ci 56b815c7f3Sopenharmony_cistatic int 57b815c7f3Sopenharmony_citest_ordinal (HMODULE hmod, const char * func_name, int ordinal) 58b815c7f3Sopenharmony_ci{ char *lpmsg ; 59b815c7f3Sopenharmony_ci void *name, *ord ; 60b815c7f3Sopenharmony_ci 61b815c7f3Sopenharmony_ci print_test_name ("win32_ordinal_test", func_name) ; 62b815c7f3Sopenharmony_ci 63b815c7f3Sopenharmony_ci#if SIZEOF_VOIDP == 8 64b815c7f3Sopenharmony_ci#define LPCSTR_OF_ORDINAL(x) ((LPCSTR) ((int64_t) (x))) 65b815c7f3Sopenharmony_ci#else 66b815c7f3Sopenharmony_ci#define LPCSTR_OF_ORDINAL(x) ((LPCSTR) (x)) 67b815c7f3Sopenharmony_ci#endif 68b815c7f3Sopenharmony_ci 69b815c7f3Sopenharmony_ci ord = GetProcAddress (hmod, LPCSTR_OF_ORDINAL (ordinal)) ; 70b815c7f3Sopenharmony_ci if ((name = GetProcAddress (hmod, func_name)) == NULL) 71b815c7f3Sopenharmony_ci { FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (), 72b815c7f3Sopenharmony_ci MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpmsg, 0, NULL) ; 73b815c7f3Sopenharmony_ci /*-puts (lpmsg) ;-*/ 74b815c7f3Sopenharmony_ci } ; 75b815c7f3Sopenharmony_ci 76b815c7f3Sopenharmony_ci if (name != NULL && ord != NULL && name == ord) 77b815c7f3Sopenharmony_ci { puts ("ok") ; 78b815c7f3Sopenharmony_ci return 0 ; 79b815c7f3Sopenharmony_ci } ; 80b815c7f3Sopenharmony_ci 81b815c7f3Sopenharmony_ci puts ("fail") ; 82b815c7f3Sopenharmony_ci return 1 ; 83b815c7f3Sopenharmony_ci} /* test_ordinal */ 84b815c7f3Sopenharmony_ci 85b815c7f3Sopenharmony_cistatic void 86b815c7f3Sopenharmony_ciwin32_ordinal_test (void) 87b815c7f3Sopenharmony_ci{ static char buffer [1024] ; 88b815c7f3Sopenharmony_ci static char func_name [1024] ; 89b815c7f3Sopenharmony_ci HMODULE hmod = NULL ; 90b815c7f3Sopenharmony_ci FILE * file = NULL ; 91b815c7f3Sopenharmony_ci int k, ordinal, errors = 0 ; 92b815c7f3Sopenharmony_ci 93b815c7f3Sopenharmony_ci for (k = 0 ; locations [k] != NULL ; k++) 94b815c7f3Sopenharmony_ci { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.def", locations [k]) ; 95b815c7f3Sopenharmony_ci if ((file = fopen (buffer, "r")) != NULL) 96b815c7f3Sopenharmony_ci break ; 97b815c7f3Sopenharmony_ci } ; 98b815c7f3Sopenharmony_ci 99b815c7f3Sopenharmony_ci if (file == NULL) 100b815c7f3Sopenharmony_ci { puts ("\n\nError : cannot open DEF file.\n") ; 101b815c7f3Sopenharmony_ci exit (1) ; 102b815c7f3Sopenharmony_ci } ; 103b815c7f3Sopenharmony_ci 104b815c7f3Sopenharmony_ci for (k = 0 ; locations [k] != NULL ; k++) 105b815c7f3Sopenharmony_ci { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.dll", locations [k]) ; 106b815c7f3Sopenharmony_ci if ((hmod = (HMODULE) LoadLibrary (buffer)) != NULL) 107b815c7f3Sopenharmony_ci break ; 108b815c7f3Sopenharmony_ci } ; 109b815c7f3Sopenharmony_ci 110b815c7f3Sopenharmony_ci if (hmod == NULL) 111b815c7f3Sopenharmony_ci { printf ("\n\nError : cannot load DLL (cwd is %s).\n", getcwd (buffer, sizeof (buffer))) ; 112b815c7f3Sopenharmony_ci exit (1) ; 113b815c7f3Sopenharmony_ci } ; 114b815c7f3Sopenharmony_ci 115b815c7f3Sopenharmony_ci while (fgets (buffer, sizeof (buffer), file) != NULL) 116b815c7f3Sopenharmony_ci { func_name [0] = 0 ; 117b815c7f3Sopenharmony_ci ordinal = 0 ; 118b815c7f3Sopenharmony_ci 119b815c7f3Sopenharmony_ci if (sscanf (buffer, "%s @%d", func_name, &ordinal) != 2) 120b815c7f3Sopenharmony_ci continue ; 121b815c7f3Sopenharmony_ci 122b815c7f3Sopenharmony_ci errors += test_ordinal (hmod, func_name, ordinal) ; 123b815c7f3Sopenharmony_ci } ; 124b815c7f3Sopenharmony_ci 125b815c7f3Sopenharmony_ci FreeLibrary (hmod) ; 126b815c7f3Sopenharmony_ci 127b815c7f3Sopenharmony_ci fclose (file) ; 128b815c7f3Sopenharmony_ci 129b815c7f3Sopenharmony_ci if (errors > 0) 130b815c7f3Sopenharmony_ci { printf ("\n\nErrors : %d\n\n", errors) ; 131b815c7f3Sopenharmony_ci exit (1) ; 132b815c7f3Sopenharmony_ci } ; 133b815c7f3Sopenharmony_ci 134b815c7f3Sopenharmony_ci return ; 135b815c7f3Sopenharmony_ci} /* win32_ordinal_test */ 136b815c7f3Sopenharmony_ci 137b815c7f3Sopenharmony_ci#endif 138b815c7f3Sopenharmony_ci 139b815c7f3Sopenharmony_ciint 140b815c7f3Sopenharmony_cimain (void) 141b815c7f3Sopenharmony_ci{ 142b815c7f3Sopenharmony_ci#if (TEST_WIN32 && WIN32_TARGET_DLL) 143b815c7f3Sopenharmony_ci win32_ordinal_test () ; 144b815c7f3Sopenharmony_ci#endif 145b815c7f3Sopenharmony_ci 146b815c7f3Sopenharmony_ci return 0 ; 147b815c7f3Sopenharmony_ci} /* main */ 148b815c7f3Sopenharmony_ci 149