Added CreateDirectory() native and a few permissions macros (bug 3253, r=ds).

This commit is contained in:
David Anderson 2008-09-17 02:07:19 -05:00
parent 09ea2e13aa
commit 556c03babf
2 changed files with 35 additions and 0 deletions

View File

@ -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},
};

View File

@ -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.
*