From 0a85d7ddf9ac9769277e6cc007f4f4d4d32a1fd1 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 25 Feb 2017 12:23:16 +0100 Subject: [PATCH] Make localtime_r portable for windows --- defines.h | 4 ++++ log.cc | 2 +- media.cc | 2 +- vepg.cc | 12 ++++++------ vepglistadvanced.cc | 10 +++++----- vepgsettimer.cc | 8 ++++---- vradiorec.cc | 2 +- vrecordinglistadvanced.cc | 4 ++-- vrecordinglistclassic.cc | 2 +- vtimeredit.cc | 4 ++-- vtimerlist.cc | 4 ++-- vvideolivetv.cc | 4 ++-- vvideomedia.cc | 3 ++- vvideorec.cc | 2 +- vwelcome.cc | 3 ++- 15 files changed, 36 insertions(+), 30 deletions(-) diff --git a/defines.h b/defines.h index ca9a1ee..18048a4 100644 --- a/defines.h +++ b/defines.h @@ -67,6 +67,7 @@ int getClockRealTime(struct timespec *tp); /* #define STRTOULL _strtoui64 */ #define STRTOUL strtoul #define STRTOKR strtok_s + #define LOCALTIME_R(time, tm) (localtime_s(tm,time)) #define CLOSESOCKET closesocket #define DEFAULT_TCP_WINDOWSIZE 2048 @@ -100,6 +101,9 @@ int getClockRealTime(struct timespec *tp); #define STRCASESTR strcasestr #define STRTOUL strtoul #define STRTOKR strtok_r + #define LOCALTIME_R(time, tm) (localtime_r(time, tm)) + + #define CLOSESOCKET close // add here defines for plattform specific objects diff --git a/log.cc b/log.cc index f1e8085..4da7d33 100644 --- a/log.cc +++ b/log.cc @@ -108,7 +108,7 @@ int Log::log(const char *fromModule, int level,const char* message, ...) struct timeval tv; gettimeofday(&tv, NULL); struct tm tms; - localtime_r(&tv.tv_sec, &tms); + LOCALTIME_R(&tv.tv_sec, &tms); spaceLeft -= strftime(buffer, spaceLeft, "%H:%M:%S.", &tms); spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec); #else diff --git a/media.cc b/media.cc index 3901049..d1fcd1a 100644 --- a/media.cc +++ b/media.cc @@ -232,7 +232,7 @@ char * Media::getTimeString(char * buffer) const { if (! buffer) buffer=new char[TIMEBUFLEN]; time_t tTime = (time_t)getTime(); struct tm btime; - localtime_r(&tTime, &btime); + LOCALTIME_R(&tTime, &btime); if (tTime != 0) { #ifndef _MSC_VER diff --git a/vepg.cc b/vepg.cc index bd5e4e7..689300c 100644 --- a/vepg.cc +++ b/vepg.cc @@ -220,7 +220,7 @@ void VEpg::setInfo(Event* event) int length = strlen(event->title); // calculate length of programme title string char* title = new char[length + 15]; // create string to hold start time, end time and programme title time_t eventtime = event->time; - localtime_r((time_t*)&eventtime, &btime); //get programme start time + LOCALTIME_R((time_t*)&eventtime, &btime); //get programme start time #ifndef _MSC_VER strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm - #else @@ -228,7 +228,7 @@ void VEpg::setInfo(Event* event) #endif strcpy(title, timeString); // put it in our buffer t = event->time + event->duration; //get programme end time - localtime_r(&t, &btime); + LOCALTIME_R(&t, &btime); #ifndef _MSC_VER strftime(timeString, 7, "%0H:%0M ", &btime); // and format it as hh:mm - #else @@ -569,7 +569,7 @@ void VEpg::drawgrid() // redraws grid and select programme t = ltime; struct tm tms; - localtime_r(&t, &tms); + LOCALTIME_R(&t, &tms); strftime(timeString, 19, "%a %d %b", &tms); int timey = chanListbox.getRootBoxOffsetY() - getFontHeight() - 3; int timex = 135; @@ -579,12 +579,12 @@ void VEpg::drawgrid() // redraws grid and select programme rectangle(155, timey + getFontHeight(), 2, 7, white); t = t + 3600; - localtime_r(&t, &tms); + LOCALTIME_R(&t, &tms); strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, timex + 180, timey, DrawStyle::LIGHTTEXT); // print middle time rectangle(335, timey + getFontHeight(), 2, 7, white); t = t + 3600; - localtime_r(&t, &tms); + LOCALTIME_R(&t, &tms); strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, timex + 360, timey, DrawStyle::LIGHTTEXT); // print right time rectangle(515, timey + getFontHeight(), 2, 7, white); @@ -788,7 +788,7 @@ void VEpg::paintCell(Event* event, int yOffset, const DrawStyle& bg, const DrawS time_t VEpg::prevHour(time_t* t) { struct tm tms; - localtime_r(t, &tms); + LOCALTIME_R(t, &tms); tms.tm_sec = 0; tms.tm_min = 0; return mktime(&tms); diff --git a/vepglistadvanced.cc b/vepglistadvanced.cc index e65e9ac..42450f8 100644 --- a/vepglistadvanced.cc +++ b/vepglistadvanced.cc @@ -469,9 +469,9 @@ void VEpgListAdvanced::drawDataChannel(bool doIndexPop) time_t eventStartTime = (time_t)currentEvent->time; time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration); - localtime_r(&eventStartTime, &btime); + LOCALTIME_R(&eventStartTime, &btime); strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime); - localtime_r(&eventEndTime, &btime); + LOCALTIME_R(&eventEndTime, &btime); strftime(tempB, 299, "- %H:%M ", &btime); //#endif sprintf(tempC, "\t %s\n \t \t%s%s", currentEvent->title,tempA,tempB); @@ -536,9 +536,9 @@ void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop) time_t eventStartTime = (time_t)currentEvent->time; time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration); - localtime_r(&eventStartTime, &btime); + LOCALTIME_R(&eventStartTime, &btime); strftime(tempA, 299, "%H:%M ", &btime); - localtime_r(&eventEndTime, &btime); + LOCALTIME_R(&eventEndTime, &btime); strftime(tempB, 299, "- %H:%M ", &btime); //#endif sprintf(tempC, "%s\n%s\t %s%s", currentEvent->title, chan->name,tempA,tempB); @@ -613,7 +613,7 @@ void VEpgListAdvanced::draw(bool doIndexPop) struct tm btime; time_t now; time(&now); - localtime_r(&now, &btime); + LOCALTIME_R(&now, &btime); strftime(freeSpace, 299, "%d/%m/%y", &btime); drawTextRJ(freeSpace, getWidth(), 5, DrawStyle::LIGHTTEXT); diff --git a/vepgsettimer.cc b/vepgsettimer.cc index 3f7ad7b..5c6a527 100644 --- a/vepgsettimer.cc +++ b/vepgsettimer.cc @@ -108,7 +108,7 @@ char* VEpgSetTimer::genTimerString() else strcpy(startMargin, "5"); startTime = event->time - (atoi(startMargin) * 60); - localtime_r(&startTime, &btime); + LOCALTIME_R(&startTime, &btime); strftime(dateString, 19, "%Y-%m-%d", &btime); strftime(startString, 9, "%H%M", &btime); @@ -121,7 +121,7 @@ char* VEpgSetTimer::genTimerString() else strcpy(endMargin, "5"); endTime = event->time + event->duration + (atoi(endMargin) * 60); - localtime_r(&endTime, &btime); + LOCALTIME_R(&endTime, &btime); strftime(endString, 9, "%H%M", &btime); char* priorityConfig = vdr->configLoad("Timers", "Priority"); @@ -181,7 +181,7 @@ void VEpgSetTimer::draw() struct tm btime; char timeString[10]; time_t eventtime = event->time; - localtime_r(&eventtime, &btime); + LOCALTIME_R(&eventtime, &btime); #ifndef _MSC_VER strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm - #else @@ -189,7 +189,7 @@ void VEpgSetTimer::draw() #endif strcpy(fullString, timeString); // put it in our buffer t = event->time + event->duration; //get programme end time - localtime_r(&t, &btime); + LOCALTIME_R(&t, &btime); #ifndef _MSC_VER strftime(timeString, 9, "%0H:%0M", &btime); // and format it as hh:mm - #else diff --git a/vradiorec.cc b/vradiorec.cc index b48eec1..81840d7 100644 --- a/vradiorec.cc +++ b/vradiorec.cc @@ -430,7 +430,7 @@ void VRadioRec::drawBarClocks() time_t t; time(&t); struct tm tms; - localtime_r(&t, &tms); + LOCALTIME_R(&t, &tms); strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT); diff --git a/vrecordinglistadvanced.cc b/vrecordinglistadvanced.cc index bfbf166..9007d8a 100644 --- a/vrecordinglistadvanced.cc +++ b/vrecordinglistadvanced.cc @@ -127,7 +127,7 @@ void VRecordingListAdvanced::drawData(bool doIndexPop) { currentRec = *j; time_t recStartTime = (time_t)currentRec->getStartTime(); - localtime_r(&recStartTime, &btime); + LOCALTIME_R(&recStartTime, &btime); //NMT does not like this too! //#ifndef _MSC_VER // strftime(tempA, 299, "%0d/%0m %0H:%0M ", &btime); @@ -287,7 +287,7 @@ void VRecordingListAdvanced::updateSelection() currentRec = *j; time_t recStartTime = (time_t)currentRec->getStartTime(); - localtime_r(&recStartTime, &btime); + LOCALTIME_R(&recStartTime, &btime); strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime); description<< tempA <<" "<< std::string(currentRec->getProgName()) << "\n"; diff --git a/vrecordinglistclassic.cc b/vrecordinglistclassic.cc index 82ffbb4..4e08a84 100644 --- a/vrecordinglistclassic.cc +++ b/vrecordinglistclassic.cc @@ -97,7 +97,7 @@ void VRecordingListClassic::drawData(bool doIndexPop) { currentRec = *j; time_t recStartTime = (time_t)currentRec->getStartTime(); - localtime_r(&recStartTime, &btime); + LOCALTIME_R(&recStartTime, &btime); //NMT does not like this too! //#ifndef _MSC_VER // strftime(tempA, 299, "%0d/%0m %0H:%0M ", &btime); diff --git a/vtimeredit.cc b/vtimeredit.cc index 0e8795d..f977d4d 100644 --- a/vtimeredit.cc +++ b/vtimeredit.cc @@ -120,13 +120,13 @@ void VTimerEdit::draw() // Start time_t rectime = recTimer->startTime; - localtime_r((time_t*)&rectime, &tms); + LOCALTIME_R((time_t*)&rectime, &tms); strftime(buffer, 999, "%d/%m %H:%M", &tms); drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT); ypos += fontheight; // Stop rectime = recTimer->startTime; - localtime_r((time_t*)&rectime, &tms); + LOCALTIME_R((time_t*)&rectime, &tms); strftime(buffer, 999, "%d/%m %H:%M", &tms); drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT); ypos += fontheight; diff --git a/vtimerlist.cc b/vtimerlist.cc index 29d5027..76d1280 100644 --- a/vtimerlist.cc +++ b/vtimerlist.cc @@ -151,7 +151,7 @@ bool VTimerList::load() { recTimer = (*recTimerList)[i]; time_t rectime = recTimer->startTime; - localtime_r((time_t*)&rectime, &btime); + LOCALTIME_R((time_t*)&rectime, &btime); strftime(strA, 299, "%d/%m %H:%M ", &btime); SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName()); sl.addOption(strB, (ULONG)recTimer, first); @@ -172,7 +172,7 @@ void VTimerList::drawClock() time_t t; time(&t); struct tm tms; - localtime_r(&t, &tms); + LOCALTIME_R(&t, &tms); strftime(timeString, 19, "%d/%m %H:%M:%S", &tms); drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT); diff --git a/vvideolivetv.cc b/vvideolivetv.cc index 3055f68..8255263 100644 --- a/vvideolivetv.cc +++ b/vvideolivetv.cc @@ -779,7 +779,7 @@ void VVideoLiveTV::setNowNextData() event = (*eventList)[i]; time_t etime = event->time; - localtime_r(&etime, &btime); + LOCALTIME_R(&etime, &btime); #ifndef _MSC_VER strftime(tempString2, 299, "%0H:%0M ", &btime); #else @@ -861,7 +861,7 @@ void VVideoLiveTV::setClock() time_t t; time(&t); struct tm tms; - localtime_r(&t, &tms); + LOCALTIME_R(&t, &tms); strftime(timeString, 19, "%H:%M", &tms); clock.setText(timeString); diff --git a/vvideomedia.cc b/vvideomedia.cc index 2f7a108..7477f0e 100644 --- a/vvideomedia.cc +++ b/vvideomedia.cc @@ -616,7 +616,8 @@ void VVideoMedia::drawBarClocks() time_t t; time(&t); struct tm tms; - localtime_r(&t, &tms); + LOCALTIME_R(&t, &tms); + strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT); diff --git a/vvideorec.cc b/vvideorec.cc index 1a0af09..0989cda 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -964,7 +964,7 @@ void VVideoRec::drawBarClocks() time_t t; time(&t); struct tm tms; - localtime_r(&t, &tms); + LOCALTIME_R(&t, &tms); strftime(timeString, 19, "%H:%M", &tms); drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT); diff --git a/vwelcome.cc b/vwelcome.cc index b92ad5d..6a88f3b 100644 --- a/vwelcome.cc +++ b/vwelcome.cc @@ -161,7 +161,8 @@ void VWelcome::drawClock() time_t t; time(&t); struct tm tms; - localtime_r(&t, &tms); + LOCALTIME_R(&t, &tms); + strftime(timeString, 19, "%H:%M", &tms); drawTextRJ(timeString, 450, 5, DrawStyle::LIGHTTEXT); -- 2.39.2