Skip to content

Commit

Permalink
Merge pull request #467 from Jafaral/time
Browse files Browse the repository at this point in the history
detect and use thread-safe time functions
  • Loading branch information
Jafaral authored May 30, 2024
2 parents 7163279 + e3adbc8 commit 43da610
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
60 changes: 2 additions & 58 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -7233,7 +7233,8 @@ fi
for ac_func in socket bcopy bzero memcpy memset inet_aton inet_pton \
snprintf vsprintf rename ftruncate flock fsync \
getrlimit setrlimit strerror vfork \
getrusage sysconf profil getenv_r
getrusage sysconf profil getenv_r clock_gettime \
ctime_r asctime_r gmtime_r localtime_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"
Expand Down Expand Up @@ -7782,63 +7783,6 @@ $as_echo "#define HAVE_GETADDRINFO 1" >>confdefs.h

fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing clock_gettime" >&5
$as_echo_n "checking for library containing clock_gettime... " >&6; }
if ${ac_cv_search_clock_gettime+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char clock_gettime ();
int
main ()
{
return clock_gettime ();
;
return 0;
}
_ACEOF
for ac_lib in '' rt; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_clock_gettime=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_clock_gettime+:} false; then :
break
fi
done
if ${ac_cv_search_clock_gettime+:} false; then :

else
ac_cv_search_clock_gettime=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_clock_gettime" >&5
$as_echo "$ac_cv_search_clock_gettime" >&6; }
ac_res=$ac_cv_search_clock_gettime
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"

$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h

fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing crypt" >&5
$as_echo_n "checking for library containing crypt... " >&6; }
Expand Down
6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ fi
AC_CHECK_FUNCS([socket bcopy bzero memcpy memset inet_aton inet_pton \
snprintf vsprintf rename ftruncate flock fsync \
getrlimit setrlimit strerror vfork \
getrusage sysconf profil getenv_r])
getrusage sysconf profil getenv_r clock_gettime \
ctime_r asctime_r gmtime_r localtime_r])

AC_FUNC_STRERROR_R()

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

AC_SEARCH_LIBS([getaddrinfo],[socket],
[AC_DEFINE([HAVE_GETADDRINFO], [1], [getaddinfo])])
AC_SEARCH_LIBS([clock_gettime],[rt],
[AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [gettime])])

AC_SEARCH_LIBS([crypt],[crypt],
[AC_DEFINE([HAVE_CRYPT], [1], [crypt])])

Expand Down
14 changes: 13 additions & 1 deletion src/h/auto.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,24 @@
/* Define to 1 if you have the <arpa/inet.h> header file. */
#undef HAVE_ARPA_INET_H

/* Define to 1 if you have the `asctime_r' function. */
#undef HAVE_ASCTIME_R

/* Define to 1 if you have the `bcopy' function. */
#undef HAVE_BCOPY

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

/* gettime */
/* Define to 1 if you have the `clock_gettime' function. */
#undef HAVE_CLOCK_GETTIME

/* crypt */
#undef HAVE_CRYPT

/* Define to 1 if you have the `ctime_r' function. */
#undef HAVE_CTIME_R

/* Define if you have the external `daylight' variable. */
#undef HAVE_DAYLIGHT

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

/* Define to 1 if you have the `gmtime_r' function. */
#undef HAVE_GMTIME_R

/* Define to 1 if you have the `inet_aton' function. */
#undef HAVE_INET_ATON

Expand Down Expand Up @@ -224,6 +233,9 @@
/* Define to 1 if you lib z */
#undef HAVE_LIBZ

/* Define to 1 if you have the `localtime_r' function. */
#undef HAVE_LOCALTIME_R

/* Define to 1 if you have the `memcpy' function. */
#undef HAVE_MEMCPY

Expand Down
4 changes: 3 additions & 1 deletion src/runtime/fxposix.ri
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,9 @@ function{0,1} name(t)
inline {
int l;
char *p;
#if HAVE_CTIME_R || HAVE_GMTIME_R
char buf[32];
#endif /* HAVE_CTIME_R || HAVE_GMTIME_R */
#if i
#if HAVE_CTIME_R
if ((p = ctime_r((time_t *)&t, buf)) == NULL) runerr(0);
Expand All @@ -1755,7 +1758,6 @@ function{0,1} name(t)
#else
#if HAVE_GMTIME_R && HAVE_ASCTIME_R
{
char buf[32];
struct tm gmt;
if (gmtime_r((time_t *)&t, &gmt) == NULL) runerr(0);
if ((p = asctime_r(&gmt, buf)) == NULL) runerr(0);
Expand Down

0 comments on commit 43da610

Please sign in to comment.