Skip to content

Commit 43da610

Browse files
authored
Merge pull request uniconproject#467 from Jafaral/time
detect and use thread-safe time functions
2 parents 7163279 + e3adbc8 commit 43da610

File tree

5 files changed

+22
-64
lines changed

5 files changed

+22
-64
lines changed

.github/workflows/codeql.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
steps:
2424
- name: Checkout
25-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
2626

2727
- name: Initialize CodeQL
2828
uses: github/codeql-action/init@v3

configure

+2-58
Original file line numberDiff line numberDiff line change
@@ -7233,7 +7233,8 @@ fi
72337233
for ac_func in socket bcopy bzero memcpy memset inet_aton inet_pton \
72347234
snprintf vsprintf rename ftruncate flock fsync \
72357235
getrlimit setrlimit strerror vfork \
7236-
getrusage sysconf profil getenv_r
7236+
getrusage sysconf profil getenv_r clock_gettime \
7237+
ctime_r asctime_r gmtime_r localtime_r
72377238
do :
72387239
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
72397240
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -7782,63 +7783,6 @@ $as_echo "#define HAVE_GETADDRINFO 1" >>confdefs.h
77827783

77837784
fi
77847785

7785-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing clock_gettime" >&5
7786-
$as_echo_n "checking for library containing clock_gettime... " >&6; }
7787-
if ${ac_cv_search_clock_gettime+:} false; then :
7788-
$as_echo_n "(cached) " >&6
7789-
else
7790-
ac_func_search_save_LIBS=$LIBS
7791-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7792-
/* end confdefs.h. */
7793-
7794-
/* Override any GCC internal prototype to avoid an error.
7795-
Use char because int might match the return type of a GCC
7796-
builtin and then its argument prototype would still apply. */
7797-
#ifdef __cplusplus
7798-
extern "C"
7799-
#endif
7800-
char clock_gettime ();
7801-
int
7802-
main ()
7803-
{
7804-
return clock_gettime ();
7805-
;
7806-
return 0;
7807-
}
7808-
_ACEOF
7809-
for ac_lib in '' rt; do
7810-
if test -z "$ac_lib"; then
7811-
ac_res="none required"
7812-
else
7813-
ac_res=-l$ac_lib
7814-
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
7815-
fi
7816-
if ac_fn_c_try_link "$LINENO"; then :
7817-
ac_cv_search_clock_gettime=$ac_res
7818-
fi
7819-
rm -f core conftest.err conftest.$ac_objext \
7820-
conftest$ac_exeext
7821-
if ${ac_cv_search_clock_gettime+:} false; then :
7822-
break
7823-
fi
7824-
done
7825-
if ${ac_cv_search_clock_gettime+:} false; then :
7826-
7827-
else
7828-
ac_cv_search_clock_gettime=no
7829-
fi
7830-
rm conftest.$ac_ext
7831-
LIBS=$ac_func_search_save_LIBS
7832-
fi
7833-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_clock_gettime" >&5
7834-
$as_echo "$ac_cv_search_clock_gettime" >&6; }
7835-
ac_res=$ac_cv_search_clock_gettime
7836-
if test "$ac_res" != no; then :
7837-
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
7838-
7839-
$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h
7840-
7841-
fi
78427786

78437787
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing crypt" >&5
78447788
$as_echo_n "checking for library containing crypt... " >&6; }

configure.ac

+3-3
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,8 @@ fi
563563
AC_CHECK_FUNCS([socket bcopy bzero memcpy memset inet_aton inet_pton \
564564
snprintf vsprintf rename ftruncate flock fsync \
565565
getrlimit setrlimit strerror vfork \
566-
getrusage sysconf profil getenv_r])
566+
getrusage sysconf profil getenv_r clock_gettime \
567+
ctime_r asctime_r gmtime_r localtime_r])
567568

568569
AC_FUNC_STRERROR_R()
569570

@@ -587,8 +588,7 @@ AC_SUBST(SQLITE)
587588

588589
AC_SEARCH_LIBS([getaddrinfo],[socket],
589590
[AC_DEFINE([HAVE_GETADDRINFO], [1], [getaddinfo])])
590-
AC_SEARCH_LIBS([clock_gettime],[rt],
591-
[AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [gettime])])
591+
592592
AC_SEARCH_LIBS([crypt],[crypt],
593593
[AC_DEFINE([HAVE_CRYPT], [1], [crypt])])
594594

src/h/auto.in

+13-1
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,24 @@
4545
/* Define to 1 if you have the <arpa/inet.h> header file. */
4646
#undef HAVE_ARPA_INET_H
4747

48+
/* Define to 1 if you have the `asctime_r' function. */
49+
#undef HAVE_ASCTIME_R
50+
4851
/* Define to 1 if you have the `bcopy' function. */
4952
#undef HAVE_BCOPY
5053

5154
/* Define to 1 if you have the `bzero' function. */
5255
#undef HAVE_BZERO
5356

54-
/* gettime */
57+
/* Define to 1 if you have the `clock_gettime' function. */
5558
#undef HAVE_CLOCK_GETTIME
5659

5760
/* crypt */
5861
#undef HAVE_CRYPT
5962

63+
/* Define to 1 if you have the `ctime_r' function. */
64+
#undef HAVE_CTIME_R
65+
6066
/* Define if you have the external `daylight' variable. */
6167
#undef HAVE_DAYLIGHT
6268

@@ -113,6 +119,9 @@
113119
/* Define to 1 if you have the <GL/gl.h> header file. */
114120
#undef HAVE_GL_GL_H
115121

122+
/* Define to 1 if you have the `gmtime_r' function. */
123+
#undef HAVE_GMTIME_R
124+
116125
/* Define to 1 if you have the `inet_aton' function. */
117126
#undef HAVE_INET_ATON
118127

@@ -224,6 +233,9 @@
224233
/* Define to 1 if you lib z */
225234
#undef HAVE_LIBZ
226235

236+
/* Define to 1 if you have the `localtime_r' function. */
237+
#undef HAVE_LOCALTIME_R
238+
227239
/* Define to 1 if you have the `memcpy' function. */
228240
#undef HAVE_MEMCPY
229241

src/runtime/fxposix.ri

+3-1
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,9 @@ function{0,1} name(t)
17451745
inline {
17461746
int l;
17471747
char *p;
1748+
#if HAVE_CTIME_R || HAVE_GMTIME_R
1749+
char buf[32];
1750+
#endif /* HAVE_CTIME_R || HAVE_GMTIME_R */
17481751
#if i
17491752
#if HAVE_CTIME_R
17501753
if ((p = ctime_r((time_t *)&t, buf)) == NULL) runerr(0);
@@ -1755,7 +1758,6 @@ function{0,1} name(t)
17551758
#else
17561759
#if HAVE_GMTIME_R && HAVE_ASCTIME_R
17571760
{
1758-
char buf[32];
17591761
struct tm gmt;
17601762
if (gmtime_r((time_t *)&t, &gmt) == NULL) runerr(0);
17611763
if ((p = asctime_r(&gmt, buf)) == NULL) runerr(0);

0 commit comments

Comments
 (0)