Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 10:26:09

0001 //========================================================================
0002 //
0003 // gfile.h
0004 //
0005 // Miscellaneous file and directory name manipulation.
0006 //
0007 // Copyright 1996-2003 Glyph & Cog, LLC
0008 //
0009 //========================================================================
0010 
0011 //========================================================================
0012 //
0013 // Modified under the Poppler project - http://poppler.freedesktop.org
0014 //
0015 // All changes made under the Poppler project to this file are licensed
0016 // under GPL version 2 or later
0017 //
0018 // Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com>
0019 // Copyright (C) 2009, 2011, 2012, 2017, 2018, 2021, 2022 Albert Astals Cid <aacid@kde.org>
0020 // Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net>
0021 // Copyright (C) 2013 Adam Reichold <adamreichold@myopera.com>
0022 // Copyright (C) 2013, 2017 Adrian Johnson <ajohnson@redneon.com>
0023 // Copyright (C) 2014 Bogdan Cristea <cristeab@gmail.com>
0024 // Copyright (C) 2014 Peter Breitenlohner <peb@mppmu.mpg.de>
0025 // Copyright (C) 2017 Christoph Cullmann <cullmann@kde.org>
0026 // Copyright (C) 2017 Thomas Freitag <Thomas.Freitag@alfa.de>
0027 // Copyright (C) 2018 Mojca Miklavec <mojca@macports.org>
0028 // Copyright (C) 2019, 2021 Christian Persch <chpe@src.gnome.org>
0029 //
0030 // To see a description of the changes please see the Changelog file that
0031 // came with your tarball or type make ChangeLog if you are building from git
0032 //
0033 //========================================================================
0034 
0035 #ifndef GFILE_H
0036 #define GFILE_H
0037 
0038 #include "poppler-config.h"
0039 #include "poppler_private_export.h"
0040 #include <cstdio>
0041 #include <cstdlib>
0042 #include <cstddef>
0043 #include <ctime>
0044 #include <string>
0045 extern "C" {
0046 #if defined(_WIN32)
0047 #    include <sys/stat.h>
0048 #    ifdef FPTEX
0049 #        include <win32lib.h>
0050 #    else
0051 #        ifndef NOMINMAX
0052 #            define NOMINMAX
0053 #        endif
0054 #        include <windows.h>
0055 #    endif
0056 #else
0057 #    include <unistd.h>
0058 #    include <sys/types.h>
0059 #    if defined(HAVE_DIRENT_H)
0060 #        include <dirent.h>
0061 #        define NAMLEN(d) strlen((d)->d_name)
0062 #    else
0063 #        define dirent direct
0064 #        define NAMLEN(d) (d)->d_namlen
0065 #        ifdef HAVE_SYS_NDIR_H
0066 #            include <sys/ndir.h>
0067 #        endif
0068 #        ifdef HAVE_SYS_DIR_H
0069 #            include <sys/dir.h>
0070 #        endif
0071 #        ifdef HAVE_NDIR_H
0072 #            include <ndir.h>
0073 #        endif
0074 #    endif
0075 #endif
0076 }
0077 
0078 #include <memory>
0079 
0080 class GooString;
0081 
0082 /* Integer type for all file offsets and file sizes */
0083 typedef long long Goffset;
0084 
0085 //------------------------------------------------------------------------
0086 
0087 // Append a file name to a path string.  <path> may be an empty
0088 // string, denoting the current directory).  Returns <path>.
0089 extern GooString POPPLER_PRIVATE_EXPORT *appendToPath(GooString *path, const char *fileName);
0090 
0091 #ifndef _WIN32
0092 // Open a file descriptor
0093 // Could be implemented on WIN32 too, but the only external caller of
0094 // this function is not used on WIN32
0095 extern int POPPLER_PRIVATE_EXPORT openFileDescriptor(const char *path, int flags);
0096 #endif
0097 
0098 // Open a file.  On Windows, this converts the path from UTF-8 to
0099 // UCS-2 and calls _wfopen (if available).  On other OSes, this simply
0100 // calls fopen.
0101 extern FILE POPPLER_PRIVATE_EXPORT *openFile(const char *path, const char *mode);
0102 
0103 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
0104 // conventions.
0105 extern char POPPLER_PRIVATE_EXPORT *getLine(char *buf, int size, FILE *f);
0106 
0107 // Like fseek/ftell but uses platform specific variants that support large files
0108 extern int POPPLER_PRIVATE_EXPORT Gfseek(FILE *f, Goffset offset, int whence);
0109 extern Goffset POPPLER_PRIVATE_EXPORT Gftell(FILE *f);
0110 
0111 // Largest offset supported by Gfseek/Gftell
0112 extern Goffset GoffsetMax();
0113 
0114 //------------------------------------------------------------------------
0115 // GooFile
0116 //------------------------------------------------------------------------
0117 
0118 class POPPLER_PRIVATE_EXPORT GooFile
0119 {
0120 public:
0121     GooFile(const GooFile &) = delete;
0122     GooFile &operator=(const GooFile &other) = delete;
0123 
0124     int read(char *buf, int n, Goffset offset) const;
0125     Goffset size() const;
0126 
0127     static std::unique_ptr<GooFile> open(const std::string &fileName);
0128 #ifndef _WIN32
0129     static std::unique_ptr<GooFile> open(int fdA);
0130 #endif
0131 
0132 #ifdef _WIN32
0133     static std::unique_ptr<GooFile> open(const wchar_t *fileName);
0134 
0135     ~GooFile() { CloseHandle(handle); }
0136 
0137     // Asuming than on windows you can't change files that are already open
0138     bool modificationTimeChangedSinceOpen() const;
0139 
0140 private:
0141     GooFile(HANDLE handleA);
0142     HANDLE handle;
0143     struct _FILETIME modifiedTimeOnOpen;
0144 #else
0145     ~GooFile() { close(fd); }
0146 
0147     bool modificationTimeChangedSinceOpen() const;
0148 
0149 private:
0150     explicit GooFile(int fdA);
0151     int fd;
0152     struct timespec modifiedTimeOnOpen;
0153 #endif // _WIN32
0154 };
0155 
0156 #endif