Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Unified Diff: tools/re2c/code.c

Issue 10324002: Merge https://github.com/yasm/yasm/commit/ab19547382660d81e0b4a0232dccb38f44c52a36 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/yasm/patched-yasm/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/re2c/code.c
===================================================================
--- tools/re2c/code.c (revision 134825)
+++ tools/re2c/code.c (working copy)
@@ -1,3 +1,7 @@
+#ifdef _WIN32
+#include <windows.h>
+#include <io.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@@ -6,6 +10,57 @@
#include "tools/re2c/dfa.h"
#include "tools/re2c/parse.h"
+#ifdef _WIN32
+/* tmpfile() replacment for Windows.
+ *
+ * On Windows tmpfile() creates the file in the root directory. This
+ * may fail due to unsufficient privileges.
+ */
+static FILE *
+win32_tmpfile (void)
+{
+ DWORD path_len;
+ WCHAR path_name[MAX_PATH + 1];
+ WCHAR file_name[MAX_PATH + 1];
+ HANDLE handle;
+ int fd;
+ FILE *fp;
+
+ path_len = GetTempPathW (MAX_PATH, path_name);
+ if (path_len <= 0 || path_len >= MAX_PATH)
+ return NULL;
Nico 2012/05/02 16:52:05 This indent looks different from the upstream patc
scottmg 2012/05/02 16:58:23 The pretty diff page on github isn't replacing tab
+
+ if (GetTempFileNameW (path_name, L"ps_", 0, file_name) == 0)
+ return NULL;
+
+ handle = CreateFileW (file_name,
+ GENERIC_READ | GENERIC_WRITE,
+ 0,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
+ NULL);
+ if (handle == INVALID_HANDLE_VALUE) {
+ DeleteFileW (file_name);
+ return NULL;
+ }
+
+ fd = _open_osfhandle((intptr_t) handle, 0);
+ if (fd < 0) {
+ CloseHandle (handle);
+ return NULL;
+ }
+
+ fp = fdopen(fd, "w+b");
+ if (fp == NULL) {
+ _close(fd);
+ return NULL;
+ }
+
+ return fp;
+}
+#endif
+
static void useLabel(size_t value) {
while (value >= vUsedLabelAlloc) {
vUsedLabels = realloc(vUsedLabels, vUsedLabelAlloc * 2);
@@ -844,7 +899,11 @@
nOrgOline = oline;
maxFillIndexes = vFillIndexes;
orgVFillIndexes = vFillIndexes;
+#ifdef _WIN32
+ tmpo = win32_tmpfile();
+#else
tmpo = tmpfile();
+#endif
for(s = d->head; s; s = s->next){
int readCh = 0;
State_emit(s, tmpo, &readCh);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698