forked from rubinius/rubinius
/
ffi_util.cpp
60 lines (47 loc) · 804 Bytes
/
ffi_util.cpp
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
50
51
52
53
54
55
56
57
58
59
60
#include "config.h"
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#ifdef RBX_WINDOWS
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netdb.h>
#endif
#include <sys/stat.h>
#include <errno.h>
#include <time.h>
#include <math.h>
#include "windows_compat.h"
#include "ffi_util.hpp"
#ifdef __APPLE__
#include <crt_externs.h>
#endif
extern "C" {
extern char** environ;
int ffi_errno() { return errno; }
char** ffi_environ() {
#ifdef __APPLE__
return *_NSGetEnviron();
#else
return environ;
#endif
}
void ffi_set_errno(int n) {
errno = n;
}
#ifndef major
#define major(x) x
#endif
#ifndef minor
#define minor(x) 0
#endif
long ffi_major(dev_t n) {
return major(n);
}
long ffi_minor(dev_t n) {
return minor(n);
}
}