forked from Perl/perl5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrnoRuntime.xs
34 lines (32 loc) · 955 Bytes
/
ErrnoRuntime.xs
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
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <errno.h>
#include "libc/fmt/magnumstrs.internal.h"
MODULE = ErrnoRuntime PACKAGE = ErrnoRuntime
IV
strtoerrno(name)
const char *name
CODE:
unsigned i;
RETVAL = 0;
for (i = 0; kErrnoNames[i].x != MAGNUM_TERMINATOR; ++i)
{
if(strcmp(name, MAGNUM_STRING(kErrnoNames, i)) == 0)
{
RETVAL = MAGNUM_NUMBER(kErrnoNames, i);
break;
}
}
// EWOULDBLOCK isn't in the table as it's the same as EAGAIN
if(strcmp(name, "EWOULDBLOCK") == 0)
{
RETVAL = EWOULDBLOCK;
}
else if(kErrnoNames[i].x == MAGNUM_TERMINATOR)
{
croak("Unknown Errno constant %s", name);
}
OUTPUT:
RETVAL