From 8da4987895ef1041366d2d1d69f3651241faa544 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 27 Apr 2006 17:31:38 +0000 Subject: [PATCH] implemented request at28875 --- amxmodx/file.cpp | 27 +++++++++++++++++++++++++++ plugins/include/file.inc | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/amxmodx/file.cpp b/amxmodx/file.cpp index 92e500eb..3204acd3 100755 --- a/amxmodx/file.cpp +++ b/amxmodx/file.cpp @@ -554,6 +554,18 @@ static cell AMX_NATIVE_CALL amx_fread_blocks(AMX *amx, cell *params) return 0; } +static cell AMX_NATIVE_CALL amx_fputs(AMX *amx, cell *params) +{ + FILE *fp = (FILE *)params[1]; + + if (!fp) + return 0; + + int len; + char *str = get_amxstring(amx, params[2], 0, len); + return fputs(str, fp); +} + static cell AMX_NATIVE_CALL amx_fgets(AMX *amx, cell *params) { FILE *fp = (FILE *)params[1]; @@ -787,6 +799,19 @@ static cell AMX_NATIVE_CALL amx_rmdir(AMX *amx, cell *params) return 1; } +static cell AMX_NATIVE_CALL amx_rename(AMX *amx, cell *params) +{ + int len; + char *fold = get_amxstring(amx, params[1], 0, len); + char *fnew = get_amxstring(amx, params[2], 1, len); + +#if defined __linux__ + return (rename(fold, fnew) == 0); +#elif defined WIN32 + return MoveFileA(fold, fnew); +#endif +} + AMX_NATIVE_INFO file_Natives[] = { {"delete_file", delete_file}, @@ -820,5 +845,7 @@ AMX_NATIVE_INFO file_Natives[] = {"fputc", amx_fputc}, {"fungetc", amx_ungetc}, {"rmdir", amx_rmdir}, + {"fputs", amx_fputs}, + {"rename_file", amx_rename}, {NULL, NULL} }; diff --git a/plugins/include/file.inc b/plugins/include/file.inc index 7e660ce6..8efb5548 100755 --- a/plugins/include/file.inc +++ b/plugins/include/file.inc @@ -28,6 +28,10 @@ native delete_file(const file[]); /* Checks for file. If file exists function returns 1, in other case 0. */ native file_exists(const file[]); +/* renames a file. returns 0 on failure, 1 on success. + */ +native rename_file(const oldname[], const newname[]); + /* Checks if a directory exists */ native dir_exists(const dir[]); @@ -72,6 +76,9 @@ native feof(file); //Reads a line from a text file -- includes newline! native fgets(file, buffer[], maxlength); +//Writes a line to a text file. Returns # of characters written. +native fputs(file, const text[]); + //Writes a line to the file native fprintf(file, const fmt[], {Float,Sql,Result,_}:...);