From 845d69187a4bbe26c1c1cc67735a0c3b01b1d2d2 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sat, 4 Jul 2020 04:00:01 +0200
Subject: [PATCH] getrandom: Fix compilation error on native Windows
 (regression from 2020-06-28).

* lib/getrandom.c: Don't include <ntdef.h>. Instead, define NTSTATUS.
* m4/getrandom.m4 (gl_FUNC_GETRANDOM): Include <windows.h> before
<bcrypt.h>.
---
 ChangeLog       | 7 +++++++
 lib/getrandom.c | 2 +-
 m4/getrandom.m4 | 6 ++++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 080f9e8342..59897eff6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-07-03  Bruno Haible  <bruno@clisp.org>
+
+	getrandom: Fix compilation error on native Windows (regr. 2020-06-28).
+	* lib/getrandom.c: Don't include <ntdef.h>. Instead, define NTSTATUS.
+	* m4/getrandom.m4 (gl_FUNC_GETRANDOM): Include <windows.h> before
+	<bcrypt.h>.
+
 2020-07-03  Bruno Haible  <bruno@clisp.org>
 
 	dfa tests: Follow common file naming conventions.
diff --git a/lib/getrandom.c b/lib/getrandom.c
index 030a78bb08..f8695abf30 100644
--- a/lib/getrandom.c
+++ b/lib/getrandom.c
@@ -32,7 +32,7 @@
 # if HAVE_BCRYPT_H
 #  include <bcrypt.h>
 # else
-#  include <ntdef.h> /* NTSTATUS */
+#  define NTSTATUS LONG
 typedef void * BCRYPT_ALG_HANDLE;
 #  define BCRYPT_USE_SYSTEM_PREFERRED_RNG 0x00000002
 #  if HAVE_LIB_BCRYPT
diff --git a/m4/getrandom.m4 b/m4/getrandom.m4
index 2a0034bf76..424c2fad3e 100644
--- a/m4/getrandom.m4
+++ b/m4/getrandom.m4
@@ -1,4 +1,4 @@
-# getrandom.m4 serial 6
+# getrandom.m4 serial 7
 dnl Copyright 2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -36,7 +36,9 @@ AC_DEFUN([gl_FUNC_GETRANDOM],
 
   case "$host_os" in
     mingw*)
-      AC_CHECK_HEADERS([bcrypt.h])
+      AC_CHECK_HEADERS([bcrypt.h], [], [],
+        [[#include <windows.h>
+        ]])
       AC_CACHE_CHECK([whether the bcrypt library is guaranteed to be present],
         [gl_cv_lib_assume_bcrypt],
         [AC_COMPILE_IFELSE(
-- 
2.39.5