Added request at15060 by twistedeuphoria

This commit is contained in:
David Anderson 2005-07-07 19:53:02 +00:00
parent 950d1b4a5f
commit 13b6c0764c
4 changed files with 47 additions and 11 deletions

View File

@ -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_IntToString(int value, char *output);
void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name); 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 ); 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)]) #define GET_PLAYER_POINTER(e) (&g_players[ENTINDEX(e)])

View File

@ -36,18 +36,18 @@
#endif #endif
#ifdef __GNUC__ #ifdef __GNUC__
//#include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#endif #endif
// header file for unlink() // header file for unlink()
#ifdef __linux__ #ifdef __linux__
#include <unistd.h> #include <unistd.h>
#else #else
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#include <io.h> #include <io.h>
#endif #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 */ static cell AMX_NATIVE_CALL file_exists(AMX *amx, cell *params) /* 1 param */
{ {
int iLen; int iLen;
char* sFile = get_amxstring(amx,params[1],0,iLen); char *sFile = get_amxstring(amx,params[1],0,iLen);
FILE* fp = fopen(build_pathname("%s",sFile),"r"); char *file = build_pathname("%s",sFile);
if ( fp != NULL) { #if defined WIN32 || defined _WIN32
fclose(fp); DWORD attr = GetFileAttributes(file);
return 1; 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; 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 */ 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 }, { "fgetf", amx_fgetf },
{ "fputf", amx_fputf }, { "fputf", amx_fputf },
{ "build_pathname", amx_build_pathname}, { "build_pathname", amx_build_pathname},
{ "dir_exists", dir_exists },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -37,7 +37,7 @@
#define _vsnprintf vsnprintf #define _vsnprintf vsnprintf
#endif #endif
const char *UTIL_VarArgs(const char *fmt, ...) char *UTIL_VarArgs(const char *fmt, ...)
{ {
va_list ap; va_list ap;
static char string[4096]; static char string[4096];

View File

@ -28,6 +28,9 @@ native delete_file(const file[]);
/* Checks for file. If file exists function returns 1, in other case 0. */ /* Checks for file. If file exists function returns 1, in other case 0. */
native file_exists(const file[]); 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. /* 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, * 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 * and when flags is 2, function returns 1 if the file ends