2 * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
3 * Copyright (C) 2013 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2014 Robin Gareus <robin@gareus.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "libpbd-config.h"
25 #ifndef HAVE_LOCALTIME_R
29 #include "pbd/pthread_utils.h"
30 #include "pbd/localtime_r.h"
37 localtime_r(const time_t *const timep, struct tm *p_tm)
39 static pthread_mutex_t time_mutex;
40 static int time_mutex_inited = 0;
43 if (!time_mutex_inited)
45 time_mutex_inited = 1;
46 pthread_mutex_init(&time_mutex, NULL);
49 pthread_mutex_lock(&time_mutex);
50 tmp = localtime(timep);
53 memcpy(p_tm, tmp, sizeof(struct tm));
56 pthread_mutex_unlock(&time_mutex);
65 __cdecl localtime(const long int *_Time)
69 return localtime((const time_t *const)NULL); // Unpredictable behavior in case of _Time == NULL;
73 const time_t tempTime = *_Time;
74 return localtime(&tempTime);