Return-Path: Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Delivered-To: mailing list dev@apr.apache.org Received: (qmail 93986 invoked from network); 25 Jan 2001 17:56:20 -0000 Received: from 24-148-31-193.na.21stcentury.net (HELO newton.collab.net) (24.148.31.193) by h31.sny.collab.net with SMTP; 25 Jan 2001 17:56:20 -0000 Received: (from cmpilato@localhost) by newton.collab.net (8.9.3/8.9.3) id MAA07806; Thu, 25 Jan 2001 12:00:32 -0600 (CST) (envelope-from cmpilato) Sender: cmpilato@newton.collab.net To: dev@apr.apache.org Subject: [patch] Use of MoveFileEx() (unsupported in Win95/98) From: cmpilato@collab.net Reply-To: cmpilato@collab.net Date: 25 Jan 2001 12:00:32 -0600 Message-ID: <84bssvv7en.fsf@newton.collab.net> Lines: 66 X-Mailer: Gnus v5.7/Emacs 20.6 X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N Hoping that "cvs diff -u" is all I need to do to create unified diffs... * open.c (apr_rename_file): Replaced use of unsupported function MoveFileEx() with MoveFile() for pre-Windows NT (Win95/98) OS levels. This may require a look-see in the future, but adds functionality where none was present. Index: open.c =================================================================== RCS file: /home/cvspublic/apr/file_io/win32/open.c,v retrieving revision 1.65 diff -u -r1.65 open.c --- open.c 2001/01/25 15:33:58 1.65 +++ open.c 2001/01/25 17:39:22 @@ -340,10 +340,10 @@ const char *topath, apr_pool_t *cont) { -#if APR_HAS_UNICODE_FS apr_oslevel_e os_level; if (!apr_get_oslevel(cont, &os_level) && os_level >= APR_WIN_NT) { +#if APR_HAS_UNICODE_FS apr_wchar_t wfrompath[APR_PATH_MAX], wtopath[APR_PATH_MAX]; apr_status_t rv; if (rv = utf8_to_unicode_path(wfrompath, sizeof(wfrompath) @@ -357,12 +357,32 @@ if (MoveFileExW(wfrompath, wtopath, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED)) return APR_SUCCESS; - } - else -#endif +#else if (MoveFileEx(frompath, topath, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED)) return APR_SUCCESS; +#endif + } + else + { + /* Windows 95 and 98 do not support MoveFileEx, so we'll use + * the old MoveFile function. However, MoveFile requires that + * the new file not already exist...so we have to delete that + * file if it does. Perhaps we should back up the to-be-deleted + * file in case something happens? + */ + HANDLE handle = INVALID_HANDLE_VALUE; + + if ((handle = CreateFile(topath, GENERIC_WRITE, 0, 0, 0, + OPEN_EXISTING, 0 )) != INVALID_HANDLE_VALUE ) + { + CloseHandle(handle); + if (!DeleteFile(topath)) + return apr_get_os_error(); + } + if (MoveFile(frompath, topath)) + return APR_SUCCESS; + } return apr_get_os_error(); }