int
_p4_rename (const char *source, const char *target)
{
char save_name [PATH_LENGTH+1];
if (access(target, 0) == 0)
{
sprintf (save_name, "%s~" , target);
if (access (save_name, 0) == 0
|| unlink (save_name) == -1
|| link (target, save_name) == -1
|| unlink (target) == -1)
return -1;
}
if (link (source, target) == -1)
{
if (save_name != NULL)
if (link (save_name, target) == -1)
return -1;
else
unlink (save_name);
return -1;
}
if (unlink (source) == -1)
return -1;
if (save_name != NULL)
unlink (save_name);
return 0;
} |