Debian Codegraph @

libs/xpdf/xpdf-src/goo/gfile.h

raw
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 #ifndef GFILE_H
12 #define GFILE_H
13
14 #include <aconf.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <stddef.h>
18 #if defined(_WIN32)
19 # include <sys/stat.h>
20 # ifdef FPTEX
21 # include <win32lib.h>
22 # else
23 # include <windows.h>
24 # endif
25 #elif defined(ACORN)
26 #elif defined(ANDROID)
27 #else
28 # include <unistd.h>
29 # include <sys/types.h>
30 #endif
31 #include "gtypes.h"
32
33 // Windows 10 supports long paths - with a registry setting, and only
34 // with Unicode (...W) functions.
35 #ifdef _WIN32
36 # define winMaxLongPath 32767
37 #endif
38
39 class GString;
40
41 //------------------------------------------------------------------------
42
43 // Get home directory path.
44 extern GString *getHomeDir();
45
46 // Get current directory.
47 extern GString *getCurrentDir();
48
49 // Append a file name to a path string. <path> may be an empty
50 // string, denoting the current directory). Returns <path>.
51 extern GString *appendToPath(GString *path, const char *fileName);
52
53 // Grab the path from the front of the file name. If there is no
54 // directory component in <fileName>, returns an empty string.
55 extern GString *grabPath(char *fileName);
56
57 // Is this an absolute path or file name?
58 extern GBool isAbsolutePath(char *path);
59
60 // Make this path absolute by prepending current directory (if path is
61 // relative) or prepending user's directory (if path starts with '~').
62 extern GString *makePathAbsolute(GString *path);
63
64 // Returns true if [path] exists and is a regular file.
65 extern GBool pathIsFile(const char *path);
66
67 // Returns true if [path] exists and is a directory.
68 extern GBool pathIsDir(const char *path);
69
70 // Get the modification time for <fileName>. Returns 0 if there is an
71 // error.
72 extern time_t getModTime(char *fileName);
73
74 // Create a temporary file and open it for writing. If <ext> is not
75 // NULL, it will be used as the file name extension. Returns both the
76 // name and the file pointer. For security reasons, all writing
77 // should be done to the returned file pointer; the file may be
78 // reopened later for reading, but not for writing. The <mode> string
79 // should be "w" or "wb". Returns true on success.
80
81 #ifndef PDF_PARSER_ONLY
82 extern GBool openTempFile(GString **name, FILE **f,
83 const char *mode, const char *ext);
84 #endif /* !PDF_PARSER_ONLY */
85
86 // Create a directory. Returns true on success.
87 extern GBool createDir(char *path, int mode);
88
89 // Execute <command>. Returns true on success.
90 extern GBool executeCommand(char *cmd);
91
92 #ifdef _WIN32
93 // Convert a file name from Latin-1 to UTF-8.
94 extern GString *fileNameToUTF8(char *path);
95
96 // Convert a file name from UCS-2 to UTF-8.
97 extern GString *fileNameToUTF8(wchar_t *path);
98
99 // Convert a file name from the OEM code page to UTF-8.
100 extern GString *fileNameMultiByteToUTF8(char *path);
101
102 // Convert a file name from UTF-8 to UCS-2. [out] has space for
103 // [outSize] wchar_t elements (including the trailing zero). Returns
104 // [out].
105 extern wchar_t *fileNameToUCS2(const char *path, wchar_t *out, size_t outSize);
106 #endif
107
108 // Open a file. On Windows, this converts the path from UTF-8 to
109 // UCS-2 and calls _wfopen(). On other OSes, this simply calls fopen().
110 extern FILE *openFile(const char *path, const char *mode);
111
112 #if 0
113 // If [wPath] is a Windows shortcut (.lnk file), read the target path
114 // and store it back into [wPath].
115 extern void readWindowsShortcut(wchar_t *wPath, size_t wPathSize);
116 #endif
117
118 // Create a directory. On Windows, this converts the path from UTF-8
119 // to UCS-2 and calls _wmkdir(), ignoring the mode argument. On other
120 // OSes, this simply calls mkdir().
121 extern int makeDir(const char *path, int mode);
122
123 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
124 // conventions.
125 extern char *getLine(char *buf, int size, FILE *f);
126
127 // Type used by gfseek/gftell for file offsets. This will be 64 bits
128 // on systems that support it.
129 #if HAVE_FSEEKO
130 typedef off_t GFileOffset;
131 #define GFILEOFFSET_MAX 0x7fffffffffffffffLL
132 #elif HAVE_FSEEK64
133 typedef long long GFileOffset;
134 #define GFILEOFFSET_MAX 0x7fffffffffffffffLL
135 #elif HAVE_FSEEKI64
136 typedef __int64 GFileOffset;
137 #define GFILEOFFSET_MAX 0x7fffffffffffffffLL
138 #else
139 typedef long GFileOffset;
140 #define GFILEOFFSET_MAX LONG_MAX
141 #endif
142
143 // Like fseek, but uses a 64-bit file offset if available.
144 extern int gfseek(FILE *f, GFileOffset offset, int whence);
145
146 // Like ftell, but returns a 64-bit file offset if available.
147 extern GFileOffset gftell(FILE *f);
148
149 // On Windows, this gets the Unicode command line and converts it to
150 // UTF-8. On other systems, this is a nop.
151 #ifndef PDF_PARSER_ONLY
152 extern void fixCommandLine(int *argc, char **argv[]);
153 #endif /* !PDF_PARSER_ONLY */
154
155 #endif