The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use POSIX thread-safe gmtime_r and localtime_r

- https://pubs.opengroup.org/onlinepubs/9799919799/functions/gmtime_r.html
- https://pubs.opengroup.org/onlinepubs/9799919799/functions/localtime_r.html

+24 -7
+5
configure
··· 3173 3173 as_fn_append ac_func_c_list " getgrgid_r HAVE_GETGRGID_R" 3174 3174 as_fn_append ac_func_c_list " getpwnam_r HAVE_GETPWNAM_R" 3175 3175 as_fn_append ac_func_c_list " getpwuid_r HAVE_GETPWUID_R" 3176 + as_fn_append ac_func_c_list " gmtime_r HAVE_GMTIME_R" 3177 + as_fn_append ac_func_c_list " localtime_r HAVE_LOCALTIME_R" 3176 3178 3177 3179 # Auxiliary files required by this configure script. 3178 3180 ac_aux_files="install-sh ltmain.sh config.guess config.sub" ··· 21281 21283 printf "%s\n" "#define HAS_MKTIME 1" >>confdefs.h 21282 21284 21283 21285 fi 21286 + 21287 + 21288 + 21284 21289 21285 21290 21286 21291 ## setsid
+1
configure.ac
··· 2415 2415 ## mktime 2416 2416 2417 2417 AC_CHECK_FUNC([mktime], [AC_DEFINE([HAS_MKTIME], [1])]) 2418 + AC_CHECK_FUNCS_ONCE([gmtime_r localtime_r]) 2418 2419 2419 2420 ## setsid 2420 2421
+15 -7
otherlibs/unix/gmtime.c
··· 21 21 #include <time.h> 22 22 #include <errno.h> 23 23 24 - static value alloc_tm(struct tm *tm) 24 + static value alloc_tm(const struct tm *tm) 25 25 { 26 26 value res; 27 27 res = caml_alloc_small(9, 0); ··· 39 39 40 40 CAMLprim value caml_unix_gmtime(value t) 41 41 { 42 - time_t clock; 42 + time_t clock = (time_t) Double_val(t); 43 43 struct tm * tm; 44 - clock = (time_t) Double_val(t); 44 + #ifdef HAVE_GMTIME_R 45 + struct tm result; 46 + tm = gmtime_r(&clock, &result); 47 + #else 45 48 tm = gmtime(&clock); 46 - if (tm == NULL) caml_unix_error(EINVAL, "gmtime", Nothing); 49 + #endif 50 + if (tm == NULL) caml_uerror("gmtime", Nothing); 47 51 return alloc_tm(tm); 48 52 } 49 53 50 54 CAMLprim value caml_unix_localtime(value t) 51 55 { 52 - time_t clock; 56 + time_t clock = (time_t) Double_val(t); 53 57 struct tm * tm; 54 - clock = (time_t) Double_val(t); 58 + #ifdef HAVE_LOCALTIME_R 59 + struct tm result; 60 + tm = localtime_r(&clock, &result); 61 + #else 55 62 tm = localtime(&clock); 56 - if (tm == NULL) caml_unix_error(EINVAL, "localtime", Nothing); 63 + #endif 64 + if (tm == NULL) caml_uerror("localtime", Nothing); 57 65 return alloc_tm(tm); 58 66 } 59 67
+3
runtime/caml/s.h.in
··· 226 226 227 227 /* Define HAS_MKTIME if you have mktime(). */ 228 228 229 + #undef HAVE_GMTIME_R 230 + #undef HAVE_LOCALTIME_R 231 + 229 232 #undef HAS_SETSID 230 233 231 234 /* Define HAS_SETSID if you have setsid(). */