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>
This commit is contained in:
gengjiawen authored and Michaël Zasso committed 2019-05-11 12:13:15 +02:00
1 parent 172fa639a6
commit a18692c4df
6 files changed
+19 -45

No files matched your search

-8
View File
@@ -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 {
+3 -12
View File
@@ -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
+2 -9
View File
@@ -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)
+2 -10
View File
@@ -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 {
+1 -6
View File
@@ -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,
+11
View File
@@ -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