summaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2011-01-27 20:22:37 +0000
committerjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2011-01-27 20:22:37 +0000
commit901f3c7ad40b376520dac5c6a48e74714b83a3c3 (patch)
tree42a335833e2d4efc567b9ade20864d521a8aed79 /libgfortran
parent57f34837f6251c10a7b3b0eaced7f5cc92b5d948 (diff)
downloadgcc-901f3c7ad40b376520dac5c6a48e74714b83a3c3.tar.gz
Pr 47431 CTIME/FDATE thread-safety using ctime_r()
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@169338 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog12
-rw-r--r--libgfortran/config.h.in3
-rwxr-xr-xlibgfortran/configure2
-rw-r--r--libgfortran/configure.ac2
-rw-r--r--libgfortran/intrinsics/ctime.c31
5 files changed, 42 insertions, 8 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index c096acfbb00..2515ca5e38a 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,5 +1,17 @@
2011-01-27 Janne Blomqvist <jb@gcc.gnu.org>
+ PR libfortran/47431
+ * config.h.in: Regenerated.
+ * configure: Regenerated.
+ * configure.ac: Add check for ctime_r().
+ * intrinsics/ctime.c (ctime_r): Fallback implementation.
+ (fdate): Use ctime_r() instead of ctime().
+ (fdate_sub): Likewise.
+ (ctime): Likewise.
+ (ctime_sub): Likewise.
+
+2011-01-27 Janne Blomqvist <jb@gcc.gnu.org>
+
PR libfortran/47432
* config.h.in: Regenerated.
* configure: Regenerated.
diff --git a/libgfortran/config.h.in b/libgfortran/config.h.in
index 65414c75fc6..913628cf09b 100644
--- a/libgfortran/config.h.in
+++ b/libgfortran/config.h.in
@@ -318,6 +318,9 @@
/* Define to 1 if you have the `ctime' function. */
#undef HAVE_CTIME
+/* Define to 1 if you have the `ctime_r' function. */
+#undef HAVE_CTIME_R
+
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
diff --git a/libgfortran/configure b/libgfortran/configure
index 836dfdc05e3..b87210675a4 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -16367,7 +16367,7 @@ _ACEOF
fi
done
-for ac_func in localtime_r gmtime_r strerror_r getpwuid_r ttyname_r
+for ac_func in localtime_r gmtime_r strerror_r getpwuid_r ttyname_r ctime_r
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 87d2340ab6c..e8f842cf7f8 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -251,7 +251,7 @@ AC_CHECK_FUNCS(chdir strerror getlogin gethostname kill link symlink perror)
AC_CHECK_FUNCS(sleep time ttyname signal alarm ctime clock access fork execl)
AC_CHECK_FUNCS(wait setmode execvp pipe dup2 close fdopen strcasestr getrlimit)
AC_CHECK_FUNCS(gettimeofday stat fstat lstat getpwuid vsnprintf dup getcwd)
-AC_CHECK_FUNCS(localtime_r gmtime_r strerror_r getpwuid_r ttyname_r)
+AC_CHECK_FUNCS(localtime_r gmtime_r strerror_r getpwuid_r ttyname_r ctime_r)
# Check for glibc backtrace functions
AC_CHECK_FUNCS(backtrace backtrace_symbols)
diff --git a/libgfortran/intrinsics/ctime.c b/libgfortran/intrinsics/ctime.c
index 98bf29d7d21..2729616bff0 100644
--- a/libgfortran/intrinsics/ctime.c
+++ b/libgfortran/intrinsics/ctime.c
@@ -1,8 +1,8 @@
/* Implementation of the CTIME and FDATE g77 intrinsics.
- Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2007, 2009, 2011 Free Software Foundation, Inc.
Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
-This file is part of the GNU Fortran 95 runtime library (libgfortran).
+This file is part of the GNU Fortran runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
@@ -41,6 +41,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <string.h>
+#ifndef HAVE_CTIME_R
+static char *
+ctime_r (const time_t * timep, char * buf __attribute__((unused)))
+{
+#ifdef HAVE_CTIME
+ return ctime (timep);
+#else
+ return NULL;
+#endif
+}
+#endif
+
+/* ctime_r() buffer size needs to be at least 26 bytes. */
+#define CSZ 26
+
extern void fdate (char **, gfc_charlen_type *);
export_proto(fdate);
@@ -48,9 +63,10 @@ void
fdate (char ** date, gfc_charlen_type * date_len)
{
#if defined(HAVE_TIME) && defined(HAVE_CTIME)
+ char cbuf[CSZ];
int i;
time_t now = time(NULL);
- *date = ctime (&now);
+ *date = ctime_r (&now, cbuf);
if (*date != NULL)
{
*date = strdup (*date);
@@ -79,6 +95,7 @@ void
fdate_sub (char * date, gfc_charlen_type date_len)
{
#if defined(HAVE_TIME) && defined(HAVE_CTIME)
+ char cbuf[CSZ];
int i;
char *d;
time_t now = time(NULL);
@@ -86,7 +103,7 @@ fdate_sub (char * date, gfc_charlen_type date_len)
memset (date, ' ', date_len);
#if defined(HAVE_TIME) && defined(HAVE_CTIME)
- d = ctime (&now);
+ d = ctime_r (&now, cbuf);
if (d != NULL)
{
i = 0;
@@ -105,9 +122,10 @@ void
PREFIX(ctime) (char ** date, gfc_charlen_type * date_len, GFC_INTEGER_8 t)
{
#if defined(HAVE_CTIME)
+ char cbuf[CSZ];
time_t now = t;
int i;
- *date = ctime (&now);
+ *date = ctime_r (&now, cbuf);
if (*date != NULL)
{
*date = strdup (*date);
@@ -136,6 +154,7 @@ void
ctime_sub (GFC_INTEGER_8 * t, char * date, gfc_charlen_type date_len)
{
#if defined(HAVE_CTIME)
+ char cbuf[CSZ];
int i;
char *d;
time_t now = *t;
@@ -143,7 +162,7 @@ ctime_sub (GFC_INTEGER_8 * t, char * date, gfc_charlen_type date_len)
memset (date, ' ', date_len);
#if defined(HAVE_CTIME)
- d = ctime (&now);
+ d = ctime_r (&now, cbuf);
if (d != NULL)
{
i = 0;