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

Former-commit-id: cf7b8645fa6a14e5be71336df4543901b2c53e0b
This commit is contained in:
Vincent HERBET 2013-06-21 23:09:41 +02:00
parent 139d68700b
commit e5864c5abf
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)
{
#ifdef __GNUC__
@ -862,6 +869,37 @@ static cell AMX_NATIVE_CALL amx_fflush(AMX *amx, cell *params)
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[] =
{
{"delete_file", delete_file},
@ -899,5 +937,6 @@ AMX_NATIVE_INFO file_Natives[] =
{"rename_file", amx_rename},
{"LoadFileForMe", LoadFileForMe},
{"fflush", amx_fflush},
{"GetFileTime", GetFileTime},
{NULL, NULL}
};

View File

@ -141,3 +141,18 @@ native LoadFileForMe(const file[], buffer[], maxlength, &length=0);
*/
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 );