@@ -1,8 +1,8 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 - * Jonathan Schleifer + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 + * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -508,11 +508,15 @@ { OFString *ret; time_t seconds = (time_t)_seconds; struct tm tm; size_t pageSize; +#ifndef _WIN32 char *buffer; +#else + wchar_t *buffer; +#endif if (seconds != floor(_seconds)) @throw [OFOutOfRangeException exception]; #ifdef HAVE_GMTIME_R @@ -539,14 +543,22 @@ pageSize = [OFSystemInfo pageSize]; buffer = [self allocMemoryWithSize: pageSize]; @try { - if (!strftime(buffer, pageSize, [format UTF8String], &tm)) +#ifndef _WIN32 + if (strftime(buffer, pageSize, [format UTF8String], &tm) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF8String: buffer]; +#else + if (wcsftime(buffer, pageSize / sizeof(wchar_t), + [format UTF16String], &tm) == 0) + @throw [OFOutOfRangeException exception]; + + ret = [OFString stringWithUTF16String: buffer]; +#endif } @finally { [self freeMemory: buffer]; } return ret; @@ -556,11 +568,15 @@ { OFString *ret; time_t seconds = (time_t)_seconds; struct tm tm; size_t pageSize; +#ifndef _WIN32 char *buffer; +#else + wchar_t *buffer; +#endif if (seconds != floor(_seconds)) @throw [OFOutOfRangeException exception]; #ifdef HAVE_LOCALTIME_R @@ -587,14 +603,22 @@ pageSize = [OFSystemInfo pageSize]; buffer = [self allocMemoryWithSize: pageSize]; @try { - if (!strftime(buffer, pageSize, [format UTF8String], &tm)) +#ifndef _WIN32 + if (strftime(buffer, pageSize, [format UTF8String], &tm) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF8String: buffer]; +#else + if (wcsftime(buffer, pageSize / sizeof(wchar_t), + [format UTF16String], &tm) == 0) + @throw [OFOutOfRangeException exception]; + + ret = [OFString stringWithUTF16String: buffer]; +#endif } @finally { [self freeMemory: buffer]; } return ret;