Skip to content

Commit 5f6a710

Browse files
cjihrigaddaleax
authored andcommitted
os,report: use UV_MAXHOSTNAMESIZE
UV_MAXHOSTNAMESIZE was introduced in libuv 1.26.0. Use this instead of including multiple header files, adding fallback ifdef logic, and remembering to add one to the buffer size for the terminating nul character with MAXHOSTNAMELEN. PR-URL: #26038 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8495a78 commit 5f6a710

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

src/node_os.cc

+1-8
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,10 @@
3333

3434
#ifdef __POSIX__
3535
# include <limits.h> // PATH_MAX on Solaris.
36-
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
3736
# include <unistd.h> // gethostname, sysconf
38-
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
3937
# include <sys/utsname.h>
4038
#endif // __POSIX__
4139

42-
// Add Windows fallback.
43-
#ifndef MAXHOSTNAMELEN
44-
# define MAXHOSTNAMELEN 256
45-
#endif // MAXHOSTNAMELEN
46-
4740
namespace node {
4841
namespace os {
4942

@@ -67,7 +60,7 @@ using v8::Value;
6760

6861
static void GetHostname(const FunctionCallbackInfo<Value>& args) {
6962
Environment* env = Environment::GetCurrent(args);
70-
char buf[MAXHOSTNAMELEN + 1];
63+
char buf[UV_MAXHOSTNAMESIZE];
7164
size_t size = sizeof(buf);
7265
int r = uv_os_gethostname(buf, &size);
7366

src/node_report.cc

+1-10
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@
4747
extern char** environ;
4848
#endif
4949

50-
#ifdef __POSIX__
51-
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
52-
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
53-
#endif // __POSIX__
54-
55-
#ifndef MAXHOSTNAMELEN
56-
# define MAXHOSTNAMELEN 256
57-
#endif // MAXHOSTNAMELEN
58-
5950
namespace report {
6051
using node::arraysize;
6152
using node::Environment;
@@ -377,7 +368,7 @@ static void PrintVersionInformation(JSONWriter* writer) {
377368
writer->json_keyvalue("osMachine", os_info.machine);
378369
}
379370

380-
char host[MAXHOSTNAMELEN + 1];
371+
char host[UV_MAXHOSTNAMESIZE];
381372
size_t host_size = sizeof(host);
382373

383374
if (uv_os_gethostname(host, &host_size) == 0)

0 commit comments

Comments
 (0)