fixed l_reserveobj (thanks to Marcel F. Krüger zauguin@gmail.com )
[luatex.git] / source / libs / poppler / poppler-0.34.0 / goo / gfile.h
blob1365a9cf2ab03ef9b24b8c6a3fc5323322a2835b
1 //========================================================================
2 //
3 // gfile.h
4 //
5 // Miscellaneous file and directory name manipulation.
6 //
7 // Copyright 1996-2003 Glyph & Cog, LLC
8 //
9 //========================================================================
11 //========================================================================
13 // Modified under the Poppler project - http://poppler.freedesktop.org
15 // All changes made under the Poppler project to this file are licensed
16 // under GPL version 2 or later
18 // Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com>
19 // Copyright (C) 2009, 2011, 2012 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 Adrian Johnson <ajohnson@redneon.com>
23 // Copyright (C) 2014 Bogdan Cristea <cristeab@gmail.com>
24 // Copyright (C) 2014 Peter Breitenlohner <peb@mppmu.mpg.de>
26 // To see a description of the changes please see the Changelog file that
27 // came with your tarball or type make ChangeLog if you are building from git
29 //========================================================================
31 #ifndef GFILE_H
32 #define GFILE_H
34 #include "poppler-config.h"
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <stddef.h>
38 extern "C" {
39 #if defined(_WIN32)
40 # include <sys/stat.h>
41 # ifdef FPTEX
42 # include <win32lib.h>
43 # else
44 # ifndef NOMINMAX
45 # define NOMINMAX
46 # endif
47 # include <windows.h>
48 # endif
49 #elif defined(ACORN)
50 #elif defined(MACOS)
51 # include <ctime.h>
52 #else
53 # include <unistd.h>
54 # include <sys/types.h>
55 # ifdef VMS
56 # include "vms_dirent.h"
57 # elif HAVE_DIRENT_H
58 # include <dirent.h>
59 # define NAMLEN(d) strlen((d)->d_name)
60 # else
61 # define dirent direct
62 # define NAMLEN(d) (d)->d_namlen
63 # if HAVE_SYS_NDIR_H
64 # include <sys/ndir.h>
65 # endif
66 # if HAVE_SYS_DIR_H
67 # include <sys/dir.h>
68 # endif
69 # if HAVE_NDIR_H
70 # include <ndir.h>
71 # endif
72 # endif
73 #endif
75 #include "gtypes.h"
77 class GooString;
79 //------------------------------------------------------------------------
81 // Get current directory.
82 extern GooString *getCurrentDir();
84 // Append a file name to a path string. <path> may be an empty
85 // string, denoting the current directory). Returns <path>.
86 extern GooString *appendToPath(GooString *path, const char *fileName);
88 // Grab the path from the front of the file name. If there is no
89 // directory component in <fileName>, returns an empty string.
90 extern GooString *grabPath(char *fileName);
92 // Is this an absolute path or file name?
93 extern GBool isAbsolutePath(char *path);
95 // Get the modification time for <fileName>. Returns 0 if there is an
96 // error.
97 extern time_t getModTime(char *fileName);
99 // Create a temporary file and open it for writing. If <ext> is not
100 // NULL, it will be used as the file name extension. Returns both the
101 // name and the file pointer. For security reasons, all writing
102 // should be done to the returned file pointer; the file may be
103 // reopened later for reading, but not for writing. The <mode> string
104 // should be "w" or "wb". Returns true on success.
105 extern GBool openTempFile(GooString **name, FILE **f, const char *mode);
107 #ifdef WIN32
108 // Convert a file name from Latin-1 to UTF-8.
109 extern GooString *fileNameToUTF8(char *path);
111 // Convert a file name from UCS-2 to UTF-8.
112 extern GooString *fileNameToUTF8(wchar_t *path);
113 #endif
115 // Open a file. On Windows, this converts the path from UTF-8 to
116 // UCS-2 and calls _wfopen (if available). On other OSes, this simply
117 // calls fopen.
118 extern FILE *openFile(const char *path, const char *mode);
120 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
121 // conventions.
122 extern char *getLine(char *buf, int size, FILE *f);
124 // Like fseek/ftell but uses platform specific variants that support large files
125 extern int Gfseek(FILE *f, Goffset offset, int whence);
126 extern Goffset Gftell(FILE *f);
128 // Largest offset supported by Gfseek/Gftell
129 extern Goffset GoffsetMax();
131 //------------------------------------------------------------------------
132 // GooFile
133 //------------------------------------------------------------------------
135 class GooFile
137 public:
138 int read(char *buf, int n, Goffset offset) const;
139 Goffset size() const;
141 static GooFile *open(const GooString *fileName);
143 #ifdef _WIN32
144 static GooFile *open(const wchar_t *fileName);
146 ~GooFile() { CloseHandle(handle); }
148 private:
149 GooFile(HANDLE handleA): handle(handleA) {}
150 HANDLE handle;
151 #else
152 ~GooFile() { close(fd); }
154 private:
155 GooFile(int fdA) : fd(fdA) {}
156 int fd;
157 #endif // _WIN32
160 //------------------------------------------------------------------------
161 // GDir and GDirEntry
162 //------------------------------------------------------------------------
164 class GDirEntry {
165 public:
167 GDirEntry(char *dirPath, char *nameA, GBool doStat);
168 ~GDirEntry();
169 GooString *getName() { return name; }
170 GooString *getFullPath() { return fullPath; }
171 GBool isDir() { return dir; }
173 private:
174 GDirEntry(const GDirEntry &other);
175 GDirEntry& operator=(const GDirEntry &other);
177 GooString *name; // dir/file name
178 GooString *fullPath;
179 GBool dir; // is it a directory?
182 class GDir {
183 public:
185 GDir(char *name, GBool doStatA = gTrue);
186 ~GDir();
187 GDirEntry *getNextEntry();
188 void rewind();
190 private:
191 GDir(const GDir &other);
192 GDir& operator=(const GDir &other);
194 GooString *path; // directory path
195 GBool doStat; // call stat() for each entry?
196 #if defined(_WIN32)
197 WIN32_FIND_DATA ffd;
198 HANDLE hnd;
199 #elif defined(ACORN)
200 #elif defined(MACOS)
201 #else
202 DIR *dir; // the DIR structure from opendir()
203 #ifdef VMS
204 GBool needParent; // need to return an entry for [-]
205 #endif
206 #endif
209 #endif