From df43d905136000cff37be486d6b09a13c1e171b5 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 19 Sep 2011 14:25:44 -0600 Subject: [PATCH] windows: fix `copy-file' changes --- src/racket/src/error.c | 10 +++++++++- src/racket/src/file.c | 2 +- src/racket/src/port.c | 20 +++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/racket/src/error.c b/src/racket/src/error.c index 087fb3ebb7..98d5d34ea6 100644 --- a/src/racket/src/error.c +++ b/src/racket/src/error.c @@ -215,7 +215,7 @@ Scheme_Config *scheme_init_error_escape_proc(Scheme_Config *config) %- = skip int %L = line number as intptr_t, -1 means no line - %e = error number for strerror()/FormatMessage() + %e = error number for strerror() %E = error number for platform-specific error string %Z = potential platform-specific error number; additional char* is either NULL or a specific error message @@ -223,6 +223,8 @@ Scheme_Config *scheme_init_error_escape_proc(Scheme_Config *config) or error number for scheme_hostname_error() %m = boolean then error number like %e, which is used only if the boolean is 1 + %M = boolean then error number like %E, which + is used only if the boolean is 1 */ static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list args, char **_s) @@ -275,6 +277,7 @@ static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list break; case 'N': case 'm': + case 'M': ints[ip++] = mzVA_ARG(args, int); ints[ip++] = mzVA_ARG(args, int); break; @@ -407,6 +410,7 @@ static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list case 'e': case 'm': case 'E': + case 'M': case 'Z': case 'N': { @@ -417,6 +421,10 @@ static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list none = !ints[ip++]; type = 'e'; he = 0; + } else if (type == 'M') { + none = !ints[ip++]; + type = 'E'; + he = 0; } else if (type == 'N') { he = ints[ip++]; type = 'E'; diff --git a/src/racket/src/file.c b/src/racket/src/file.c index a1d6ae8c24..27b1349e9b 100644 --- a/src/racket/src/file.c +++ b/src/racket/src/file.c @@ -3967,7 +3967,7 @@ static Scheme_Object *copy_file(int argc, Scheme_Object **argv) #endif scheme_raise_exn(pre_exists ? MZEXN_FAIL_FILESYSTEM_EXISTS : MZEXN_FAIL_FILESYSTEM, - "copy-file: %s; cannot copy: %q to: %q%s%m%s", + "copy-file: %s; cannot copy: %q to: %q%s%M%s", reason, filename_for_error(argv[0]), filename_for_error(argv[1]), diff --git a/src/racket/src/port.c b/src/racket/src/port.c index d72119cadc..5b3bc3fc31 100644 --- a/src/racket/src/port.c +++ b/src/racket/src/port.c @@ -4125,8 +4125,10 @@ scheme_do_open_input_file(char *name, int offset, int argc, Scheme_Object *argv[ if (fd == INVALID_HANDLE_VALUE) { if (err) { + int errv; + errv = GetLastError(); *err = "cannot open source file"; - *eerrno = GetLastError(); + *eerrno = errv; } else filename_exn(name, "cannot open input file", filename, GetLastError()); return NULL; @@ -4397,9 +4399,9 @@ scheme_do_open_output_file(char *name, int offset, int argc, Scheme_Object *argv NULL); if (fd == INVALID_HANDLE_VALUE) { - int err; - err = GetLastError(); - if ((err == ERROR_ACCESS_DENIED) && (existsok < -1)) { + int errv; + errv = GetLastError(); + if ((errv == ERROR_ACCESS_DENIED) && (existsok < -1)) { /* Delete and try again... */ if (DeleteFileW(WIDE_PATH(filename))) { fd = CreateFileW(WIDE_PATH(filename), @@ -4410,17 +4412,17 @@ scheme_do_open_output_file(char *name, int offset, int argc, Scheme_Object *argv 0, NULL); if (fd == INVALID_HANDLE_VALUE) - err = GetLastError(); + errv = GetLastError(); } else { scheme_raise_exn(MZEXN_FAIL_FILESYSTEM, "%s: error deleting \"%q\" (%E)", name, filename, GetLastError()); return NULL; } - } else if (err == ERROR_FILE_EXISTS) { + } else if (errv == ERROR_FILE_EXISTS) { if (err) { *err = "destination already exists"; - *eerrno = err; + *eerrno = errv; } else scheme_raise_exn(MZEXN_FAIL_FILESYSTEM_EXISTS, "%s: file \"%q\" exists", name, filename); @@ -4430,9 +4432,9 @@ scheme_do_open_output_file(char *name, int offset, int argc, Scheme_Object *argv if (fd == INVALID_HANDLE_VALUE) { if (err) { *err = "cannot open destination"; - *eerrno = err; + *eerrno = errv; } else - filename_exn(name, "cannot open output file", filename, err); + filename_exn(name, "cannot open output file", filename, errv); return NULL; } }