| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#define PERL_NO_GET_CONTEXT |
|
2
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
3
|
|
|
|
|
|
|
#include "perl.h" |
|
4
|
|
|
|
|
|
|
#include "XSUB.h" |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#include |
|
7
|
|
|
|
|
|
|
#include |
|
8
|
|
|
|
|
|
|
#include |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#define MY_PKG "Sys::GetRandom" |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#ifndef PERL_VERSION_GE |
|
13
|
|
|
|
|
|
|
#define PERL_VERSION_GE(R, V, S) (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && PERL_SUBVERSION >= (S))))) |
|
14
|
|
|
|
|
|
|
#endif |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
MODULE = Sys::GetRandom PACKAGE = Sys::GetRandom PREFIX = sgr_ |
|
17
|
|
|
|
|
|
|
PROTOTYPES: ENABLE |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
BOOT: |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
2
|
|
|
|
|
|
HV *const stash = gv_stashpvs(MY_PKG, GV_ADD); |
|
22
|
2
|
|
|
|
|
|
newCONSTSUB(stash, "GRND_NONBLOCK", newSVuv(GRND_NONBLOCK)); |
|
23
|
2
|
|
|
|
|
|
newCONSTSUB(stash, "GRND_RANDOM", newSVuv(GRND_RANDOM)); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
ssize_t |
|
27
|
|
|
|
|
|
|
sgr_getrandom(buffer, length, flags = 0, offset = 0) |
|
28
|
|
|
|
|
|
|
SV *buffer |
|
29
|
|
|
|
|
|
|
size_t length |
|
30
|
|
|
|
|
|
|
unsigned int flags |
|
31
|
|
|
|
|
|
|
STRLEN offset |
|
32
|
|
|
|
|
|
|
PREINIT: |
|
33
|
|
|
|
|
|
|
char *p; |
|
34
|
|
|
|
|
|
|
CODE: |
|
35
|
20
|
50
|
|
|
|
|
if (length >= SSIZE_MAX || length >= (STRLEN)-1 - offset) { |
|
|
|
50
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
errno = EFAULT; |
|
37
|
0
|
|
|
|
|
|
XSRETURN_UNDEF; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
20
|
100
|
|
|
|
|
if (!SvOK(buffer)) { |
|
40
|
|
|
|
|
|
|
#if PERL_VERSION_GE(5, 25, 6) |
|
41
|
3
|
|
|
|
|
|
SvPVCLEAR(buffer); |
|
42
|
|
|
|
|
|
|
#else |
|
43
|
|
|
|
|
|
|
sv_setpvs(buffer, ""); |
|
44
|
|
|
|
|
|
|
#endif |
|
45
|
|
|
|
|
|
|
} else { |
|
46
|
|
|
|
|
|
|
STRLEN curlen; |
|
47
|
17
|
|
|
|
|
|
SvPVbyte_force(buffer, curlen); |
|
48
|
|
|
|
|
|
|
(void)curlen; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
20
|
50
|
|
|
|
|
p = offset + SvGROW(buffer, offset + length + 1u); |
|
|
|
100
|
|
|
|
|
|
|
51
|
20
|
|
|
|
|
|
RETVAL = getrandom(p, length, flags); |
|
52
|
20
|
50
|
|
|
|
|
if (RETVAL == -1) { |
|
53
|
0
|
|
|
|
|
|
XSRETURN_UNDEF; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
20
|
|
|
|
|
|
p[RETVAL] = '\0'; |
|
56
|
20
|
|
|
|
|
|
SvCUR_set(buffer, offset + RETVAL); |
|
57
|
20
|
|
|
|
|
|
SvUTF8_off(buffer); |
|
58
|
20
|
50
|
|
|
|
|
SvSETMAGIC(buffer); |
|
59
|
|
|
|
|
|
|
OUTPUT: |
|
60
|
|
|
|
|
|
|
RETVAL |