chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] [PATCH] Fix rename-file behavior on Windows when d


From: Mario Domenech Goulart
Subject: Re: [Chicken-hackers] [PATCH] Fix rename-file behavior on Windows when destination exists
Date: Mon, 18 Aug 2014 16:28:03 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Hi Michele,

On Mon, 18 Aug 2014 16:34:23 +0200 Michele La Monaca <address@hidden> wrote:

> (rename-file "x" "y")
>
> fails on Windows if "y" already exists. I think it would be better to have the
> same behavior as Unix (i.e. overwrite). The attached patch does that.
>
> Regards,
> Michele
>
> From 57098c32ce1b02834b972924c85690653b2d4fb3 Mon Sep 17 00:00:00 2001
> From: Michele La Monaca <address@hidden>
> Date: Mon, 18 Aug 2014 16:19:44 +0200
> Subject: [PATCH] Fix rename-file behavior on Windows when destination exists
>
> ---
>  chicken.h | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/chicken.h b/chicken.h
> index fc40303..0624e22 100644
> --- a/chicken.h
> +++ b/chicken.h
> @@ -1309,7 +1309,12 @@ extern double trunc(double);
>  #define C_string_compare(to, from, n)   C_fix(C_memcmp(C_c_string(to), 
> C_c_string(from), C_unfix(n)))
>  #define C_string_compare_case_insensitive(from, to, n) \
>                                          C_fix(C_memcasecmp(C_c_string(from), 
> C_c_string(to), C_unfix(n)))
> -#define C_rename_file(old, new)         C_fix(rename(C_c_string(old), 
> C_c_string(new)))
> +#if defined(_WIN32) || defined(_WIN64)

Shouldn't we check !defined(__CYGWIN__) here?

> +# include <windows.h>
> +# define C_rename_file(old, new)        C_fix(0 == 
> MoveFileEx(C_c_string(old), C_c_string(new), MOVEFILE_REPLACE_EXISTING) ? -1 
> : 0)
> +#else
> +# define C_rename_file(old, new)        C_fix(rename(C_c_string(old), 
> C_c_string(new)))
> +#endif
>  #define C_delete_file(fname)            C_fix(remove(C_c_string(fname)))
>  #define C_poke_double(b, i, n)          (((double *)C_data_pointer(b))[ 
> C_unfix(i) ] = C_c_double(n), C_SCHEME_UNDEFINED)
>  #define C_poke_c_string(b, i, from, s)  (C_strlcpy((char *)C_block_item(b, 
> C_unfix(i)), C_data_pointer(from), s), C_SCHEME_UNDEFINED)

Best wishes.
Mario
-- 
http://parenteses.org/mario



reply via email to

[Prev in Thread] Current Thread [Next in Thread]