From 6f0868aacca9b9efd1bc0b621ea34f73dd7f09b9 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Tue, 6 Apr 1999 20:46:59 +0000 Subject: [PATCH] Workaround the fact that Windows has really poor emulation of POSIX functions such as rename. (In fact, it has completely different semantics for this call!) Fix supplied by Tom Sanfilippo (txn# 2184 in krb5dev) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11341 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/rcache/ChangeLog | 7 ++++++ src/lib/krb5/rcache/rc_io.c | 41 ++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/lib/krb5/rcache/ChangeLog b/src/lib/krb5/rcache/ChangeLog index a015224cf..1f5ac87c2 100644 --- a/src/lib/krb5/rcache/ChangeLog +++ b/src/lib/krb5/rcache/ChangeLog @@ -1,3 +1,10 @@ +Tue Apr 6 16:10:44 1999 Theodore Y. Ts'o + + * rc_io.c (krb5_rc_io_move): Workaround the fact that Windows has + really poor emulation of POSIX functions such as rename. + (In fact, it has completely different semantics for this + call!) Fix supplied by Tom Sanfilippo (txn# 2184 in krb5dev) + 1998-11-13 Theodore Ts'o * Makefile.in: Set the myfulldir and mydir variables (which are diff --git a/src/lib/krb5/rcache/rc_io.c b/src/lib/krb5/rcache/rc_io.c index ae5c6d061..d45c7a1fb 100644 --- a/src/lib/krb5/rcache/rc_io.c +++ b/src/lib/krb5/rcache/rc_io.c @@ -245,19 +245,40 @@ krb5_error_code krb5_rc_io_move (context, new, old) krb5_rc_iostuff *new; krb5_rc_iostuff *old; { - if (rename(old->fn,new->fn) == -1) /* MUST be atomic! */ - return KRB5_RC_IO_UNKNOWN; - (void) krb5_rc_io_close(context, new); - new->fn = malloc(strlen(old->fn)+1); - if (new->fn == 0) - return ENOMEM; - strcpy(new->fn, old->fn); +#if defined(_MSDOS) || defined(_WIN32) + /* + * Work around provided by Tom Sanfilippo to work around poor + * Windows emulation of POSIX functions. Rename and dup has + * different semantics! + */ + char *fn = NULL; + GETDIR; + close(new->fd); + unlink(new->fn); + close(old->fd); + if (rename(old->fn,new->fn) == -1) /* MUST be atomic! */ + return KRB5_RC_IO_UNKNOWN; + if (!(fn = malloc(strlen(new->fn) - dirlen + 1))) + return KRB5_RC_IO_MALLOC; + strcpy(fn, new->fn + dirlen); + krb5_rc_io_close(context, new); + krb5_rc_io_open(context, new, fn); + free(fn); +#else + if (rename(old->fn,new->fn) == -1) /* MUST be atomic! */ + return KRB5_RC_IO_UNKNOWN; + (void) krb5_rc_io_close(context, new); + new->fn = malloc(strlen(old->fn)+1); + if (new->fn == 0) + return ENOMEM; + strcpy(new->fn, old->fn); #ifdef macintosh - new->fd = fcntl(old->fd, F_DUPFD); + new->fd = fcntl(old->fd, F_DUPFD); #else - new->fd = dup(old->fd); + new->fd = dup(old->fd); #endif - return 0; +#endif + return 0; } krb5_error_code krb5_rc_io_write (context, d, buf, num) -- 2.26.2