Add roken/rename.c to fix non-standard rename()

roken/rename.c is for platforms where the native rename()
implementation does not replace the target if it already exists.  This
implementation isn't atomic, but should be close enough for most
purposes.

For correct behavior, rk_rename() should be used instead of rename().
rk_rename() is #defined to be rename() on platforms where this fix is
not necessary.
This commit is contained in:
Asanka Herath
2010-08-24 00:34:18 -04:00
committed by Asanka C. Herath
parent 6cc480fc09
commit 4b36b36e0b
4 changed files with 58 additions and 18 deletions

View File

@@ -813,15 +813,7 @@ fcc_remove_cred(krb5_context context,
return ret;
}
ret = rename(&newname[5], FILENAME(id));
#ifdef RENAME_DOES_NOT_UNLINK
if (ret && (errno == EEXIST || errno == EACCES)) {
ret = unlink(FILENAME(id));
if (ret == 0) {
ret = rename(&newname[5], FILENAME(id));
}
}
#endif
ret = rk_rename(&newname[5], FILENAME(id));
if (ret)
ret = errno;
free(newname);
@@ -917,15 +909,7 @@ fcc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
{
krb5_error_code ret = 0;
ret = rename(FILENAME(from), FILENAME(to));
#ifdef RENAME_DOES_NOT_UNLINK
if (ret && (errno == EEXIST || errno == EACCES)) {
ret = unlink(FILENAME(to));
if (ret == 0) {
ret = rename(FILENAME(from), FILENAME(to));
}
}
#endif
ret = rk_rename(FILENAME(from), FILENAME(to));
if (ret && errno != EXDEV) {
char buf[128];