-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathos.cpp
More file actions
90 lines (75 loc) · 1.87 KB
/
os.cpp
File metadata and controls
90 lines (75 loc) · 1.87 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 2013 Plenluno All rights reserved.
#include <libnode/os.h>
#include <libnode/detail/os.h>
#include <libj/endian.h>
#ifdef LIBJ_PF_WINDOWS
# define MAXHOSTNAMELEN 256
#else
# include <sys/param.h>
# include <sys/utsname.h>
#endif
namespace libj {
namespace node {
namespace os {
String::CPtr endianness() {
LIBJ_STATIC_SYMBOL_DEF(symBE, "BE");
LIBJ_STATIC_SYMBOL_DEF(symLE, "LE");
return endian() == BIG ? symBE : symLE;
}
String::CPtr hostname() {
char buf[MAXHOSTNAMELEN + 1];
if (gethostname(buf, sizeof(buf))) {
return String::null();
} else {
buf[sizeof(buf) - 1] = 0;
return String::create(buf);
}
}
String::CPtr type() {
#ifdef LIBJ_PF_WINDOWS
LIBJ_STATIC_SYMBOL_DEF(symType, "Windows_NT");
return symType;
#else
struct utsname info;
if (uname(&info) < 0) {
return String::null();
} else {
return String::create(info.sysname);
}
#endif
}
String::CPtr release() {
#ifdef LIBJ_PF_WINDOWS
OSVERSIONINFO info;
info.dwOSVersionInfoSize = sizeof(info);
if (!GetVersionEx(&info)) return String::null();
StringBuilder::Ptr sb = StringBuilder::create();
sb->append(static_cast<ULong>(info.dwMajorVersion));
sb->appendChar('.');
sb->append(static_cast<ULong>(info.dwMinorVersion));
sb->appendChar('.');
sb->append(static_cast<ULong>(info.dwBuildNumber));
return sb->toString();
#else
struct utsname info;
if (uname(&info) < 0) {
return String::null();
} else {
return String::create(info.release);
}
#endif
}
JsObject::Ptr networkInterface() {
return node::detail::os::networkInterface();
}
String::CPtr EOL() {
#ifdef LIBJ_PF_WINDOWS
LIBJ_STATIC_SYMBOL_DEF(symEOL, "\r\n");
#else
LIBJ_STATIC_SYMBOL_DEF(symEOL, "\n");
#endif
return symEOL;
}
} // namespace os
} // namespace node
} // namespace libj