summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgengjiawen <technicalcute@gmail.com>2019-05-01 16:18:44 +0800
committerZYSzys <zyszys98@gmail.com>2019-05-11 17:49:52 +0800
commit56ab82e9106f87512f18a5c80be6cc0a26bda66a (patch)
tree044abe4e19d50b7db8418a05b26e0b44f6df5331 /src
parentb49d2aad2afe25665d389c2a8d9fbd934d10ec73 (diff)
downloadandroid-node-v8-56ab82e9106f87512f18a5c80be6cc0a26bda66a.tar.gz
android-node-v8-56ab82e9106f87512f18a5c80be6cc0a26bda66a.tar.bz2
android-node-v8-56ab82e9106f87512f18a5c80be6cc0a26bda66a.zip
src: extract common macro to util.h
PR-URL: https://github.com/nodejs/node/pull/27512 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/env-inl.h8
-rw-r--r--src/inspector_profiler.cc15
-rw-r--r--src/node_process_methods.cc11
-rw-r--r--src/node_report.cc12
-rw-r--r--src/node_report.h7
-rw-r--r--src/util.h11
6 files changed, 19 insertions, 45 deletions
diff --git a/src/env-inl.h b/src/env-inl.h
index 992e51354e..4765d0db98 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -38,14 +38,6 @@
#include <utility>
-#ifdef _WIN32
-/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
-#define CWD_BUFSIZE (MAX_PATH * 4)
-#else
-#include <climits> // 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 2d3f061e98..4dfad49019 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 <climits> // 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<V8ProfilerConnection::V8ProfilerSessionDelegate>(
@@ -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 1f215eddc4..a9ddd70bcb 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<Value>& args) {
Abort();
}
@@ -81,7 +74,7 @@ static void Chdir(const FunctionCallbackInfo<Value>& 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<Value>& args) {
static void Cwd(const FunctionCallbackInfo<Value>& 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 d917a77281..578da4376e 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 <Windows.h>
@@ -17,14 +17,6 @@
#include <cwctype>
#include <fstream>
#include <iomanip>
-#include <climits> // 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 27ace3c8ef..4cb82470f4 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 <sys/types.h>
@@ -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 c9c6056850..83a7f6c1ef 100644
--- a/src/util.h
+++ b/src/util.h
@@ -27,6 +27,7 @@
#include "v8.h"
#include <cassert>
+#include <climits> // PATH_MAX
#include <csignal>
#include <cstddef>
#include <cstdio>
@@ -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