diff --git a/core/smn_filesystem.cpp b/core/smn_filesystem.cpp index f1cfd782..863a4ff7 100644 --- a/core/smn_filesystem.cpp +++ b/core/smn_filesystem.cpp @@ -448,6 +448,25 @@ static cell_t sm_WriteFileLine(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t sm_FlushFile(IPluginContext *pContext, const cell_t *params) +{ + Handle_t hndl = static_cast(params[1]); + HandleError herr; + HandleSecurity sec; + FILE *pFile; + + sec.pOwner = NULL; + sec.pIdentity = g_pCoreIdent; + + if ((herr=g_HandleSys.ReadHandle(hndl, g_FileType, &sec, (void **)&pFile)) + != HandleError_None) + { + return pContext->ThrowNativeError("Invalid file handle %x (error %d)", hndl, herr); + } + + return (fflush(pFile) == 0) ? 1 : 0; +} + static cell_t sm_BuildPath(IPluginContext *pContext, const cell_t *params) { char path[PLATFORM_MAX_PATH], *fmt, *buffer; @@ -523,5 +542,6 @@ REGISTER_NATIVES(filesystem) {"LogToGame", sm_LogToGame}, {"LogMessage", sm_LogMessage}, {"LogError", sm_LogError}, + {"FlushFile", sm_FlushFile}, {NULL, NULL}, }; diff --git a/plugins/include/files.inc b/plugins/include/files.inc index 86501a68..8df5451b 100644 --- a/plugins/include/files.inc +++ b/plugins/include/files.inc @@ -168,6 +168,15 @@ native bool:DirExists(const String:path[]); */ native FileSize(const String:path[]); +/** + * Flushes a file's buffered output; any buffered output + * is immediately written to the file. + * + * @param file Handle to the file. + * @return True on success, false on failure. + */ +native FlushFile(Handle:file); + /** * Removes a directory. * @note On most Operating Systems you cannot remove a directory which has files inside it.