summaryrefslogtreecommitdiff
path: root/cpp/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/main.c')
-rw-r--r--cpp/main.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/cpp/main.c b/cpp/main.c
index 0cbdaa3..dfe0e5c 100644
--- a/cpp/main.c
+++ b/cpp/main.c
@@ -7,6 +7,7 @@
#include <ctype.h>
#include <string.h>
#include <malloc.h>
+#include <time.h>
#include "cc.h"
@@ -138,6 +139,22 @@ static char Usage[] = "Usage: cpp -E -0 -Dxxx -Uxxx -Ixxx infile -o outfile";
if (!curfile)
cfatal(Usage);
+ /* Define date and time macros. */
+ if (dialect != DI_KNR) {
+ time_t now;
+ char * timep;
+ char buf[128];
+ time(&now);
+ timep = ctime(&now);
+
+ /* Yes, well */
+ sprintf(buf, "__TIME__=\"%.8s\"", timep + 11);
+ define_macro(buf);
+ /* US order; Seems to be mandated by standard. */
+ sprintf(buf, "__DATE__=\"%.3s %.2s %.4s\"", timep + 4, timep + 8, timep + 20);
+ define_macro(buf);
+ }
+
if (outfile) ofd = fopen(outfile, "w");
else ofd = stdout;
if (!ofd)