diff options
author | libuv upstream <libuv@googlegroups.com> | 2017-05-25 15:51:45 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-05-26 17:33:40 (GMT) |
commit | 362435f02a52008a90a1c19862f09b01f1b5bd7f (patch) | |
tree | 8f63df70d3742bd44cd7a3240bc59aa1d447a08c /src/win/util.c | |
parent | 12a78bc824655524d817508d6107ef4dcf8e3626 (diff) | |
download | CMake-362435f02a52008a90a1c19862f09b01f1b5bd7f.zip CMake-362435f02a52008a90a1c19862f09b01f1b5bd7f.tar.gz CMake-362435f02a52008a90a1c19862f09b01f1b5bd7f.tar.bz2 |
libuv 2017-05-25 (dc596109)
Code extracted from:
https://github.com/libuv/libuv.git
at commit dc596109d5a22db1dbf57098630eebd30fce8068 (v1.x).
Diffstat (limited to 'src/win/util.c')
-rw-r--r-- | src/win/util.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/win/util.c b/src/win/util.c index 1d64d4c..d2e7f77 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -59,6 +59,14 @@ # define UNLEN 256 #endif +/* + Max hostname length. The Windows gethostname() documentation states that 256 + bytes will always be large enough to hold the null-terminated hostname. +*/ +#ifndef MAXHOSTNAMELEN +# define MAXHOSTNAMELEN 256 +#endif + /* Maximum environment variable size, including the terminating null */ #define MAX_ENV_VAR_LENGTH 32767 @@ -1540,3 +1548,29 @@ int uv_os_unsetenv(const char* name) { return 0; } + + +int uv_os_gethostname(char* buffer, size_t* size) { + char buf[MAXHOSTNAMELEN + 1]; + size_t len; + + if (buffer == NULL || size == NULL || *size == 0) + return UV_EINVAL; + + uv__once_init(); /* Initialize winsock */ + + if (gethostname(buf, sizeof(buf)) != 0) + return uv_translate_sys_error(WSAGetLastError()); + + buf[sizeof(buf) - 1] = '\0'; /* Null terminate, just to be safe. */ + len = strlen(buf); + + if (len >= *size) { + *size = len + 1; + return UV_ENOBUFS; + } + + memcpy(buffer, buf, len + 1); + *size = len; + return 0; +} |