Add null checks to <dirent.h> functions.

Move all the new checks over to the existing __fortify_fatal.

Bug: http://b/67455242
Test: ran tests
Change-Id: Idb899c58c32d52d3b423caf1a91feb7defcba9b3
diff --git a/libc/stdio/fread.c b/libc/stdio/fread.cpp
similarity index 98%
rename from libc/stdio/fread.c
rename to libc/stdio/fread.cpp
index b6a3077..073f71a 100644
--- a/libc/stdio/fread.c
+++ b/libc/stdio/fread.cpp
@@ -79,7 +79,7 @@
 		__smakebuf(fp);
 	}
 
-	char* dst = buf;
+	char* dst = static_cast<char*>(buf);
 
 	while (total > 0) {
 		/*
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index 02ea8f8..c728eec 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -39,7 +39,9 @@
 #include <stdbool.h>
 #include <wchar.h>
 
-#include <async_safe/log.h>
+#if defined(__cplusplus) // Until we fork all of stdio...
+#include "private/bionic_fortify.h"
+#endif
 
 #include "wcio.h"
 
@@ -257,11 +259,6 @@
 
 // Sanity check a FILE* for nullptr, so we can emit a message while crashing
 // instead of doing a blind null-dereference.
-#define CHECK_FP(fp)                                                       \
-  do {                                                                     \
-    if (__predict_false(fp == 0)) {                                        \
-      async_safe_fatal("invalid FILE* %p passed to %s", fp, __FUNCTION__); \
-    }                                                                      \
-  } while (0)
+#define CHECK_FP(fp) if (fp == nullptr) __fortify_fatal("%s: null FILE*", __FUNCTION__)
 
 #endif