GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — os: add homedir() · nodejs/node@e7e5992

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • os.markdown
  • lib
    • os.js
  • src
    • node_os.cc
  • test/parallel
    • test-os.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/os.markdown‎

Copy file name to clipboardExpand all lines: doc/api/os.markdown
+4Lines changed: 4 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Use `require('os')` to access this module.
1010

1111
Returns the operating system's default directory for temporary files.
1212

13+
## os.homedir()
14+
15+
Returns the home directory of the current user.
16+
1317
## os.endianness()
1418

1519
Returns the endianness of the CPU. Possible values are `'BE'` for big endian
Collapse file

‎lib/os.js‎

Copy file name to clipboardExpand all lines: lib/os.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ exports.cpus = binding.getCPUs;
1313
exports.type = binding.getOSType;
1414
exports.release = binding.getOSRelease;
1515
exports.networkInterfaces = binding.getInterfaceAddresses;
16+
exports.homedir = binding.getHomeDirectory;
17+
1618

1719
exports.arch = function() {
1820
return process.arch;
Collapse file

‎src/node_os.cc‎

Copy file name to clipboardExpand all lines: src/node_os.cc
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,29 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
271271
}
272272

273273

274+
static void GetHomeDirectory(const FunctionCallbackInfo<Value>& args) {
275+
Environment* env = Environment::GetCurrent(args);
276+
#ifdef _WIN32
277+
char buf[MAX_PATH];
278+
#else
279+
char buf[PATH_MAX];
280+
#endif
281+
282+
size_t len = sizeof(buf);
283+
int err = uv_os_homedir(buf, &len);
284+
285+
if (err) {
286+
return env->ThrowUVException(err, "uv_os_homedir");
287+
}
288+
289+
Local<String> home = String::NewFromUtf8(env->isolate(),
290+
buf,
291+
String::kNormalString,
292+
len);
293+
args.GetReturnValue().Set(home);
294+
}
295+
296+
274297
void Initialize(Handle<Object> target,
275298
Handle<Value> unused,
276299
Handle<Context> context) {
@@ -284,6 +307,7 @@ void Initialize(Handle<Object> target,
284307
env->SetMethod(target, "getOSType", GetOSType);
285308
env->SetMethod(target, "getOSRelease", GetOSRelease);
286309
env->SetMethod(target, "getInterfaceAddresses", GetInterfaceAddresses);
310+
env->SetMethod(target, "getHomeDirectory", GetHomeDirectory);
287311
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "isBigEndian"),
288312
Boolean::New(env->isolate(), IsBigEndian()));
289313
}
Collapse file

‎test/parallel/test-os.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-os.js
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
var common = require('../common');
33
var assert = require('assert');
44
var os = require('os');
5+
var isWindows = process.platform === 'win32';
56

67

78
process.env.TMPDIR = '/tmpdir';
89
process.env.TMP = '/tmp';
910
process.env.TEMP = '/temp';
10-
if (process.platform === 'win32') {
11+
if (isWindows) {
1112
assert.equal(os.tmpdir(), '/temp');
1213
process.env.TEMP = '';
1314
assert.equal(os.tmpdir(), '/tmp');
@@ -101,3 +102,15 @@ switch (platform) {
101102

102103
var EOL = os.EOL;
103104
assert.ok(EOL.length > 0);
105+
106+
107+
var home = os.homedir();
108+
109+
console.log('homedir = ' + home);
110+
assert.ok(home.length > 0);
111+
112+
if (isWindows && process.env.USERPROFILE) {
113+
assert.equal(home, process.env.USERPROFILE);
114+
} else if (!isWindows && process.env.HOME) {
115+
assert.equal(home, process.env.HOME);
116+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.