diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-08-02 04:18:16 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-08-02 04:18:16 +0000 |
commit | 3385506fe73e94274312eb1696ff3b965bdd368b (patch) | |
tree | c63ec9dce2bc93a6a52925534a75b6d065be7679 /gcc/cppmacro.c | |
parent | 9ab9d8af329b4f99b807b65efb8fd4fb4246549d (diff) | |
download | gcc-3385506fe73e94274312eb1696ff3b965bdd368b.tar.gz |
* c-common.c (c_common_init): -Wtraditional also implies -Wlong-long.
* cppinit.c (cpp_post_options): Likewise.
* cppexp.c (cpp_classify_number): Suppress -Wtraditional
warning about 'LL' suffix (but not 'ULL' etc) when
-Wno-long-long is in effect.
* cppmacro.c (_cpp_builtin_macro_text) [BT_TIME, BT_DATE]:
Check for failing time()/localtime(), issue a warning, and
make __TIME__ and __DATE__ expand to fallback strings.
* doc/cpp.texi, doc/extend.texi: Document behavior of __DATE__
and __TIME__ when the date and time cannot be determined.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55969 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppmacro.c')
-rw-r--r-- | gcc/cppmacro.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index 50cc9bbf4ba..f0986b353cb 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -207,17 +207,37 @@ _cpp_builtin_macro_text (pfile, node) storage. We only do this once, and don't generate them at init time, because time() and localtime() are very slow on some systems. */ - time_t tt = time (NULL); - struct tm *tb = localtime (&tt); - - pfile->date = _cpp_unaligned_alloc (pfile, - sizeof ("\"Oct 11 1347\"")); - sprintf ((char *) pfile->date, "\"%s %2d %4d\"", - monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900); - - pfile->time = _cpp_unaligned_alloc (pfile, sizeof ("\"12:34:56\"")); - sprintf ((char *) pfile->time, "\"%02d:%02d:%02d\"", - tb->tm_hour, tb->tm_min, tb->tm_sec); + time_t tt; + struct tm *tb = NULL; + + /* (time_t) -1 is a legitimate value for "number of seconds + since the Epoch", so we have to do a little dance to + distinguish that from a genuine error. */ + errno = 0; + tt = time(NULL); + if (tt != (time_t)-1 || errno == 0) + tb = localtime (&tt); + + if (tb) + { + pfile->date = _cpp_unaligned_alloc (pfile, + sizeof ("\"Oct 11 1347\"")); + sprintf ((char *) pfile->date, "\"%s %2d %4d\"", + monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900); + + pfile->time = _cpp_unaligned_alloc (pfile, + sizeof ("\"12:34:56\"")); + sprintf ((char *) pfile->time, "\"%02d:%02d:%02d\"", + tb->tm_hour, tb->tm_min, tb->tm_sec); + } + else + { + cpp_errno (pfile, DL_WARNING, + "could not determine date and time"); + + pfile->date = U"\"??? ?? ????\""; + pfile->time = U"\"??:??:??\""; + } } if (node->value.builtin == BT_DATE) |