From 556c03babfeac3d679edfb459384efb4d20eff11 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 17 Sep 2008 02:07:19 -0500 Subject: [PATCH] Added CreateDirectory() native and a few permissions macros (bug 3253, r=ds). --- core/smn_filesystem.cpp | 16 ++++++++++++++++ plugins/include/files.inc | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/core/smn_filesystem.cpp b/core/smn_filesystem.cpp index 74f3aa8c..0d9a95c7 100644 --- a/core/smn_filesystem.cpp +++ b/core/smn_filesystem.cpp @@ -487,6 +487,21 @@ static cell_t sm_FileSize(IPluginContext *pContext, const cell_t *params) #endif } +static cell_t sm_CreateDirectory(IPluginContext *pContext, const cell_t *params) +{ + char *name; + char realpath[PLATFORM_MAX_PATH]; + + pContext->LocalToString(params[1], &name); + g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name); + +#if defined PLATFORM_WINDOWS + return mkdir(realpath) == 0; +#else + return mkdir(realpath, params[2]) == 0; +#endif +} + static cell_t sm_RemoveDir(IPluginContext *pContext, const cell_t *params) { char *name; @@ -959,5 +974,6 @@ REGISTER_NATIVES(filesystem) {"WriteFileString", sm_WriteFileString}, {"AddGameLogHook", sm_AddGameLogHook}, {"RemoveGameLogHook", sm_RemoveGameLogHook}, + {"CreateDirectory", sm_CreateDirectory}, {NULL, NULL}, }; diff --git a/plugins/include/files.inc b/plugins/include/files.inc index d01c1492..65fb01fd 100644 --- a/plugins/include/files.inc +++ b/plugins/include/files.inc @@ -353,6 +353,25 @@ native FlushFile(Handle:file); */ native bool:RemoveDir(const String:path[]); +#define FPERM_U_READ 0x0100 /* User can read. */ +#define FPERM_U_WRITE 0x0080 /* User can write. */ +#define FPERM_U_EXEC 0x0040 /* User can exec. */ +#define FPERM_G_READ 0x0020 /* Group can read. */ +#define FPERM_G_WRITE 0x0010 /* Group can write. */ +#define FPERM_G_EXEC 0x0008 /* Group can exec. */ +#define FPERM_O_READ 0x0004 /* Anyone can read. */ +#define FPERM_O_WRITE 0x0002 /* Anyone can write. */ +#define FPERM_O_EXEC 0x0001 /* Anyone can exec. */ + +/** + * Creates a directory. + * + * @param path Path to create. + * @param mode Permissions (default is o=rx,g=rx,u=rwx). Note that folders must have + * the execute bit set on Linux. On Windows, the mode is ignored. + */ +native bool:CreateDirectory(const String:path[], mode); + /** * Returns a file timestamp as a unix timestamp. *