Fixed bug am46630: rename_file did not have a relative location version

This commit is contained in:
David Anderson 2006-10-31 20:18:44 +00:00
parent b33e76d9c4
commit 8b8cc3dd6b
2 changed files with 18 additions and 3 deletions

View File

@ -799,13 +799,25 @@ static cell AMX_NATIVE_CALL amx_rmdir(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_rename(AMX *amx, cell *params)
{
int len;
char f_old_r[260];
char f_new_r[260];
char *fold = get_amxstring(amx, params[1], 0, len);
char *fnew = get_amxstring(amx, params[2], 1, len);
if (params[0] / sizeof(cell) == 3 && params[3])
{
build_pathname_r(f_old_r, sizeof(f_old_r)-1, "%s", fold);
build_pathname_r(f_new_r, sizeof(f_new_r)-1, "%s", fnew);
} else {
snprintf(f_old_r, sizeof(f_old_r)-1, "%s", fold);
snprintf(f_new_r, sizeof(f_new_r)-1, "%s", fnew);
}
#if defined __linux__
return (rename(fold, fnew) == 0);
return (rename(f_old_r, f_new_r) == 0);
#elif defined WIN32
return MoveFileA(fold, fnew);
return MoveFileA(f_old_r, f_new_r);
#endif
}

View File

@ -29,8 +29,11 @@ native delete_file(const file[]);
native file_exists(const file[]);
/* renames a file. returns 0 on failure, 1 on success.
* if relative true, rename_file will act like other natives which
* use the moddir as a base directory. otherwise, the current directory is
* undefined (but assumed to be hlds).
*/
native rename_file(const oldname[], const newname[]);
native rename_file(const oldname[], const newname[], relative=0);
/* Checks if a directory exists */
native dir_exists(const dir[]);