Ported the new dir commands to linux

This commit is contained in:
David Anderson 2005-07-15 16:14:00 +00:00
parent 1b09be51e1
commit fe2d28f711
2 changed files with 32 additions and 2 deletions

View File

@ -2355,6 +2355,9 @@ static cell AMX_NATIVE_CALL get_modulesnum(AMX *amx, cell *params)
return (cell)countModules(CountModules_All); return (cell)countModules(CountModules_All);
} }
#if defined WIN32 || defined _WIN32
#pragma warning (disable:4700)
#endif
// register by value? - source macros [ EXPERIMENTAL ] // register by value? - source macros [ EXPERIMENTAL ]
#define spx(n,T) ((n)=(n)^(T),(T)=(n)^(T),true)?(n)=(n)^(T):0 #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++;} #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; int len, ret = 0;
//get the destination string //get the destination string
char *data = get_amxstring(amx, params[2], 0, len); char *data = get_amxstring(amx, params[2], 0, len);
void *PT; void *PT;
//copy //copy

View File

@ -648,15 +648,28 @@ static cell AMX_NATIVE_CALL amx_open_dir(AMX *amx, cell *params)
{ {
int len; int len;
char *path = get_amxstring(amx, params[1], 0, len); char *path = get_amxstring(amx, params[1], 0, len);
char *dirname = build_pathname("%s\\*", path);
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
char *dirname = build_pathname("%s\\*", path);
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
HANDLE hFile = FindFirstFile(dirname, &fd); HANDLE hFile = FindFirstFile(dirname, &fd);
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
return 0; return 0;
set_amxstring(amx, params[2], fd.cFileName, params[3]); set_amxstring(amx, params[2], fd.cFileName, params[3]);
return (DWORD)hFile; 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 #endif
} }
@ -668,6 +681,12 @@ static cell AMX_NATIVE_CALL amx_close_dir(AMX *amx, cell *params)
return 0; return 0;
FindClose(hFile); FindClose(hFile);
return 1; return 1;
#else
DIR *dp = (DIR *)params[1];
if (!dp)
return 0;
closedir(dp);
return 1;
#endif #endif
} }
@ -682,6 +701,15 @@ static cell AMX_NATIVE_CALL amx_get_dir(AMX *amx, cell *params)
return 0; return 0;
set_amxstring(amx, params[2], fd.cFileName, params[3]); set_amxstring(amx, params[2], fd.cFileName, params[3]);
return 1; 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 #endif
} }