[cairo] [PATCH] win32: Correct missing file handling in Windows 7

Brent Fulgham bfulgham at gmail.com
Tue Feb 8 12:42:58 PST 2011


I'm not sure if this is a change in Windows Vista/Windows 7, or if
this has always failed.  However, the POSIX 'unlink' in the MSVCRT
library behaves differently from Linux and other platforms.  Instead
of returning ENOENT when a file is missing, it sets a last error value
of "ERROR_FILE_NOT_FOUND", and sets (for some reason) 'errno' to
EILSEQ.

This prevents the tests from running.

Proposed patch:

*** cairo-1.10.2/test/cairo-test.c	2010-07-12 01:57:03.000000000 -0700
--- cairo-1.10.2.new/test/cairo-test.c	2011-02-08 12:36:44.682423300 -0800
***************
*** 73,78 ****
--- 73,79 ----

  #ifdef _MSC_VER
  #include <crtdbg.h>
+ #include <windows.h>
  #define vsnprintf _vsnprintf
  #define access _access
  #define F_OK 0
***************
*** 322,330 ****
--- 323,355 ----
  static void
  _xunlink (const cairo_test_context_t *ctx, const char *pathname)
  {
+ #ifdef _WIN32
+     if (!DeleteFileA (pathname)) {
+         void *lpMsgBuf;
+         DWORD last_error = GetLastError ();
+         if (ERROR_FILE_NOT_FOUND == last_error)
+             return;
+
+         if (!FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                 FORMAT_MESSAGE_FROM_SYSTEM,
+                 NULL,
+                 last_error,
+                 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+                 (LPWSTR) &lpMsgBuf,
+                 0, NULL)) {
+             cairo_test_log (ctx, "Error: Cannot remove %s: %s\n",
+                 pathname, strerror (errno));
+         } else {
+             fwprintf (stderr, L"Error: Cannot remove %s: %S", pathname,
+                 (wchar_t *)lpMsgBuf);
+
+             LocalFree (lpMsgBuf);
+         }
+ #else
      if (unlink (pathname) < 0 && errno != ENOENT) {
          cairo_test_log (ctx, "Error: Cannot remove %s: %s\n",
              pathname, strerror (errno));
+ #endif
          exit (1);
      }
  }


More information about the cairo mailing list