Add GetFileTime returning a file timestamp as a unix timestamp (bug 4543, r=joropito)

This commit is contained in:
Vincent HERBET 2013-06-21 23:09:41 +02:00
parent df7c045089
commit cf7b8645fa
2 changed files with 54 additions and 0 deletions

View File

@ -74,6 +74,13 @@ public:
} }
}; };
enum FileTimeType
{
FileTime_LastAccess = 0, /* Last access (not available on FAT) */
FileTime_Created = 1, /* Creation (not available on FAT) */
FileTime_LastChange = 2, /* Last modification */
};
static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params) static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params)
{ {
#ifdef __GNUC__ #ifdef __GNUC__
@ -862,6 +869,37 @@ static cell AMX_NATIVE_CALL amx_fflush(AMX *amx, cell *params)
return fflush(fp); return fflush(fp);
} }
static cell AMX_NATIVE_CALL GetFileTime(AMX *amx, cell *params)
{
int len;
char *file = get_amxstring(amx, params[1], 0, len);
char path[256];
build_pathname_r(path, sizeof(path), "%s", file);
#if defined(WIN32)
struct _stat s;
if (_stat(path, &s) != 0)
#elif defined(__linux__) || defined(__APPLE__)
struct stat s;
if (stat(path, &s) != 0)
#endif
{
return -1;
}
time_t time_val;
switch( params[2] )
{
case FileTime_LastAccess : time_val = s.st_atime; break;
case FileTime_Created : time_val = s.st_ctime; break;
case FileTime_LastChange : time_val = s.st_mtime; break;
}
return (cell)time_val;
}
AMX_NATIVE_INFO file_Natives[] = AMX_NATIVE_INFO file_Natives[] =
{ {
{"delete_file", delete_file}, {"delete_file", delete_file},
@ -899,5 +937,6 @@ AMX_NATIVE_INFO file_Natives[] =
{"rename_file", amx_rename}, {"rename_file", amx_rename},
{"LoadFileForMe", LoadFileForMe}, {"LoadFileForMe", LoadFileForMe},
{"fflush", amx_fflush}, {"fflush", amx_fflush},
{"GetFileTime", GetFileTime},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -141,3 +141,18 @@ native LoadFileForMe(const file[], buffer[], maxlength, &length=0);
*/ */
native fflush(file); native fflush(file);
enum FileTimeType
{
FileTime_LastAccess, /* Last access (not available on FAT) */
FileTime_Created, /* Creation (not available on FAT) */
FileTime_LastChang, /* Last modification */
};
/**
* Returns a file timestamp as a unix timestamp.
*
* @param file File name.
* @param tmode Time mode. See FileTime_* constants.
* @return Returns a file timestamp as a unix timestamp.
*/
native GetFileTime( const file[], FileTimeType:tmode );