summaryrefslogtreecommitdiff
path: root/libcpp/macro.c
diff options
context:
space:
mode:
authordalecki <dalecki@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-18 09:25:31 +0000
committerdalecki <dalecki@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-18 09:25:31 +0000
commitcca5dddcda2bd7053ca800e0f33bd2e6676ee3df (patch)
tree7042da2d52f0b0578ba88e4df4ca0cbceeee00ab /libcpp/macro.c
parent4b4581752338623a2d4a9ec3b00b7c253e528c1f (diff)
downloadgcc-cca5dddcda2bd7053ca800e0f33bd2e6676ee3df.tar.gz
2006-02-17 Grigory Zagorodnev <grigory_zagorodnev@linux.intel.com>
gcc/ChangeLog: * doc/cpp.texi (__TIMESTAMP__): Document. libcpp/ChangeLog: * macro.c (_cpp_builtin_macro_text): Handle BT_TIMESTAMP. * files.c (_cpp_get_file_stat): New function. * include/cpplib.h (builtin_type): Add BT_TIMESTAMP. * init.c (builtin_array): Add support for __TIMESTAMP__/BT_TIMESTAMP. * internal.h (_cpp_get_file_stat): Prototype. (struct cpp_buffer): Add timestamp. gcc/testsuite/ChangeLog: * gcc.dg/cpp/undef3.c: New test. * gcc.dg/cpp/trad/builtins2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111232 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp/macro.c')
-rw-r--r--libcpp/macro.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 3204e553b02..67e936ee31a 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -123,6 +123,44 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
NODE_NAME (node));
break;
+ case BT_TIMESTAMP:
+ {
+ cpp_buffer *pbuffer = cpp_get_buffer (pfile);
+ if (pbuffer->timestamp == NULL)
+ {
+ /* Initialize timestamp value of the assotiated file. */
+ struct _cpp_file *file = cpp_get_file (pbuffer);
+ if (file)
+ {
+ /* Generate __TIMESTAMP__ string, that represents
+ the date and time of the last modification
+ of the current source file. The string constant
+ looks like "Sun Sep 16 01:03:52 1973". */
+ struct tm *tb = NULL;
+ struct stat *st = _cpp_get_file_stat (file);
+ if (st)
+ tb = localtime (&st->st_mtime);
+ if (tb)
+ {
+ char *str = asctime (tb);
+ size_t len = strlen (str);
+ unsigned char *buf = _cpp_unaligned_alloc (pfile, len + 2);
+ buf[0] = '"';
+ strcpy ((char *) buf + 1, str);
+ buf[len] = '"';
+ pbuffer->timestamp = buf;
+ }
+ else
+ {
+ cpp_errno (pfile, CPP_DL_WARNING,
+ "could not determine file timestamp");
+ pbuffer->timestamp = U"\"??? ??? ?? ??:??:?? ????\"";
+ }
+ }
+ }
+ result = pbuffer->timestamp;
+ }
+ break;
case BT_FILE:
case BT_BASE_FILE:
{