Web lists-archives.org

[Mingw-users] Porting localtime_r and gmtime_r




Hi,

I am new to porting Unix applications and have little experience with C. 
The localtime_r and gmtime_r implementation with basic error checking 
are based on the following sources:

http://www.opengroup.org/onlinepubs/009695399/functions/localtime.html
http://www.opengroup.org/onlinepubs/009695399/functions/gmtime.html
http://mail-archives.apache.org/mod_mbox/httpd-cvs/199910.mbox/%3C19991006064852.5464.qmail@xxxxxxxxxxxxx%3E


===================================================================
#include <stdlib.h>
#include <time.h>
#include <string.h>

struct tm *localtime_r (const time_t *, struct tm *);
struct tm *gmtime_r (const time_t *, struct tm *);

struct tm *
localtime_r (const time_t *timer, struct tm *result)
{
   struct tm *local_result;
   local_result = localtime (timer);

   if (local_result == NULL || result == NULL)
     return NULL;

   memcpy (result, local_result, sizeof (result));
   return result;
}

struct tm *
gmtime_r (const time_t *timer, struct tm *result)
{
   struct tm *local_result;
   local_result = gmtime (timer);

   if (local_result == NULL || result == NULL)
     return NULL;

   memcpy (result, local_result, sizeof (result));
   return result;
}


===================================================================
Are there any immediate problems with it? If yes, please advice.

Thanks.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users