ardour
localtime_r.cc
Go to the documentation of this file.
1 #ifdef WAF_BUILD
2 #include "libpbd-config.h"
3 #endif
4 
5 #ifndef HAVE_LOCALTIME_R
6 #include <time.h>
7 #include <string.h>
8 
9 #include "pbd/pthread_utils.h"
10 #include "pbd/localtime_r.h"
11 
12 #ifdef localtime_r
13 #undef localtime_r
14 #endif
15 
16 struct tm *
17 localtime_r(const time_t *const timep, struct tm *p_tm)
18 {
19  static pthread_mutex_t time_mutex;
20  static int time_mutex_inited = 0;
21  struct tm *tmp;
22 
23  if (!time_mutex_inited)
24  {
25  time_mutex_inited = 1;
26  pthread_mutex_init(&time_mutex, NULL);
27  }
28 
29  pthread_mutex_lock(&time_mutex);
30  tmp = localtime(timep);
31  if (tmp)
32  {
33  memcpy(p_tm, tmp, sizeof(struct tm));
34  tmp = p_tm;
35  }
36  pthread_mutex_unlock(&time_mutex);
37 
38  return tmp;
39 }
40 
41 #endif
42 
43 #ifdef __MINGW64__
44  struct tm *
45 __cdecl localtime(const long int *_Time)
46 {
47  if (_Time == NULL)
48  {
49  return localtime((const time_t *const)NULL); // Unpredictable behavior in case of _Time == NULL;
50  }
51  else
52  {
53  const time_t tempTime = *_Time;
54  return localtime(&tempTime);
55  }
56 }
57 #endif
struct tm * localtime_r(const time_t *const timep, struct tm *p_tm)
Definition: localtime_r.cc:17