Skip to content

Commit fe73a74

Browse files
committed
More macOS porting, copied from wowcube.
1 parent 8ab13b8 commit fe73a74

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

amx/amx.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
#include <sys/types.h>
4343
#include <sys/mman.h>
4444
#endif
45+
#if defined __APPLE__
46+
#include <zconf.h>
47+
#include <errno.h>
48+
#include <libproc.h>
49+
#endif
4550
#endif
4651
#if !defined AMX_ANSIONLY && (defined __LCC__ || defined __LINUX__ || defined __APPLE__)
4752
#include <wchar.h> /* for wcslen() */
@@ -610,7 +615,7 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, const cell *params)
610615
#if defined AMX_NO_PACKED_OPC
611616
#define GETOPCODE(c) (OPCODE)(c)
612617
#else
613-
#define GETOPCODE(c) (OPCODE)((c) & ((1L << sizeof(cell)*4)-1))
618+
#define GETOPCODE(c) (OPCODE)((c) & ((1UL << sizeof(cell)*4)-1))
614619
#endif
615620
#endif
616621
#if !defined GETPARAM_P
@@ -1120,8 +1125,10 @@ static int VerifyPcode(AMX *amx)
11201125
strcat(libname,source);
11211126
#if defined _Windows
11221127
strcat(libname,".dll");
1123-
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
1128+
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
11241129
strcat(libname,".so");
1130+
#elif defined __APPLE__
1131+
strcat(libname,".dylib");
11251132
#endif
11261133
}
11271134
#endif
@@ -1320,8 +1327,25 @@ int AMXAPI amx_Init(AMX *amx,void *program)
13201327
if (hlib<=HINSTANCE_ERROR)
13211328
hlib=NULL;
13221329
#endif
1323-
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
1330+
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
13241331
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+
}
13251349
#endif
13261350
if (hlib!=NULL) {
13271351
/* a library that cannot be loaded or that does not have the required

0 commit comments

Comments
 (0)