A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 179 lines 4.1 kB view raw
1/* Copyright (c) 1997-1999 Miller Puckette. 2* For information on usage and redistribution, and for a DISCLAIMER OF ALL 3* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ 4 5#ifdef ROCKBOX 6#include "plugin.h" 7#include "../../pdbox.h" 8#else /* ROCKBOX */ 9#ifdef DL_OPEN 10#include <dlfcn.h> 11#endif 12#ifdef UNIX 13#include <stdlib.h> 14#include <unistd.h> 15#endif 16#ifdef MSW 17#include <io.h> 18#include <windows.h> 19#endif 20#ifdef MACOSX 21#include <mach-o/dyld.h> 22#endif 23#include <string.h> 24#include <stdio.h> 25#endif /* ROCKBOX */ 26#include "m_pd.h" 27#include "s_stuff.h" 28 29typedef void (*t_xxx)(void); 30 31#ifndef ROCKBOX 32static char sys_dllextent[] = 33#ifdef __FreeBSD__ 34 ".pd_freebsd"; 35#endif 36#ifdef IRIX 37#ifdef N32 38 ".pd_irix6"; 39#else 40 ".pd_irix5"; 41#endif 42#endif 43#ifdef __linux__ 44 ".pd_linux"; 45#endif 46#ifdef MACOSX 47 ".pd_darwin"; 48#endif 49#ifdef MSW 50 ".dll"; 51#endif 52#endif /* ROCKBOX */ 53 54void class_set_extern_dir(t_symbol *s); 55 56#ifdef STATIC 57int sys_load_lib(char *dirname, char *classname) 58#ifdef ROCKBOX 59{ 60 (void) dirname; 61 (void) classname; 62 63 return 0; 64} 65#else /* ROCKBOX */ 66{ return 0;} 67#endif /* ROCKBOX */ 68#else 69int sys_load_lib(char *dirname, char *classname) 70{ 71 char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], 72 classname2[MAXPDSTRING], *nameptr, *lastdot; 73 void *dlobj; 74 t_xxx makeout = NULL; 75 int fd; 76#ifdef MSW 77 HINSTANCE ntdll; 78#endif 79#if 0 80 fprintf(stderr, "lib %s %s\n", dirname, classname); 81#endif 82 /* try looking in the path for (classname).(sys_dllextent) ... */ 83 if ((fd = open_via_path(dirname, classname, sys_dllextent, 84 dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) 85 { 86 /* next try (classname)/(classname).(sys_dllextent) ... */ 87 strncpy(classname2, classname, MAXPDSTRING); 88 filename[MAXPDSTRING-2] = 0; 89 strcat(classname2, "/"); 90 strncat(classname2, classname, MAXPDSTRING-strlen(classname2)); 91 filename[MAXPDSTRING-1] = 0; 92 if ((fd = open_via_path(dirname, classname2, sys_dllextent, 93 dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) 94 { 95 return (0); 96 } 97 } 98 99 100 close(fd); 101 class_set_extern_dir(gensym(dirbuf)); 102 103 /* refabricate the pathname */ 104 strncpy(filename, dirbuf, MAXPDSTRING); 105 filename[MAXPDSTRING-2] = 0; 106 strcat(filename, "/"); 107 strncat(filename, nameptr, MAXPDSTRING-strlen(filename)); 108 filename[MAXPDSTRING-1] = 0; 109 /* extract the setup function name */ 110 if (lastdot = strrchr(nameptr, '.')) 111 *lastdot = 0; 112 113#ifdef MACOSX 114 strcpy(symname, "_"); 115 strcat(symname, nameptr); 116#else 117 strcpy(symname, nameptr); 118#endif 119 /* if the last character is a tilde, replace with "_tilde" */ 120 if (symname[strlen(symname) - 1] == '~') 121 strcpy(symname + (strlen(symname) - 1), "_tilde"); 122 /* and append _setup to form the C setup function name */ 123 strcat(symname, "_setup"); 124#ifdef DL_OPEN 125 dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL); 126 if (!dlobj) 127 { 128 post("%s: %s", filename, dlerror()); 129 class_set_extern_dir(&s_); 130 return (0); 131 } 132 makeout = (t_xxx)dlsym(dlobj, symname); 133#endif 134#ifdef MSW 135 sys_bashfilename(filename, filename); 136 ntdll = LoadLibrary(filename); 137 if (!ntdll) 138 { 139 post("%s: couldn't load", filename); 140 class_set_extern_dir(&s_); 141 return (0); 142 } 143 makeout = (t_xxx)GetProcAddress(ntdll, symname); 144#endif 145#ifdef MACOSX 146 { 147 NSObjectFileImage image; 148 void *ret; 149 NSSymbol s; 150 if ( NSCreateObjectFileImageFromFile( filename, &image) != NSObjectFileImageSuccess ) 151 { 152 post("%s: couldn't load", filename); 153 class_set_extern_dir(&s_); 154 return 0; 155 } 156 ret = NSLinkModule( image, filename, 157 NSLINKMODULE_OPTION_BINDNOW + NSLINKMODULE_OPTION_PRIVATE); 158 159 s = NSLookupSymbolInModule(ret, symname); 160 161 if (s) 162 makeout = (t_xxx)NSAddressOfSymbol( s); 163 else makeout = 0; 164 } 165#endif 166 167 if (!makeout) 168 { 169 post("load_object: Symbol \"%s\" not found", symname); 170 class_set_extern_dir(&s_); 171 return 0; 172 } 173 (*makeout)(); 174 class_set_extern_dir(&s_); 175 return (1); 176} 177 178#endif 179