>From 4f92a69f4f97b2de932d7a2cdebd9722432f2d19 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 12 Jun 2017 20:38:49 -0700
Subject: [PATCH 2/4] Remove some dependencies

localtime.c and difftime.c do not need stdio to compile, so remove
those dependencies.  This makes the runtime more portable to
freestanding implementations that lack stdio.  Similarly, remove
the sys/wait dependencies for .c files other than zic.c.
* NEWS: Mention this.
* asctime.c, date.c, strftime.c, zdump.c, zic.c: Include <stdio.h>.
* private.h: Do not include <stdio.h> or <sys/wait.h>.
Move declarations of WIFEXITED and WEXITSTATUS to zic.c.
(F_OK): Remove; unused.
* zic.c: Include <sys/wait.h>.
---
 NEWS       |  3 +++
 asctime.c  |  1 +
 date.c     |  1 +
 private.h  | 17 +----------------
 strftime.c |  1 +
 zdump.c    |  1 +
 zic.c      | 12 ++++++++++++
 7 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/NEWS b/NEWS
index 40285bf..0aa2e3f 100644
--- a/NEWS
+++ b/NEWS
@@ -83,6 +83,9 @@ Unreleased, experimental changes
 
     Y2K runtime checks have been removed, as Y2K was years ago.
 
+    localtime.c and difftime.c no longer require stdio.h, and .c files
+    other than zic.c no longer require sys/wait.h.
+
     Several minor changes have been made to the code to make it a
     bit easier to port to MS-Windows and Solaris.  (Thanks to Kees
     Dekker for reporting the problems.)
diff --git a/asctime.c b/asctime.c
index de681ce..edd6875 100644
--- a/asctime.c
+++ b/asctime.c
@@ -12,6 +12,7 @@
 /*LINTLIBRARY*/
 
 #include "private.h"
+#include <stdio.h>
 
 /*
 ** Some systems only handle "%.2d"; others only handle "%02d";
diff --git a/date.c b/date.c
index 0d64b8a..b29e162 100644
--- a/date.c
+++ b/date.c
@@ -29,6 +29,7 @@
 
 #include "private.h"
 #include <locale.h>
+#include <stdio.h>
 
 /*
 ** The two things date knows about time are. . .
diff --git a/private.h b/private.h
index 0e8cfda..e6cb21d 100644
--- a/private.h
+++ b/private.h
@@ -109,7 +109,6 @@
 #undef tzfree
 
 #include <sys/types.h>	/* for time_t */
-#include <stdio.h>
 #include <string.h>
 #include <limits.h>	/* for CHAR_BIT et al. */
 #include <stdlib.h>
@@ -130,19 +129,8 @@
 #include <libintl.h>
 #endif /* HAVE_GETTEXT */
 
-#if HAVE_SYS_WAIT_H
-#include <sys/wait.h>	/* for WIFEXITED and WEXITSTATUS */
-#endif /* HAVE_SYS_WAIT_H */
-
-#ifndef WIFEXITED
-#define WIFEXITED(status)	(((status) & 0xff) == 0)
-#endif /* !defined WIFEXITED */
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(status)	(((status) >> 8) & 0xff)
-#endif /* !defined WEXITSTATUS */
-
 #if HAVE_UNISTD_H
-#include <unistd.h>	/* for F_OK, R_OK, and other POSIX goodness */
+#include <unistd.h>	/* for R_OK, and other POSIX goodness */
 #endif /* HAVE_UNISTD_H */
 
 #ifndef HAVE_STRFTIME_L
@@ -169,9 +157,6 @@
 # endif
 #endif
 
-#ifndef F_OK
-#define F_OK	0
-#endif /* !defined F_OK */
 #ifndef R_OK
 #define R_OK	4
 #endif /* !defined R_OK */
diff --git a/strftime.c b/strftime.c
index 9df4176..76d3342 100644
--- a/strftime.c
+++ b/strftime.c
@@ -37,6 +37,7 @@
 
 #include <fcntl.h>
 #include <locale.h>
+#include <stdio.h>
 
 struct lc_time_T {
 	const char *	mon[MONSPERYEAR];
diff --git a/zdump.c b/zdump.c
index b69b1e9..38a13bc 100644
--- a/zdump.c
+++ b/zdump.c
@@ -20,6 +20,7 @@
 #endif
 
 #include "private.h"
+#include <stdio.h>
 
 #ifndef HAVE_LOCALTIME_R
 # define HAVE_LOCALTIME_R 1
diff --git a/zic.c b/zic.c
index ff71af6..300d563 100644
--- a/zic.c
+++ b/zic.c
@@ -11,6 +11,7 @@
 #include <locale.h>
 #include <stdarg.h>
 #include <stddef.h>
+#include <stdio.h>
 
 #define	ZIC_VERSION_PRE_2013 '2'
 #define	ZIC_VERSION	'3'
@@ -41,6 +42,17 @@ typedef int_fast64_t	zic_t;
 #define MKDIR_UMASK 0755
 #endif
 
+#if HAVE_SYS_WAIT_H
+#include <sys/wait.h>	/* for WIFEXITED and WEXITSTATUS */
+#endif /* HAVE_SYS_WAIT_H */
+
+#ifndef WIFEXITED
+#define WIFEXITED(status)	(((status) & 0xff) == 0)
+#endif /* !defined WIFEXITED */
+#ifndef WEXITSTATUS
+#define WEXITSTATUS(status)	(((status) >> 8) & 0xff)
+#endif /* !defined WEXITSTATUS */
+
 /* The maximum ptrdiff_t value, for pre-C99 platforms.  */
 #ifndef PTRDIFF_MAX
 static ptrdiff_t const PTRDIFF_MAX = MAXVAL(ptrdiff_t, TYPE_BIT(ptrdiff_t));
-- 
2.9.4

