Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions amx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

SET(dl dl)
IF(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
SET(dl "")
ENDIF()

# check for optional include files
INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
Expand Down Expand Up @@ -211,7 +216,7 @@ IF(APPLE) #Export list is set at link time
SET_PROPERTY(TARGET amxProcess APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-exported_symbol,_amx_ProcessCleanup ")
ENDIF(APPLE)
IF(UNIX AND NOT APPLE)
TARGET_LINK_LIBRARIES(amxProcess dl)
TARGET_LINK_LIBRARIES(amxProcess ${dl})
ADD_CUSTOM_COMMAND(TARGET amxProcess POST_BUILD COMMAND strip ARGS -K amx_ProcessInit -K amx_ProcessCleanup ${CMAKE_BINARY_DIR}/amxProcess.so)
ENDIF(UNIX AND NOT APPLE)
INSTALL(TARGETS amxProcess LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand Down Expand Up @@ -283,9 +288,9 @@ SET_TARGET_PROPERTIES(pawnrun PROPERTIES COMPILE_FLAGS -DAMXDBG COMPILE_FLAGS -D
IF (UNIX)
IF(HAVE_CURSES_H)
# SET_TARGET_PROPERTIES(pawnrun PROPERTIES COMPILE_FLAGS -DUSE_CURSES)
TARGET_LINK_LIBRARIES(pawnrun dl curses)
TARGET_LINK_LIBRARIES(pawnrun ${dl} curses)
ELSE(HAVE_CURSES_H)
TARGET_LINK_LIBRARIES(pawnrun dl)
TARGET_LINK_LIBRARIES(pawnrun ${dl})
ENDIF(HAVE_CURSES_H)
ENDIF (UNIX)
INSTALL(TARGETS pawnrun RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand All @@ -305,9 +310,9 @@ SET_TARGET_PROPERTIES(pawndbg PROPERTIES COMPILE_FLAGS -DENABLE_BINRELOC)
IF (UNIX)
IF(HAVE_CURSES_H)
# SET_TARGET_PROPERTIES(pawndbg PROPERTIES COMPILE_FLAGS -DUSE_CURSES)
TARGET_LINK_LIBRARIES(pawndbg dl curses)
TARGET_LINK_LIBRARIES(pawndbg ${dl} curses)
ELSE(HAVE_CURSES_H)
TARGET_LINK_LIBRARIES(pawndbg dl)
TARGET_LINK_LIBRARIES(pawndbg ${dl})
ENDIF(HAVE_CURSES_H)
ENDIF (UNIX)
INSTALL(TARGETS pawndbg RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down Expand Up @@ -342,7 +347,7 @@ INSTALL(TARGETS amx LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

CONFIGURE_FILE(amx.pc.in amx.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/amx.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
DESTINATION lib/pkgconfig)

# --------------------------------------------------------------------------
# Headers
Expand Down
40 changes: 20 additions & 20 deletions amx/amx.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <stdlib.h> /* for getenv() */
#include <string.h>
#include "osdefs.h"
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
#include <sclinux.h>
#if !defined AMX_NODYNALOAD
#include <dlfcn.h>
Expand All @@ -48,7 +48,7 @@
#include <libproc.h>
#endif
#endif
#if !defined AMX_ANSIONLY && (defined __LCC__ || defined __LINUX__ || defined __APPLE__)
#if !defined AMX_ANSIONLY && (defined __LCC__ || defined __LINUX__ || defined __APPLE__ || defined(__NetBSD__))
#include <wchar.h> /* for wcslen() */
#endif

Expand Down Expand Up @@ -620,7 +620,7 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, const cell *params)
#if defined AMX_NO_PACKED_OPC
#define GETOPCODE(c) (OPCODE)(c)
#else
#define GETOPCODE(c) (OPCODE)((c) & ((1UL << sizeof(cell)*4)-1))
#define GETOPCODE(c) (OPCODE)((c) & (((ucell)1 << sizeof(cell)*4)-1))
#endif
#endif
#if !defined GETPARAM_P
Expand Down Expand Up @@ -666,7 +666,7 @@ static int VerifyPcode(AMX *amx)
#if defined AMX_NO_PACKED_OPC
opmask= ~0;
#else
opmask=(1UL << sizeof(cell)*4)-1;
opmask=((ucell)1 << sizeof(cell)*4)-1;
#endif

/* sanity checks */
Expand Down Expand Up @@ -1108,18 +1108,18 @@ static int VerifyPcode(AMX *amx)
}

/* definitions used for amx_Init() and amx_Cleanup() */
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__) && !defined AMX_NODYNALOAD
typedef int AMXEXPORT (AMXAPI _FAR *AMX_ENTRY)(AMX _FAR *amx);

static void getlibname(char *libname,const char *source)
{
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
char *root=getenv("AMXLIB");
#endif

assert(libname!=NULL && source!=NULL);
libname[0]='\0';
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
if (root!=NULL && *root!='\0') {
strcpy(libname,root);
if (libname[strlen(libname)-1]!='/')
Expand All @@ -1130,7 +1130,7 @@ static int VerifyPcode(AMX *amx)
strcat(libname,source);
#if defined _Windows
strcat(libname,".dll");
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
strcat(libname,".so");
#elif defined __APPLE__
strcat(libname,".dylib");
Expand Down Expand Up @@ -1307,12 +1307,12 @@ int AMXAPI amx_Init(AMX *amx,void *program)
return err;

/* load any extension modules that the AMX refers to */
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__) && !defined AMX_NODYNALOAD
{ /* local */
#if defined _Windows
char libname[sNAMEMAX+8]; /* +1 for '\0', +3 for 'amx' prefix, +4 for extension */
HINSTANCE hlib;
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
char libname[_MAX_PATH];
void *hlib;
#endif
Expand All @@ -1332,7 +1332,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
if (hlib<=HINSTANCE_ERROR)
hlib=NULL;
#endif
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
hlib=dlopen(libname,RTLD_NOW);
#elif defined __APPLE__
/* try to search library in pidpath */
Expand Down Expand Up @@ -1362,7 +1362,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
strcat(funcname,"Init");
#if defined _Windows
libinit=(AMX_ENTRY)GetProcAddress(hlib,funcname);
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
libinit=(AMX_ENTRY)dlsym(hlib,funcname);
#endif
if (libinit!=NULL)
Expand Down Expand Up @@ -1399,7 +1399,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
return !VirtualProtect(addr, len, p, &prev);
}

#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__

/* Linux, BSD and OSX already have mprotect() */
#define ALIGN(addr) (char *)(((long)addr + sysconf(_SC_PAGESIZE)-1) & ~(sysconf(_SC_PAGESIZE)-1))
Expand Down Expand Up @@ -1469,11 +1469,11 @@ int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code)
#if defined AMX_CLEANUP
int AMXAPI amx_Cleanup(AMX *amx)
{
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__) && !defined AMX_NODYNALOAD
#if defined _Windows
char libname[sNAMEMAX+8]; /* +1 for '\0', +3 for 'amx' prefix, +4 for extension */
HINSTANCE hlib;
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
char libname[_MAX_PATH];
void *hlib;
#endif
Expand All @@ -1484,7 +1484,7 @@ int AMXAPI amx_Cleanup(AMX *amx)
#endif

/* unload all extension modules */
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__) && !defined AMX_NODYNALOAD
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__) && !defined AMX_NODYNALOAD
hdr=(AMX_HEADER *)amx->base;
assert(hdr->magic==AMX_MAGIC);
numlibraries=NUMENTRIES(hdr,libraries,pubvars);
Expand All @@ -1500,7 +1500,7 @@ int AMXAPI amx_Cleanup(AMX *amx)
if (hlib<=HINSTANCE_ERROR)
hlib=NULL;
#endif
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
hlib=dlopen(libname,RTLD_NOLOAD);
#endif
if (hlib!=NULL) {
Expand All @@ -1510,14 +1510,14 @@ int AMXAPI amx_Cleanup(AMX *amx)
strcat(funcname,"Cleanup");
#if defined _Windows
libcleanup=(AMX_ENTRY)GetProcAddress(hlib,funcname);
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
libcleanup=(AMX_ENTRY)dlsym(hlib,funcname);
#endif
if (libcleanup!=NULL)
libcleanup(amx);
#if defined _Windows
FreeLibrary(hlib);
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
dlclose(hlib);
#endif
} /* if (hlib!=NULL) */
Expand Down Expand Up @@ -2847,7 +2847,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
#if !defined AMX_NO_OVERLAY
case OP_CALL_OVL:
offs=(cell)((unsigned char *)cip-amx->code+sizeof(cell)); /* skip address */
assert(offs>=0 && offs<(1L<<(sizeof(cell)*4)));
assert(offs>=0 && offs<((cell)1<<(sizeof(cell)*4)));
PUSH((offs<<(sizeof(cell)*4)) | amx->ovl_index);
amx->ovl_index=(int)*cip;
assert(amx->overlay!=NULL);
Expand Down
5 changes: 4 additions & 1 deletion amx/amx.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#if defined FREEBSD && !defined __FreeBSD__
#define __FreeBSD__
#endif
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined(__NetBSD__)
#include <sclinux.h>
#endif

Expand Down Expand Up @@ -107,6 +107,9 @@
#define HAVE_ALLOCA_H 1
#endif
#endif
#ifdef __NetBSD__
#undef HAVE_ALLOCA_H
#endif
#if defined HAVE_ALLOCA_H && HAVE_ALLOCA_H
#include <alloca.h>
#elif defined __BORLANDC__
Expand Down
8 changes: 3 additions & 5 deletions amx/amxargs.def
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
NAME amxArgs
DESCRIPTION 'Pawn AMX: Script Arguments support'

EXPORTS
amx_ArgsInit
amx_ArgsCleanup
amx_ArgsCleanup @1
amx_ArgsInit @2
amx_ArgsSetCmdLine @3
3 changes: 2 additions & 1 deletion amx/amxdgram.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
#include <stdio.h>
#include <string.h>
#include "osdefs.h"
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <time.h>
#else
#include <malloc.h>
#include <winsock.h>
Expand Down
11 changes: 8 additions & 3 deletions amx/amxfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#if defined __BORLANDC__
#include <dir.h>
#endif
#if defined __BORLANDC__ || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined MACOS || defined __APPLE__
#if defined __BORLANDC__ || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined MACOS || defined __APPLE__ || defined(__NetBSD__)
#include <utime.h>
#else
#include <sys/utime.h>
Expand All @@ -48,11 +48,14 @@
#if defined __WATCOMC__ || defined _MSC_VER
#include <direct.h>
#endif
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined MACOS || defined __APPLE__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined MACOS || defined __APPLE__ || defined __NetBSD__ || defined __MINGW32__
#include <dirent.h>
#else
#include <io.h>
#endif
#if defined __MINGW32__
#include <direct.h>
#endif
#if defined __GNUC__ || defined __clang__
#include <unistd.h>
#endif
Expand Down Expand Up @@ -93,7 +96,7 @@
#define _tgetenv getenv
#define _tremove remove
#define _trename rename
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__
#define _tmkdir mkdir
#define _trmdir rmdir
#define _tstat stat
Expand All @@ -110,6 +113,8 @@
#elif defined __WIN32__
#if defined __WATCOMC__
#define t_stat _stat
#elif defined __MINGW32__
#define t_stat _stat
#else
#define t_stat __stat
#endif
Expand Down
7 changes: 2 additions & 5 deletions amx/amxfile.def
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
NAME amxFile
DESCRIPTION 'File I/O support library'

EXPORTS
amx_FileInit
amx_FileCleanup
amx_FileCleanup @1
amx_FileInit @2
4 changes: 2 additions & 2 deletions amx/amxfixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static cell AMX_NATIVE_CALL n_fmul(AMX *amx,const cell *params)
cell sign=1;

(void)amx;
assert(MULTIPLIER<=(1L<<WORDSHIFT));
assert(MULTIPLIER<=((cell)1<<WORDSHIFT));

/* make both operands positive values, but keep the sign of the result */
if (params[1]<0) {
Expand Down Expand Up @@ -423,7 +423,7 @@ static cell AMX_NATIVE_CALL n_fdiv(AMX *amx,const cell *params)

/* pre-scale the dividend into a 64-bit/128-bit number */
b[0]=dividend*MULTIPLIER;
b[1]=(HIWORD(dividend)*MULTIPLIER) >> WORDSHIFT;
b[1]=(ucell)(HIWORD(dividend)*MULTIPLIER) >> WORDSHIFT;

/* add half of the divisor, to round the data */
b[0]+=(ucell)divisor/2;
Expand Down
Loading