Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check result of localtime #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions Piece.xs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ extern "C" {
#include "perl.h"
#include "XSUB.h"
#include <time.h>
#include <errno.h>
#include <string.h>
#ifdef __cplusplus
}
#endif
Expand Down Expand Up @@ -745,7 +747,7 @@ label:
int sverrno;
long n;
time_t t;
struct tm mytm;
struct tm mytm, *pmytm;

sverrno = errno;
errno = 0;
Expand All @@ -759,9 +761,12 @@ label:
memset(&mytm, 0, sizeof(mytm));

if(*got_GMT == 1)
mytm = *localtime(&t);
pmytm = localtime(&t);
else
mytm = *gmtime(&t);
pmytm = gmtime(&t);
if (pmytm == NULL)
croak(strerror(errno));
mytm = *pmytm;

tm->tm_sec = mytm.tm_sec;
tm->tm_min = mytm.tm_min;
Expand Down Expand Up @@ -960,13 +965,17 @@ _strftime(fmt, epoch, islocal = 1)
CODE:
{
char tmpbuf[TP_BUF_SIZE];
struct tm mytm;
struct tm mytm, *pmytm;
size_t len;

if(islocal == 1)
mytm = *localtime(&epoch);
pmytm = localtime(&epoch);
else
mytm = *gmtime(&epoch);
pmytm = gmtime(&epoch);

if (pmytm == NULL)
croak(strerror(errno));
mytm = *pmytm;

len = strftime(tmpbuf, TP_BUF_SIZE, fmt, &mytm);
/*
Expand Down Expand Up @@ -1086,10 +1095,13 @@ _crt_localtime(time_t sec)
ALIAS:
_crt_gmtime = 1
PREINIT:
struct tm mytm;
struct tm mytm, *pmytm;
PPCODE:
if(ix) mytm = *gmtime(&sec);
else mytm = *localtime(&sec);
if(ix) pmytm = gmtime(&sec);
else pmytm = localtime(&sec);
if (pmytm == NULL)
croak(strerror(errno));
mytm = *pmytm;
/* Need to get: $s,$n,$h,$d,$m,$y */

EXTEND(SP, 10);
Expand Down