diff options
author | Norbert Preining <norbert@preining.info> | 2023-01-12 03:01:29 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-01-12 03:01:29 +0000 |
commit | 6a7900c93acc16d1bbd2f1e26286c7dd7387e6c0 (patch) | |
tree | 76196287351cba68a51934c49468bf1a7846aa76 /dviware/dvisvgm/libs/ff-woff/fontforge/tmpfile2.cpp | |
parent | c1c19023b4b1d43cb874f84df5102b485853e672 (diff) |
CTAN sync 202301120301
Diffstat (limited to 'dviware/dvisvgm/libs/ff-woff/fontforge/tmpfile2.cpp')
-rw-r--r-- | dviware/dvisvgm/libs/ff-woff/fontforge/tmpfile2.cpp | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/dviware/dvisvgm/libs/ff-woff/fontforge/tmpfile2.cpp b/dviware/dvisvgm/libs/ff-woff/fontforge/tmpfile2.cpp deleted file mode 100644 index d22d03bc3c..0000000000 --- a/dviware/dvisvgm/libs/ff-woff/fontforge/tmpfile2.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* This file is part of ff-woff, a reduced version of the FontForge library. -* It provides the function tmpfile2() with the functionality of tmpfile() but -* works on POSIX and Windows systems. -* License: Revised BSD license used by FontForge -* https://github.com/fontforge/fontforge/blob/master/LICENSE -* (C) 2017-2022 Martin Gieseking <martin.gieseking@uos.de> */ - -#include <cstdio> -#include <cstdlib> -#include <exception> -#include <iostream> -#include <string> - -#if _WIN32 -#include <fcntl.h> -#include <sys/stat.h> -#include <windows.h> -#ifdef _MSC_VER -#include <io.h> -#endif -#endif - -using namespace std; - -class TmpFileException : public exception { - public: - TmpFileException (const char *msg) : _message(msg) {} - const char* what () const noexcept override {return _message.c_str();} - - private: - string _message; -}; - - -static inline void tmpfile_error (const char *msg) { -#if defined(_MSC_VER) || defined(__MINGW32__) - // Visual C++ and MinGW support exception handling - // between extern "C" and C++ functions. - throw TmpFileException(msg); -#else - cerr << msg << endl; - exit(EXIT_FAILURE); -#endif -} - - -/* Creates a temporary binary file in the system's temp folder and returns -* its file pointer. The file is automatically removed when closing it. -* If the temp file can't be created for some reason, the function calls -* exit() or throws a TmpFileException (depending on OS and compiler). */ -extern "C" FILE* tmpfile2 () { -#ifndef _WIN32 - if (FILE *fp = std::tmpfile()) - return fp; -#else - char tmpdir[MAX_PATH+1]; - DWORD len = GetTempPath(MAX_PATH+1, tmpdir); - if (len > 0) { - if (len >= MAX_PATH-14) - tmpfile_error("path to temp folder too long"); - char fname[MAX_PATH]; - if (GetTempFileName(tmpdir, "tmp", 0, fname)) { - int fd = _open(fname, _O_CREAT | _O_TEMPORARY | _O_RDWR | _O_BINARY, _S_IREAD | _S_IWRITE); - if (fd >= 0) { - if (FILE *fp = _fdopen(fd, "w+b")) - return fp; - int saved_errno = errno; - _close(fd); - errno = saved_errno; - } - } - } -#endif - tmpfile_error("failed to create temporary file"); -} |