Line | Count | Source |
1 | | //======================================================================== |
2 | | // |
3 | | // gfile.h |
4 | | // |
5 | | // Miscellaneous file and directory name manipulation. |
6 | | // |
7 | | // Copyright 1996-2003 Glyph & Cog, LLC |
8 | | // |
9 | | //======================================================================== |
10 | | |
11 | | //======================================================================== |
12 | | // |
13 | | // Modified under the Poppler project - http://poppler.freedesktop.org |
14 | | // |
15 | | // All changes made under the Poppler project to this file are licensed |
16 | | // under GPL version 2 or later |
17 | | // |
18 | | // Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com> |
19 | | // Copyright (C) 2009, 2011, 2012, 2017, 2018, 2021, 2022, 2025, 2026 Albert Astals Cid <aacid@kde.org> |
20 | | // Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net> |
21 | | // Copyright (C) 2013 Adam Reichold <adamreichold@myopera.com> |
22 | | // Copyright (C) 2013, 2017 Adrian Johnson <ajohnson@redneon.com> |
23 | | // Copyright (C) 2014 Bogdan Cristea <cristeab@gmail.com> |
24 | | // Copyright (C) 2014 Peter Breitenlohner <peb@mppmu.mpg.de> |
25 | | // Copyright (C) 2017 Christoph Cullmann <cullmann@kde.org> |
26 | | // Copyright (C) 2017 Thomas Freitag <Thomas.Freitag@alfa.de> |
27 | | // Copyright (C) 2018 Mojca Miklavec <mojca@macports.org> |
28 | | // Copyright (C) 2019, 2021 Christian Persch <chpe@src.gnome.org> |
29 | | // Copyright (C) 2026 g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk> |
30 | | // |
31 | | // To see a description of the changes please see the Changelog file that |
32 | | // came with your tarball or type make ChangeLog if you are building from git |
33 | | // |
34 | | //======================================================================== |
35 | | |
36 | | #ifndef GFILE_H |
37 | | #define GFILE_H |
38 | | |
39 | | #include "poppler_private_export.h" |
40 | | #include <cstdio> |
41 | | #include <ctime> |
42 | | #include <string> |
43 | | extern "C" { |
44 | | #ifdef _WIN32 |
45 | | # include <sys/stat.h> |
46 | | # ifdef FPTEX |
47 | | # include <win32lib.h> |
48 | | # else |
49 | | # ifndef NOMINMAX |
50 | | # define NOMINMAX |
51 | | # endif |
52 | | # include <windows.h> |
53 | | # endif |
54 | | #else |
55 | | # include <unistd.h> |
56 | | # include <sys/types.h> |
57 | | #endif |
58 | | } |
59 | | |
60 | | #include <memory> |
61 | | |
62 | | /* Integer type for all file offsets and file sizes */ |
63 | | using Goffset = long long; |
64 | | |
65 | | //------------------------------------------------------------------------ |
66 | | |
67 | | // Open a file. On Windows, this converts the path from UTF-8 to |
68 | | // UCS-2 and calls _wfopen (if available). On other OSes, this simply |
69 | | // calls fopen. |
70 | | extern FILE POPPLER_PRIVATE_EXPORT *openFile(const char *path, const char *mode); |
71 | | |
72 | | // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line |
73 | | // conventions. |
74 | | extern char POPPLER_PRIVATE_EXPORT *getLine(char *buf, int size, FILE *f); |
75 | | |
76 | | // Like fseek/ftell but uses platform specific variants that support large files |
77 | | extern int POPPLER_PRIVATE_EXPORT Gfseek(FILE *f, Goffset offset, int whence); |
78 | | extern Goffset POPPLER_PRIVATE_EXPORT Gftell(FILE *f); |
79 | | |
80 | | // Largest offset supported by Gfseek/Gftell |
81 | | extern Goffset GoffsetMax(); |
82 | | |
83 | | //------------------------------------------------------------------------ |
84 | | // GooFile |
85 | | //------------------------------------------------------------------------ |
86 | | |
87 | | class POPPLER_PRIVATE_EXPORT GooFile |
88 | | { |
89 | | public: |
90 | | GooFile(const GooFile &) = delete; |
91 | | GooFile &operator=(const GooFile &other) = delete; |
92 | | |
93 | | int read(char *buf, int n, Goffset offset) const; |
94 | | Goffset size() const; |
95 | | |
96 | | static std::unique_ptr<GooFile> open(const std::string &fileName); |
97 | | #ifndef _WIN32 |
98 | | static std::unique_ptr<GooFile> open(int fdA); |
99 | | #endif |
100 | | |
101 | | #ifdef _WIN32 |
102 | | static std::unique_ptr<GooFile> open(const wchar_t *fileName); |
103 | | |
104 | | ~GooFile() { CloseHandle(handle); } |
105 | | |
106 | | // Asuming than on windows you can't change files that are already open |
107 | | bool modificationTimeChangedSinceOpen() const; |
108 | | |
109 | | private: |
110 | | GooFile(HANDLE handleA); |
111 | | HANDLE handle; |
112 | | struct _FILETIME modifiedTimeOnOpen; |
113 | | #else |
114 | 7.13k | ~GooFile() { close(fd); } |
115 | | |
116 | | bool modificationTimeChangedSinceOpen() const; |
117 | | |
118 | | private: |
119 | | explicit GooFile(int fdA); |
120 | | int fd; |
121 | | struct timespec modifiedTimeOnOpen; |
122 | | #endif // _WIN32 |
123 | | }; |
124 | | |
125 | | #endif |