mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 22:35:37 +03:00
Added request at15060 by twistedeuphoria
This commit is contained in:
parent
950d1b4a5f
commit
13b6c0764c
@ -116,7 +116,7 @@ void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pM
|
||||
void UTIL_IntToString(int value, char *output);
|
||||
void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name);
|
||||
void UTIL_ShowMenu( edict_t* pEntity, int slots, int time, char *menu, int mlen );
|
||||
const char *UTIL_VarArgs(const char *fmt, ...);
|
||||
char *UTIL_VarArgs(const char *fmt, ...);
|
||||
|
||||
|
||||
#define GET_PLAYER_POINTER(e) (&g_players[ENTINDEX(e)])
|
||||
|
@ -36,18 +36,18 @@
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
//#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#endif
|
||||
|
||||
// header file for unlink()
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#define WINDOWS_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
@ -234,13 +234,45 @@ static cell AMX_NATIVE_CALL delete_file(AMX *amx, cell *params) /* 1 param */
|
||||
static cell AMX_NATIVE_CALL file_exists(AMX *amx, cell *params) /* 1 param */
|
||||
{
|
||||
int iLen;
|
||||
char* sFile = get_amxstring(amx,params[1],0,iLen);
|
||||
FILE* fp = fopen(build_pathname("%s",sFile),"r");
|
||||
if ( fp != NULL) {
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
char *sFile = get_amxstring(amx,params[1],0,iLen);
|
||||
char *file = build_pathname("%s",sFile);
|
||||
#if defined WIN32 || defined _WIN32
|
||||
DWORD attr = GetFileAttributes(file);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||
return 0;
|
||||
if (attr == FILE_ATTRIBUTE_DIRECTORY)
|
||||
return 0;
|
||||
return 1;
|
||||
#else
|
||||
struct stat s;
|
||||
if (stat(file, &s) != 0)
|
||||
return 0;
|
||||
if (S_ISDIR(s.st_mode))
|
||||
return 0;
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL dir_exists(AMX *amx, cell *params) /* 1 param */
|
||||
{
|
||||
int iLen;
|
||||
char *sFile = get_amxstring(amx,params[1],0,iLen);
|
||||
char *file = build_pathname("%s",sFile);
|
||||
#if defined WIN32 || defined _WIN32
|
||||
DWORD attr = GetFileAttributes(file);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||
return 0;
|
||||
if (attr == FILE_ATTRIBUTE_DIRECTORY)
|
||||
return 1;
|
||||
return 0;
|
||||
#else
|
||||
struct stat s;
|
||||
if (stat(file, &s) != 0)
|
||||
return 0;
|
||||
if (S_ISDIR(s.st_mode))
|
||||
return 1;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */
|
||||
@ -643,6 +675,7 @@ AMX_NATIVE_INFO file_Natives[] = {
|
||||
{ "fgetf", amx_fgetf },
|
||||
{ "fputf", amx_fputf },
|
||||
{ "build_pathname", amx_build_pathname},
|
||||
{ "dir_exists", dir_exists },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
@ -37,7 +37,7 @@
|
||||
#define _vsnprintf vsnprintf
|
||||
#endif
|
||||
|
||||
const char *UTIL_VarArgs(const char *fmt, ...)
|
||||
char *UTIL_VarArgs(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
static char string[4096];
|
||||
|
@ -28,6 +28,9 @@ native delete_file(const file[]);
|
||||
/* Checks for file. If file exists function returns 1, in other case 0. */
|
||||
native file_exists(const file[]);
|
||||
|
||||
/* Checks if a directory exists */
|
||||
native dir_exists(const dir[]);
|
||||
|
||||
/* Returns a file size in bytes if flag is set to 0.
|
||||
* When flag is set to 1 returns number of lines in the file,
|
||||
* and when flags is 2, function returns 1 if the file ends
|
||||
|
Loading…
Reference in New Issue
Block a user