windows patch

This commit is contained in:
zimoch
2011-03-10 10:13:52 +00:00
parent d51d6648e0
commit 5a6d293a5f

View File

@ -29,6 +29,7 @@
#ifdef _WIN32 #ifdef _WIN32
#define tzset() _tzset() #define tzset() _tzset()
#define timezone _timezone #define timezone _timezone
#define localtime_r(timet,tm) localtime_s(tm,timet) /* Windows sucks */
#endif #endif
#ifdef __rtems__ #ifdef __rtems__
@ -58,7 +59,7 @@ parse(const StreamFormat&, StreamBuffer& info,
{ {
unsigned int n; unsigned int n;
char* c; char* c;
if (*source == '(') if (*source == '(')
{ {
while (*++source != ')') while (*++source != ')')
@ -139,7 +140,7 @@ printDouble(const StreamFormat& format, StreamBuffer& output, double value)
length = strftime(buffer, sizeof(buffer), format.info, &brokenDownTime); length = strftime(buffer, sizeof(buffer), format.info, &brokenDownTime);
i = output.length(); i = output.length();
output.append(buffer, length); output.append(buffer, length);
/* look for fractional seconds */ /* look for fractional seconds */
while ((i = output.find("%0",i)) != -1) while ((i = output.find("%0",i)) != -1)
{ {
@ -156,7 +157,7 @@ printDouble(const StreamFormat& format, StreamBuffer& output, double value)
/* many OS don't have strptime or strptime does not fully support /* many OS don't have strptime or strptime does not fully support
all fields, e.g. %z. all fields, e.g. %z.
*/ */
static int strmatch(const char*& input, const char** strings, int minlen) static int strmatch(const char*& input, const char** strings, int minlen)
{ {
int i; int i;
@ -176,7 +177,7 @@ static int strmatch(const char*& input, const char** strings, int minlen)
} }
break; break;
} }
} }
} }
return -1; return -1;
} }
@ -194,22 +195,22 @@ static int nummatch(const char*& input, int min, int max)
} }
static const char* scantime(const char* input, const char* format, struct tm *tm, unsigned long *ns) static const char* scantime(const char* input, const char* format, struct tm *tm, unsigned long *ns)
{ {
static const char* months[] = { static const char* months[] = {
"january", "february", "march", "april", "may", "june", "january", "february", "march", "april", "may", "june",
"july", "august", "september", "november", "december", 0 }; "july", "august", "september", "november", "december", 0 };
static const char* ampm[] = { static const char* ampm[] = {
"am", "pm", 0 }; "am", "pm", 0 };
int i, n; int i, n;
int pm = -1; int pm = -1;
int century = -1; int century = -1;
int zone = 0; int zone = 0;
tzset(); tzset();
zone = timezone/60; zone = timezone/60;
debug ("TimestampConverter::scantime: native time zone = %d\n", zone); debug ("TimestampConverter::scantime: native time zone = %d\n", zone);
while (*format) while (*format)
{ {
switch (*format) switch (*format)
@ -499,7 +500,7 @@ scanDouble(const StreamFormat& format, const char* input, double& value)
time_t seconds; time_t seconds;
unsigned long nanoseconds; unsigned long nanoseconds;
const char* end; const char* end;
/* Init time stamp with "today" */ /* Init time stamp with "today" */
time (&seconds); time (&seconds);
localtime_r(&seconds, &brokenDownTime); localtime_r(&seconds, &brokenDownTime);
@ -509,12 +510,12 @@ scanDouble(const StreamFormat& format, const char* input, double& value)
brokenDownTime.tm_yday = 0; brokenDownTime.tm_yday = 0;
brokenDownTime.tm_isdst = -1; brokenDownTime.tm_isdst = -1;
nanoseconds = 0; nanoseconds = 0;
end = scantime(input, format.info, &brokenDownTime, &nanoseconds); end = scantime(input, format.info, &brokenDownTime, &nanoseconds);
if (end == NULL) { if (end == NULL) {
error ("error parsing time\n"); error ("error parsing time\n");
return -1; return -1;
} }
if (brokenDownTime.tm_mon == -1) { if (brokenDownTime.tm_mon == -1) {
seconds = brokenDownTime.tm_sec; seconds = brokenDownTime.tm_sec;
} else { } else {