exit(1);
}
+#ifdef _WIN32
+void
+stderr_last_error(char *msg)
+{
+ LPSTR buf = NULL;
+ DWORD err = GetLastError();
+
+ if (!FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)&buf,
+ 0, NULL)) {
+ fprintf(stderr, "\n%s: [0x%08x]\n", msg, err);
+ }
+ else {
+ fprintf(stderr, "\n%s: [0x%08x] %s\n", msg, err, buf);
+ }
+}
+#endif
+
/*****************/
/* OS Allocation */
/*****************/
if (ptr == NULL) {
#if ZEND_MM_ERROR
- fprintf(stderr, "\nVirtualAlloc() failed: [%d]\n", GetLastError());
+ stderr_last_error("VirtualAlloc() failed");
#endif
return NULL;
}
#ifdef _WIN32
if (VirtualFree(addr, 0, MEM_RELEASE) == 0) {
#if ZEND_MM_ERROR
- fprintf(stderr, "\nVirtualFree() failed: [%d]\n", GetLastError());
+ stderr_last_error("VirtualFree() failed");
#endif
}
#else
if (UNEXPECTED(chunk == NULL)) {
#if ZEND_MM_ERROR
+#ifdef _WIN32
+ stderr_last_error("Can't initialize heap");
+#else
fprintf(stderr, "\nCan't initialize heap: [%d] %s\n", errno, strerror(errno));
+#endif
#endif
return NULL;
}