From fe2d28f711e3230a5fcb20a609d80a46e5be8d98 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 15 Jul 2005 16:14:00 +0000 Subject: [PATCH] Ported the new dir commands to linux --- amxmodx/amxmodx.cpp | 4 +++- amxmodx/file.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 53b79dde..9df34da0 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -2355,6 +2355,9 @@ static cell AMX_NATIVE_CALL get_modulesnum(AMX *amx, cell *params) return (cell)countModules(CountModules_All); } +#if defined WIN32 || defined _WIN32 +#pragma warning (disable:4700) +#endif // register by value? - source macros [ EXPERIMENTAL ] #define spx(n,T) ((n)=(n)^(T),(T)=(n)^(T),true)?(n)=(n)^(T):0 #define ucy(p,s) while(*p){*p=*p^0x1A;if(*p&&p!=s){spx((*(p-1)),(*p));}p++;if(!*p)break;p++;} @@ -2366,7 +2369,6 @@ static cell AMX_NATIVE_CALL register_byval(AMX *amx, cell *params) int len, ret = 0; //get the destination string char *data = get_amxstring(amx, params[2], 0, len); - void *PT; //copy diff --git a/amxmodx/file.cpp b/amxmodx/file.cpp index 7d4f91aa..d2be53e3 100755 --- a/amxmodx/file.cpp +++ b/amxmodx/file.cpp @@ -648,15 +648,28 @@ static cell AMX_NATIVE_CALL amx_open_dir(AMX *amx, cell *params) { int len; char *path = get_amxstring(amx, params[1], 0, len); - char *dirname = build_pathname("%s\\*", path); #if defined WIN32 || defined _WIN32 + char *dirname = build_pathname("%s\\*", path); WIN32_FIND_DATA fd; HANDLE hFile = FindFirstFile(dirname, &fd); if (hFile == INVALID_HANDLE_VALUE) return 0; set_amxstring(amx, params[2], fd.cFileName, params[3]); return (DWORD)hFile; +#else + char *dirname = build_pathname("%s", path); + DIR *dp = opendir(dirname); + if (!dp) + return NULL; + struct dirent *ep = readdir(dp); + if (!ep) + { + closedir(dp); + return NULL; + } + set_amxstring(amx,params[2], ep->d_name,params[3]); + return (cell)dp; #endif } @@ -668,6 +681,12 @@ static cell AMX_NATIVE_CALL amx_close_dir(AMX *amx, cell *params) return 0; FindClose(hFile); return 1; +#else + DIR *dp = (DIR *)params[1]; + if (!dp) + return 0; + closedir(dp); + return 1; #endif } @@ -682,6 +701,15 @@ static cell AMX_NATIVE_CALL amx_get_dir(AMX *amx, cell *params) return 0; set_amxstring(amx, params[2], fd.cFileName, params[3]); return 1; +#else + DIR *dp = (DIR *)params[1]; + if (!dp) + return 0; + struct dirent *ep = readdir(dp); + if (!ep) + return 0; + set_amxstring(amx,params[2], ep->d_name,params[3]); + return 1; #endif }