File: strptime.xs

package info (click to toggle)
libposix-strptime-perl 0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 264 kB
  • sloc: perl: 37; makefile: 5
file content (49 lines) | stat: -rw-r--r-- 1,296 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"

#include <time.h>

#define POSIX_STRPTIME_SENTINEL (-1901)

#define POSIX_STRPTIME_SET(field) \
  { \
    if (field == POSIX_STRPTIME_SENTINEL) { \
        XPUSHs(&PL_sv_undef); \
    } \
    else { \
        mXPUSHi(field); \
    } \
  } \


MODULE = POSIX::strptime		PACKAGE = POSIX::strptime

void
strptime(input, format)
    SV *input
    SV *format
   PREINIT:
     struct tm tm_t;
     init_tm(&tm_t);
     // We need these to tell what values were *not* modified by strptime()
     tm_t.tm_sec = POSIX_STRPTIME_SENTINEL;
     tm_t.tm_min = POSIX_STRPTIME_SENTINEL;
     tm_t.tm_hour = POSIX_STRPTIME_SENTINEL;
     tm_t.tm_mday = POSIX_STRPTIME_SENTINEL;
     tm_t.tm_mon = POSIX_STRPTIME_SENTINEL;
     tm_t.tm_year = POSIX_STRPTIME_SENTINEL;
     tm_t.tm_isdst = POSIX_STRPTIME_SENTINEL;
   PPCODE:
     strptime(SvPV_nolen(input), SvPV_nolen(format), &tm_t);
     POSIX_STRPTIME_SET(tm_t.tm_sec);
     POSIX_STRPTIME_SET(tm_t.tm_min);
     POSIX_STRPTIME_SET(tm_t.tm_hour);
     POSIX_STRPTIME_SET(tm_t.tm_mday);
     POSIX_STRPTIME_SET(tm_t.tm_mon);
     POSIX_STRPTIME_SET(tm_t.tm_year);
     POSIX_STRPTIME_SET(tm_t.tm_wday);
     POSIX_STRPTIME_SET(tm_t.tm_yday);
     POSIX_STRPTIME_SET(tm_t.tm_isdst);