1 //========================================================================
5 // Miscellaneous file and directory name manipulation.
7 // Copyright 1996-2003 Glyph & Cog, LLC
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 //========================================================================
34 #include "poppler-config.h"
40 # include <sys/stat.h>
42 # include <win32lib.h>
54 # include <sys/types.h>
56 # include "vms_dirent.h"
59 # define NAMLEN(d) strlen((d)->d_name)
61 # define dirent direct
62 # define NAMLEN(d) (d)->d_namlen
64 # include <sys/ndir.h>
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
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
);
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
);
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
118 extern FILE *openFile(const char *path
, const char *mode
);
120 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
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 //------------------------------------------------------------------------
133 //------------------------------------------------------------------------
138 int read(char *buf
, int n
, Goffset offset
) const;
139 Goffset
size() const;
141 static GooFile
*open(const GooString
*fileName
);
144 static GooFile
*open(const wchar_t *fileName
);
146 ~GooFile() { CloseHandle(handle
); }
149 GooFile(HANDLE handleA
): handle(handleA
) {}
152 ~GooFile() { close(fd
); }
155 GooFile(int fdA
) : fd(fdA
) {}
160 //------------------------------------------------------------------------
161 // GDir and GDirEntry
162 //------------------------------------------------------------------------
167 GDirEntry(char *dirPath
, char *nameA
, GBool doStat
);
169 GooString
*getName() { return name
; }
170 GooString
*getFullPath() { return fullPath
; }
171 GBool
isDir() { return dir
; }
174 GDirEntry(const GDirEntry
&other
);
175 GDirEntry
& operator=(const GDirEntry
&other
);
177 GooString
*name
; // dir/file name
179 GBool dir
; // is it a directory?
185 GDir(char *name
, GBool doStatA
= gTrue
);
187 GDirEntry
*getNextEntry();
191 GDir(const GDir
&other
);
192 GDir
& operator=(const GDir
&other
);
194 GooString
*path
; // directory path
195 GBool doStat
; // call stat() for each entry?
202 DIR *dir
; // the DIR structure from opendir()
204 GBool needParent
; // need to return an entry for [-]