diff --git a/src/env-inl.h b/src/env-inl.h index 992e51354e6cf2..4765d0db98525a 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -38,14 +38,6 @@ #include -#ifdef _WIN32 -/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */ -#define CWD_BUFSIZE (MAX_PATH * 4) -#else -#include // PATH_MAX on Solaris. -#define CWD_BUFSIZE (PATH_MAX) -#endif - namespace node { inline v8::Isolate* IsolateData::isolate() const { diff --git a/src/inspector_profiler.cc b/src/inspector_profiler.cc index 2d3f061e987d35..4dfad49019e154 100644 --- a/src/inspector_profiler.cc +++ b/src/inspector_profiler.cc @@ -5,6 +5,7 @@ #include "node_file.h" #include "node_internals.h" #include "v8-inspector.h" +#include "util.h" namespace node { namespace profiler { @@ -23,16 +24,6 @@ using v8::Value; using v8_inspector::StringView; -#ifdef _WIN32 -const char* const kPathSeparator = "\\/"; -/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */ -#define CWD_BUFSIZE (MAX_PATH * 4) -#else -#include // PATH_MAX on Solaris. -const char* const kPathSeparator = "/"; -#define CWD_BUFSIZE (PATH_MAX) -#endif - V8ProfilerConnection::V8ProfilerConnection(Environment* env) : session_(env->inspector_agent()->Connect( std::make_unique( @@ -284,8 +275,8 @@ void EndStartedProfilers(Environment* env) { } std::string GetCwd() { - char cwd[CWD_BUFSIZE]; - size_t size = CWD_BUFSIZE; + char cwd[PATH_MAX_BYTES]; + size_t size = PATH_MAX_BYTES; int err = uv_cwd(cwd, &size); // This can fail if the cwd is deleted. // TODO(joyeecheung): store this in the Environment during Environment diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 1f215eddc4f194..a9ddd70bcbe2d6 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -59,13 +59,6 @@ Mutex umask_mutex; // used in Hrtime() and Uptime() below #define NANOS_PER_SEC 1000000000 -#ifdef _WIN32 -/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */ -#define CHDIR_BUFSIZE (MAX_PATH * 4) -#else -#define CHDIR_BUFSIZE (PATH_MAX) -#endif - static void Abort(const FunctionCallbackInfo& args) { Abort(); } @@ -81,7 +74,7 @@ static void Chdir(const FunctionCallbackInfo& args) { if (err) { // Also include the original working directory, since that will usually // be helpful information when debugging a `chdir()` failure. - char buf[CHDIR_BUFSIZE]; + char buf[PATH_MAX_BYTES]; size_t cwd_len = sizeof(buf); uv_cwd(buf, &cwd_len); return env->ThrowUVException(err, "chdir", nullptr, buf, *path); @@ -119,7 +112,7 @@ static void CPUUsage(const FunctionCallbackInfo& args) { static void Cwd(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK(env->has_run_bootstrapping_code()); - char buf[CHDIR_BUFSIZE]; + char buf[PATH_MAX_BYTES]; size_t cwd_len = sizeof(buf); int err = uv_cwd(buf, &cwd_len); if (err) diff --git a/src/node_report.cc b/src/node_report.cc index d917a772812b27..578da4376e07da 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -1,8 +1,8 @@ - #include "node_report.h" #include "debug_utils.h" #include "node_internals.h" #include "node_metadata.h" +#include "util.h" #ifdef _WIN32 #include @@ -17,14 +17,6 @@ #include #include #include -#include // PATH_MAX - -#ifdef _WIN32 -/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */ -#define PATH_MAX_BYTES (MAX_PATH * 4) -#else -#define PATH_MAX_BYTES (PATH_MAX) -#endif #ifndef _WIN32 extern char** environ; @@ -110,7 +102,7 @@ std::string TriggerNodeReport(Isolate* isolate, // Regular file. Append filename to directory path if one was specified if (env != nullptr && options->report_directory.length() > 0) { std::string pathname = options->report_directory; - pathname += PATHSEP; + pathname += node::kPathSeparator; pathname += filename; outfile.open(pathname, std::ios::out | std::ios::binary); } else { diff --git a/src/node_report.h b/src/node_report.h index 27ace3c8efedf9..4cb82470f43594 100644 --- a/src/node_report.h +++ b/src/node_report.h @@ -4,6 +4,7 @@ #include "node_buffer.h" #include "uv.h" #include "v8.h" +#include "util.h" #ifndef _WIN32 #include @@ -26,12 +27,6 @@ namespace report { -#ifdef _WIN32 -#define PATHSEP "\\" -#else // UNIX, OSX -#define PATHSEP "/" -#endif - // Function declarations - functions in src/node_report.cc std::string TriggerNodeReport(v8::Isolate* isolate, node::Environment* env, diff --git a/src/util.h b/src/util.h index c9c605685070ff..83a7f6c1ef5592 100644 --- a/src/util.h +++ b/src/util.h @@ -27,6 +27,7 @@ #include "v8.h" #include +#include // PATH_MAX #include #include #include @@ -43,6 +44,16 @@ namespace node { +// Maybe remove kPathSeparator when cpp17 is ready +#ifdef _WIN32 + constexpr char kPathSeparator = '\\'; +/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */ +#define PATH_MAX_BYTES (MAX_PATH * 4) +#else + constexpr char kPathSeparator = '/'; +#define PATH_MAX_BYTES (PATH_MAX) +#endif + // These should be used in our code as opposed to the native // versions as they abstract out some platform and or // compiler version specific functionality