1 /*
2 TiMidity++ -- MIDI to WAVE converter and player
3 Copyright (C) 1999-2001 Masanao Izumo <mo@goice.co.jp>
4 Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif /* HAVE_CONFIG_H */
24 /*
25 dl_dyld.c
26 To use dyld in Mac OS X / Darwin system
27 by Urabe Shyouhei<mput@mac.com>
28 */
29 #include <stdio.h>
30 #include <mach-o/dyld.h>
31 #include <unistd.h>
32 #include "timidity.h"
33 #include "dlutils.h"
34
dl_init(int argc,char ** argv)35 void dl_init(int argc,char** argv)
36 {
37 // do nothing.
38 }
39
dl_load_file(char * path)40 void* dl_load_file(char* path)
41 {
42 NSObjectFileImage obj_file; /* file handler */
43
44 if (NSCreateObjectFileImageFromFile(path, &obj_file) != NSObjectFileImageSuccess) {
45 fprintf(stderr,"dl_load_file:Failed to load %.200s\n", path);
46 }
47 return NSLinkModule(obj_file,path,TRUE);
48 }
49
dl_find_symbol(void * libhandle,char * symbol)50 void* dl_find_symbol(void* libhandle, char* symbol)
51 {
52
53 /* avoid a bug of how to treat '_'. */
54 size_t len = strlen(symbol);
55 char buf[len+2]; /* +2 for '_' and '\0' */
56 sprintf(buf,"_%s",symbol);
57
58 if(!NSIsSymbolNameDefined(buf)) {
59 fprintf(stderr,"dl_find_symbol:Failed to find %.200s\n",symbol);
60 return NULL;
61 }
62 else {
63 return NSAddressOfSymbol(NSLookupAndBindSymbol(buf));
64 }
65 }
66
dl_free(void * libhandle)67 void dl_free(void *libhandle)
68 {
69 NSUnLinkModule(libhandle, 0);
70 }
71