File tree 4 files changed +18
-0
lines changed
4 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ Use `require('os')` to access this module.
10
10
11
11
Returns the operating system's default directory for temp files.
12
12
13
+ ## os.endianness()
14
+
15
+ Returns the endianness of the CPU. Possible values are ` "BE" ` or ` "LE" ` .
16
+
13
17
## os.hostname()
14
18
15
19
Returns the hostname of the operating system.
Original file line number Diff line number Diff line change 22
22
var binding = process . binding ( 'os' ) ;
23
23
var util = require ( 'util' ) ;
24
24
25
+ exports . endianness = binding . getEndianness ;
25
26
exports . hostname = binding . getHostname ;
26
27
exports . loadavg = binding . getLoadAvg ;
27
28
exports . uptime = binding . getUptime ;
Original file line number Diff line number Diff line change @@ -41,6 +41,14 @@ namespace node {
41
41
42
42
using namespace v8 ;
43
43
44
+ static Handle <Value> GetEndianness (const Arguments& args) {
45
+ HandleScope scope;
46
+ int i = 1 ;
47
+ bool big = (*(char *)&i) == 0 ;
48
+ Local<String> endianness = String::New (big ? " BE" : " LE" );
49
+ return scope.Close (endianness);
50
+ }
51
+
44
52
static Handle <Value> GetHostname (const Arguments& args) {
45
53
HandleScope scope;
46
54
char s[255 ];
@@ -242,6 +250,7 @@ static Handle<Value> GetInterfaceAddresses(const Arguments& args) {
242
250
void OS::Initialize (v8::Handle <v8::Object> target) {
243
251
HandleScope scope;
244
252
253
+ NODE_SET_METHOD (target, " getEndianness" , GetEndianness);
245
254
NODE_SET_METHOD (target, " getHostname" , GetHostname);
246
255
NODE_SET_METHOD (target, " getLoadAvg" , GetLoadAvg);
247
256
NODE_SET_METHOD (target, " getUptime" , GetUptime);
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ assert.equal(os.tmpDir(), '/temp');
39
39
process . env . TEMP = '' ;
40
40
assert . equal ( os . tmpDir ( ) , t ) ;
41
41
42
+ var endianness = os . endianness ( ) ;
43
+ console . log ( 'endianness = %s' , endianness ) ;
44
+ assert . ok ( / [ B L ] E / . test ( endianness ) ) ;
45
+
42
46
var hostname = os . hostname ( ) ;
43
47
console . log ( 'hostname = %s' , hostname ) ;
44
48
assert . ok ( hostname . length > 0 ) ;
You can’t perform that action at this time.
0 commit comments