• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /* this file is used to test that we can use libesd with lazy dynamic linking */
17 
18 #include <esd.h>
19 #include <dlfcn.h>
20 #include <stdio.h>
21 
22 #define  D(...)  fprintf(stderr,__VA_ARGS__)
23 #define  STRINGIFY(x)  _STRINGIFY(x)
24 #define _STRINGIFY(x)  #x
25 
26 #define  ESD_SYMBOLS   \
27     ESD_FUNCTION(int,esd_play_stream,(esd_format_t,int,const char*,const char*))   \
28     ESD_FUNCTION(int,esd_record_stream,(esd_format_t,int,const char*,const char*)) \
29     ESD_FUNCTION(int,esd_open_sound,( const char *host )) \
30     ESD_FUNCTION(int,esd_close,(int)) \
31 
32 /* define pointers to library functions we're going to use */
33 #define  ESD_FUNCTION(ret,name,sig)   \
34     static ret  (*func_ ## name)sig;
35 
36 ESD_SYMBOLS
37 
38 #undef  ESD_FUNCTION
39 static void*    esd_lib;
40 
main(void)41 int main( void )
42 {
43     int  fd;
44 
45     esd_lib = dlopen( "libesd.so", RTLD_NOW );
46     if (esd_lib == NULL)
47         esd_lib = dlopen( "libesd.so.0", RTLD_NOW );
48 
49     if (esd_lib == NULL) {
50         D("could not find libesd on this system\n");
51         return 1;
52     }
53 
54 #undef  ESD_FUNCTION
55 #define ESD_FUNCTION(ret,name,sig)                                               \
56     do {                                                                         \
57         (func_ ##name) = dlsym( esd_lib, STRINGIFY(name) );                      \
58         if ((func_##name) == NULL) {                                             \
59             D("could not find %s in libesd\n", STRINGIFY(name));   \
60             return 1;                                               \
61         }                                                                        \
62     } while (0);
63 
64     ESD_SYMBOLS
65 
66     return 0;
67 }
68