|
42 | 42 | #include <sys/types.h>
|
43 | 43 | #include <sys/mman.h>
|
44 | 44 | #endif
|
| 45 | + #if defined __APPLE__ |
| 46 | + #include <zconf.h> |
| 47 | + #include <errno.h> |
| 48 | + #include <libproc.h> |
| 49 | + #endif |
45 | 50 | #endif
|
46 | 51 | #if !defined AMX_ANSIONLY && (defined __LCC__ || defined __LINUX__ || defined __APPLE__)
|
47 | 52 | #include <wchar.h> /* for wcslen() */
|
@@ -610,7 +615,7 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, const cell *params)
|
610 | 615 | #if defined AMX_NO_PACKED_OPC
|
611 | 616 | #define GETOPCODE(c) (OPCODE)(c)
|
612 | 617 | #else
|
613 |
| - #define GETOPCODE(c) (OPCODE)((c) & ((1L << sizeof(cell)*4)-1)) |
| 618 | + #define GETOPCODE(c) (OPCODE)((c) & ((1UL << sizeof(cell)*4)-1)) |
614 | 619 | #endif
|
615 | 620 | #endif
|
616 | 621 | #if !defined GETPARAM_P
|
@@ -1120,8 +1125,10 @@ static int VerifyPcode(AMX *amx)
|
1120 | 1125 | strcat(libname,source);
|
1121 | 1126 | #if defined _Windows
|
1122 | 1127 | strcat(libname,".dll");
|
1123 |
| - #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ |
| 1128 | + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ |
1124 | 1129 | strcat(libname,".so");
|
| 1130 | + #elif defined __APPLE__ |
| 1131 | + strcat(libname,".dylib"); |
1125 | 1132 | #endif
|
1126 | 1133 | }
|
1127 | 1134 | #endif
|
@@ -1320,8 +1327,25 @@ int AMXAPI amx_Init(AMX *amx,void *program)
|
1320 | 1327 | if (hlib<=HINSTANCE_ERROR)
|
1321 | 1328 | hlib=NULL;
|
1322 | 1329 | #endif
|
1323 |
| - #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ |
| 1330 | + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ |
1324 | 1331 | hlib=dlopen(libname,RTLD_NOW);
|
| 1332 | + #elif defined __APPLE__ |
| 1333 | + /* try to search library in pidpath */ |
| 1334 | + char pathbuf[PROC_PIDPATHINFO_MAXSIZE]; |
| 1335 | + int ret=proc_pidpath(getpid(), pathbuf, sizeof(pathbuf)); |
| 1336 | + if (ret>0) { |
| 1337 | + char ptr=strrchr(pathbuf,'/'); |
| 1338 | + assert(ptr!=NULL); |
| 1339 | + *ptr='\0'; |
| 1340 | + asprintf(&ptr,"%s/%s",pathbuf,libname); |
| 1341 | + assert(ptr!=NULL); |
| 1342 | + hlib=dlopen(ptr,RTLD_NOW); |
| 1343 | + free(ptr); |
| 1344 | + } |
| 1345 | + if (hlib==NULL) { |
| 1346 | + /* if failed, try to search elsewhere */ |
| 1347 | + hlib=dlopen(libname,RTLD_NOW); |
| 1348 | + } |
1325 | 1349 | #endif
|
1326 | 1350 | if (hlib!=NULL) {
|
1327 | 1351 | /* a library that cannot be loaded or that does not have the required
|
|
0 commit comments