| 1 |
*** open.c.orig 2016-02-01 01:11:47.863795221 -0500 |
| 2 |
--- open.c 2016-02-02 23:29:46.799174898 -0500 |
| 3 |
*************** |
| 4 |
*** 1,3 **** |
| 5 |
--- 1,119 ---- |
| 6 |
+ #ifdef _WIN32 |
| 7 |
+ |
| 8 |
+ /* On Windows, replace tmpfile() by _cairo_win_tmpfile() defined as follows, |
| 9 |
+ * and presumably more secure than mktemp(). |
| 10 |
+ */ |
| 11 |
+ |
| 12 |
+ /* _cairo_win_tmpfile (void) - replace tmpfile() in Windows |
| 13 |
+ * extracted from cairo-misc.c in cairo - a vector graphics library |
| 14 |
+ * The functiion name is changed from |
| 15 |
+ * _cairo_win32_tmpfile (void) to |
| 16 |
+ * _cairo_win_tmpfile (void) |
| 17 |
+ * |
| 18 |
+ * |
| 19 |
+ * Copyright 2002 University of Southern California |
| 20 |
+ * Copyright 2005 Red Hat, Inc. |
| 21 |
+ * Copyright 2007 Adrian Johnson |
| 22 |
+ * |
| 23 |
+ * This library is free software; you can redistribute it and/or |
| 24 |
+ * modify it either under the terms of the GNU Lesser General Public |
| 25 |
+ * License version 2.1 as published by the Free Software Foundation |
| 26 |
+ * (the "LGPL") or, at your option, under the terms of the Mozilla |
| 27 |
+ * Public License Version 1.1 (the "MPL"). If you do not alter this |
| 28 |
+ * notice, a recipient may use your version of this file under either |
| 29 |
+ * the MPL or the LGPL. |
| 30 |
+ * |
| 31 |
+ * You should have received a copy of the LGPL along with this library |
| 32 |
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software |
| 33 |
+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA |
| 34 |
+ * You should have received a copy of the MPL along with this library |
| 35 |
+ * in the file COPYING-MPL-1.1 |
| 36 |
+ * |
| 37 |
+ * The contents of this file are subject to the Mozilla Public License |
| 38 |
+ * Version 1.1 (the "License"); you may not use this file except in |
| 39 |
+ * compliance with the License. You may obtain a copy of the License at |
| 40 |
+ * http://www.mozilla.org/MPL/ |
| 41 |
+ * |
| 42 |
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY |
| 43 |
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for |
| 44 |
+ * the specific language governing rights and limitations. |
| 45 |
+ * |
| 46 |
+ * The Original Code is the cairo graphics library. |
| 47 |
+ * |
| 48 |
+ * The Initial Developer of the Original Code is University of Southern |
| 49 |
+ * California. |
| 50 |
+ * |
| 51 |
+ * Contributor(s): |
| 52 |
+ * Carl D. Worth <[email protected]> |
| 53 |
+ * Adrian Johnson <[email protected]> |
| 54 |
+ */ |
| 55 |
+ |
| 56 |
+ #include <stdio.h> |
| 57 |
+ #define WIN32_LEAN_AND_MEAN |
| 58 |
+ /* We require Windows 2000 features such as ETO_PDY */ |
| 59 |
+ #if !defined(WINVER) || (WINVER < 0x0500) |
| 60 |
+ # define WINVER 0x0500 |
| 61 |
+ #endif |
| 62 |
+ #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500) |
| 63 |
+ # define _WIN32_WINNT 0x0500 |
| 64 |
+ #endif |
| 65 |
+ |
| 66 |
+ #include <windows.h> |
| 67 |
+ #include <io.h> |
| 68 |
+ |
| 69 |
+ /* tmpfile() replacement for Windows. |
| 70 |
+ * |
| 71 |
+ * On Windows tmpfile() creates the file in the root directory. This |
| 72 |
+ * may fail due to unsufficient privileges. However, this isn't a |
| 73 |
+ * problem on Windows CE so we don't use it there. |
| 74 |
+ */ |
| 75 |
+ FILE * |
| 76 |
+ _cairo_win_tmpfile (void) |
| 77 |
+ { |
| 78 |
+ DWORD path_len; |
| 79 |
+ WCHAR path_name[MAX_PATH + 1]; |
| 80 |
+ WCHAR file_name[MAX_PATH + 1]; |
| 81 |
+ HANDLE handle; |
| 82 |
+ int fd; |
| 83 |
+ FILE *fp; |
| 84 |
+ |
| 85 |
+ path_len = GetTempPathW (MAX_PATH, path_name); |
| 86 |
+ if (path_len <= 0 || path_len >= MAX_PATH) |
| 87 |
+ return NULL; |
| 88 |
+ |
| 89 |
+ if (GetTempFileNameW (path_name, L"ps_", 0, file_name) == 0) |
| 90 |
+ return NULL; |
| 91 |
+ |
| 92 |
+ handle = CreateFileW (file_name, |
| 93 |
+ GENERIC_READ | GENERIC_WRITE, |
| 94 |
+ 0, |
| 95 |
+ NULL, |
| 96 |
+ CREATE_ALWAYS, |
| 97 |
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, |
| 98 |
+ NULL); |
| 99 |
+ if (handle == INVALID_HANDLE_VALUE) { |
| 100 |
+ DeleteFileW (file_name); |
| 101 |
+ return NULL; |
| 102 |
+ } |
| 103 |
+ |
| 104 |
+ fd = _open_osfhandle((intptr_t) handle, 0); |
| 105 |
+ if (fd < 0) { |
| 106 |
+ CloseHandle (handle); |
| 107 |
+ return NULL; |
| 108 |
+ } |
| 109 |
+ |
| 110 |
+ fp = _fdopen(fd, "w+b"); |
| 111 |
+ if (fp == NULL) { |
| 112 |
+ _close(fd); |
| 113 |
+ return NULL; |
| 114 |
+ } |
| 115 |
+ |
| 116 |
+ return fp; |
| 117 |
+ } |
| 118 |
+ |
| 119 |
+ #define tmpfile _cairo_win_tmpfile |
| 120 |
+ #endif /* _WIN32 */ |
| 121 |
+ |
| 122 |
#include "f2c.h" |
| 123 |
#include "fio.h" |
| 124 |
#include "string.h" |
| 125 |
*************** |
| 126 |
*** 30,35 **** |
| 127 |
--- 146,154 ---- |
| 128 |
#ifdef NON_ANSI_RW_MODES |
| 129 |
char *f__r_mode[2] = {"r", "r"}; |
| 130 |
char *f__w_mode[4] = {"w", "w", "r+w", "r+w"}; |
| 131 |
+ #elif defined(WIN32) |
| 132 |
+ char *f__r_mode[2] = {"rb", "rb"}; |
| 133 |
+ char *f__w_mode[4] = {"wb", "wb", "rb+", "rb+"}; |
| 134 |
#else |
| 135 |
char *f__r_mode[2] = {"rb", "r"}; |
| 136 |
char *f__w_mode[4] = {"wb", "w", "r+b", "r+"}; |