diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-04-18 12:14:30 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-04-18 12:14:30 +0200 |
commit | 8e190bf6a13f89e7503c61fc4199e531a5c8afbd (patch) | |
tree | 6acf0f02edd5772a559dbbf0f0e90af363ee1999 /src/node_os.cc | |
parent | 39dfe94682063c9b38d18fff36f57b0080fcdacb (diff) | |
parent | 659fb238e7f1c837978c2ee661385b691a18a8ac (diff) | |
download | android-node-v8-8e190bf6a13f89e7503c61fc4199e531a5c8afbd.tar.gz android-node-v8-8e190bf6a13f89e7503c61fc4199e531a5c8afbd.tar.bz2 android-node-v8-8e190bf6a13f89e7503c61fc4199e531a5c8afbd.zip |
Merge remote-tracking branch 'origin/v0.10'
Conflicts:
src/node_os.cc
Diffstat (limited to 'src/node_os.cc')
-rw-r--r-- | src/node_os.cc | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/node_os.cc b/src/node_os.cc index 614a10c96f..9b1b02deb2 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -33,10 +33,17 @@ #endif #ifdef __POSIX__ -# include <unistd.h> // gethostname, sysconf +# include <netdb.h> // MAXHOSTNAMELEN on Solaris. +# include <unistd.h> // gethostname, sysconf +# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs. # include <sys/utsname.h> #endif +// Add Windows fallback. +#ifndef MAXHOSTNAMELEN +# define MAXHOSTNAMELEN 256 +#endif + namespace node { using namespace v8; @@ -51,32 +58,29 @@ static Handle<Value> GetEndianness(const Arguments& args) { static Handle<Value> GetHostname(const Arguments& args) { HandleScope scope(node_isolate); - char s[255]; - int r = gethostname(s, 255); + char buf[MAXHOSTNAMELEN + 1]; - if (r < 0) { + if (gethostname(buf, sizeof(buf))) { #ifdef __POSIX__ return ThrowException(ErrnoException(errno, "gethostname")); #else // __MINGW32__ return ThrowException(ErrnoException(WSAGetLastError(), "gethostname")); #endif // __MINGW32__ } + buf[sizeof(buf) - 1] = '\0'; - return scope.Close(String::New(s)); + return scope.Close(String::New(buf)); } static Handle<Value> GetOSType(const Arguments& args) { HandleScope scope(node_isolate); #ifdef __POSIX__ - char type[256]; struct utsname info; - - uname(&info); - strncpy(type, info.sysname, strlen(info.sysname)); - type[strlen(info.sysname)] = 0; - - return scope.Close(String::New(type)); + if (uname(&info)) { + return ThrowException(ErrnoException(errno, "uname")); + } + return scope.Close(String::New(info.sysname)); #else // __MINGW32__ return scope.Close(String::New("Windows_NT")); #endif |