@@ -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+
274297void 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}
0 commit comments