use uv_exepath instead of argv[0] for reading overlays

This commit is contained in:
Igor Klopov 2016-10-05 01:42:24 +03:00
parent a62be08882
commit 6bbe3cc88b
4 changed files with 92 additions and 20 deletions

View File

@ -354,13 +354,14 @@
} // namespace node
--- node/src/node_main.cc
+++ node/src/node_main.cc
@@ -19,10 +19,280 @@
@@ -19,10 +19,298 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "node.h"
+#include <string.h>
+#include "uv.h"
+
+#define BOUNDARY 4096
+
@ -512,9 +513,26 @@
+#endif
+
+
+char* ReadOverlays(const char* filename) {
+char* ReadOverlays() {
+
+ FILE* file = fopen(filename, "rb");
+ char exepath[1024];
+ size_t exepath_size = sizeof(exepath);
+ if (uv_exepath(exepath, &exepath_size)) {
+ fprintf(stderr, "Pkg: Error obtaining exepath.\n");
+ exit(1);
+ }
+
+ FILE* file;
+#ifdef _WIN32
+ WCHAR exepath_w[2048];
+ if (!MultiByteToWideChar(CP_UTF8, 0, exepath, -1, exepath_w, sizeof(exepath_w))) {
+ fprintf(stderr, "Pkg: Error converting to WideChar.\n");
+ exit(1);
+ }
+ file = _wfopen(exepath_w, L"rb");
+#else
+ file = fopen(exepath, "rb");
+#endif
+ if (!file) {
+ fprintf(stderr, "Pkg: Error opening file.\n");
+ exit(1);
@ -601,7 +619,7 @@
+ }
+ }
+ char** nargv = new char*[argc + 64];
+ char* bakery = ReadOverlays(argv[0]);
+ char* bakery = ReadOverlays();
+ int c = 0;
+ nargv[c++] = argv[0];
+ if (bakery) {
@ -635,7 +653,7 @@
// Convert argv to to UTF8
char** argv = new char*[argc];
for (int i = 0; i < argc; i++) {
@@ -55,13 +325,13 @@
@@ -55,13 +343,13 @@
fprintf(stderr, "Could not convert arguments to utf8.");
exit(1);
}

View File

@ -418,10 +418,11 @@
} // namespace node
--- node/src/node_main.cc
+++ node/src/node_main.cc
@@ -1,7 +1,277 @@
@@ -1,7 +1,295 @@
#include "node.h"
+#include <string.h>
+#include "uv.h"
+
+#define BOUNDARY 4096
+
@ -573,9 +574,26 @@
+#endif
+
+
+char* ReadOverlays(const char* filename) {
+char* ReadOverlays() {
+
+ FILE* file = fopen(filename, "rb");
+ char exepath[1024];
+ size_t exepath_size = sizeof(exepath);
+ if (uv_exepath(exepath, &exepath_size)) {
+ fprintf(stderr, "Pkg: Error obtaining exepath.\n");
+ exit(1);
+ }
+
+ FILE* file;
+#ifdef _WIN32
+ WCHAR exepath_w[2048];
+ if (!MultiByteToWideChar(CP_UTF8, 0, exepath, -1, exepath_w, sizeof(exepath_w))) {
+ fprintf(stderr, "Pkg: Error converting to WideChar.\n");
+ exit(1);
+ }
+ file = _wfopen(exepath_w, L"rb");
+#else
+ file = fopen(exepath, "rb");
+#endif
+ if (!file) {
+ fprintf(stderr, "Pkg: Error opening file.\n");
+ exit(1);
@ -662,7 +680,7 @@
+ }
+ }
+ char** nargv = new char*[argc + 64];
+ char* bakery = ReadOverlays(argv[0]);
+ char* bakery = ReadOverlays();
+ int c = 0;
+ nargv[c++] = argv[0];
+ if (bakery) {
@ -696,7 +714,7 @@
// Convert argv to to UTF8
char** argv = new char*[argc + 1];
for (int i = 0; i < argc; i++) {
@@ -35,14 +305,14 @@
@@ -35,14 +323,14 @@
exit(1);
}
}

View File

@ -430,10 +430,11 @@
} // namespace node
--- node/src/node_main.cc
+++ node/src/node_main.cc
@@ -1,7 +1,277 @@
@@ -1,7 +1,295 @@
#include "node.h"
+#include <string.h>
+#include "uv.h"
+
+#define BOUNDARY 4096
+
@ -585,9 +586,26 @@
+#endif
+
+
+char* ReadOverlays(const char* filename) {
+char* ReadOverlays() {
+
+ FILE* file = fopen(filename, "rb");
+ char exepath[1024];
+ size_t exepath_size = sizeof(exepath);
+ if (uv_exepath(exepath, &exepath_size)) {
+ fprintf(stderr, "Pkg: Error obtaining exepath.\n");
+ exit(1);
+ }
+
+ FILE* file;
+#ifdef _WIN32
+ WCHAR exepath_w[2048];
+ if (!MultiByteToWideChar(CP_UTF8, 0, exepath, -1, exepath_w, sizeof(exepath_w))) {
+ fprintf(stderr, "Pkg: Error converting to WideChar.\n");
+ exit(1);
+ }
+ file = _wfopen(exepath_w, L"rb");
+#else
+ file = fopen(exepath, "rb");
+#endif
+ if (!file) {
+ fprintf(stderr, "Pkg: Error opening file.\n");
+ exit(1);
@ -674,7 +692,7 @@
+ }
+ }
+ char** nargv = new char*[argc + 64];
+ char* bakery = ReadOverlays(argv[0]);
+ char* bakery = ReadOverlays();
+ int c = 0;
+ nargv[c++] = argv[0];
+ if (bakery) {
@ -708,7 +726,7 @@
int wmain(int argc, wchar_t *wargv[]) {
if (!IsWindows7OrGreater()) {
@@ -43,17 +313,17 @@
@@ -43,17 +331,17 @@
exit(1);
}
}

View File

@ -430,10 +430,11 @@
} // namespace node
--- node/src/node_main.cc
+++ node/src/node_main.cc
@@ -1,7 +1,277 @@
@@ -1,7 +1,295 @@
#include "node.h"
+#include <string.h>
+#include "uv.h"
+
+#define BOUNDARY 4096
+
@ -585,9 +586,26 @@
+#endif
+
+
+char* ReadOverlays(const char* filename) {
+char* ReadOverlays() {
+
+ FILE* file = fopen(filename, "rb");
+ char exepath[1024];
+ size_t exepath_size = sizeof(exepath);
+ if (uv_exepath(exepath, &exepath_size)) {
+ fprintf(stderr, "Pkg: Error obtaining exepath.\n");
+ exit(1);
+ }
+
+ FILE* file;
+#ifdef _WIN32
+ WCHAR exepath_w[2048];
+ if (!MultiByteToWideChar(CP_UTF8, 0, exepath, -1, exepath_w, sizeof(exepath_w))) {
+ fprintf(stderr, "Pkg: Error converting to WideChar.\n");
+ exit(1);
+ }
+ file = _wfopen(exepath_w, L"rb");
+#else
+ file = fopen(exepath, "rb");
+#endif
+ if (!file) {
+ fprintf(stderr, "Pkg: Error opening file.\n");
+ exit(1);
@ -674,7 +692,7 @@
+ }
+ }
+ char** nargv = new char*[argc + 64];
+ char* bakery = ReadOverlays(argv[0]);
+ char* bakery = ReadOverlays();
+ int c = 0;
+ nargv[c++] = argv[0];
+ if (bakery) {
@ -708,7 +726,7 @@
#include <WinError.h>
int wmain(int argc, wchar_t *wargv[]) {
@@ -44,17 +314,17 @@
@@ -44,17 +332,17 @@
exit(1);
}
}