implemented amb843 - GetFileTime()

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401376
This commit is contained in:
David Anderson
2007-08-26 18:29:02 +00:00
parent 294d6b9f8f
commit d9866748f7
2 changed files with 63 additions and 0 deletions
+44
View File
@@ -543,6 +543,49 @@ static cell_t sm_LogError(IPluginContext *pContext, const cell_t *params)
return 1;
}
enum
{
FileTime_LastAccess = 0, /* Last access (not available on FAT) */
FileTime_Created = 1, /* Creation (not available on FAT) */
FileTime_LastChange = 2, /* Last modification */
};
static cell_t sm_GetFileTime(IPluginContext *pContext, const cell_t *params)
{
char *name;
int err;
if ((err=pContext->LocalToString(params[1], &name)) != SP_ERROR_NONE)
{
pContext->ThrowNativeErrorEx(err, NULL);
return 0;
}
char realpath[PLATFORM_MAX_PATH];
g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name);
#ifdef PLATFORM_WINDOWS
struct _stat s;
if (_stat(realpath, &s) != 0)
#elif defined PLATFORM_POSIX
struct stat s;
if (stat(path, &s) != 0)
#endif
{
return -1;
} else {
if (params[2] == FileTime_LastAccess)
{
return (cell_t)s.st_atime;
} else if (params[2] == FileTime_Created) {
return (cell_t)s.st_ctime;
} else if (params[2] == FileTime_LastChange) {
return (cell_t)s.st_mtime;
}
}
return -1;
}
static FileNatives s_FileNatives;
REGISTER_NATIVES(filesystem)
@@ -566,5 +609,6 @@ REGISTER_NATIVES(filesystem)
{"LogMessage", sm_LogMessage},
{"LogError", sm_LogError},
{"FlushFile", sm_FlushFile},
{"GetFileTime", sm_GetFileTime},
{NULL, NULL},
};