"Fossies" - the Fresh Open Source Software Archive 
Member "xpdf-4.04/goo/gfile.h" (18 Apr 2022, 4565 Bytes) of package /linux/misc/xpdf-4.04.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
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 // Get the modification time for <fileName>. Returns 0 if there is an
68 // error.
69 extern time_t getModTime(char *fileName);
70
71 // Create a temporary file and open it for writing. If <ext> is not
72 // NULL, it will be used as the file name extension. Returns both the
73 // name and the file pointer. For security reasons, all writing
74 // should be done to the returned file pointer; the file may be
75 // reopened later for reading, but not for writing. The <mode> string
76 // should be "w" or "wb". Returns true on success.
77 extern GBool openTempFile(GString **name, FILE **f,
78 const char *mode, const char *ext);
79
80 // Create a directory. Returns true on success.
81 extern GBool createDir(char *path, int mode);
82
83 // Execute <command>. Returns true on success.
84 extern GBool executeCommand(char *cmd);
85
86 #ifdef _WIN32
87 // Convert a file name from Latin-1 to UTF-8.
88 extern GString *fileNameToUTF8(char *path);
89
90 // Convert a file name from UCS-2 to UTF-8.
91 extern GString *fileNameToUTF8(wchar_t *path);
92
93 // Convert a file name from UTF-8 to UCS-2. [out] has space for
94 // [outSize] wchar_t elements (including the trailing zero). Returns
95 // [out].
96 extern wchar_t *fileNameToUCS2(const char *path, wchar_t *out, size_t outSize);
97 #endif
98
99 // Open a file. On Windows, this converts the path from UTF-8 to
100 // UCS-2 and calls _wfopen(). On other OSes, this simply calls fopen().
101 extern FILE *openFile(const char *path, const char *mode);
102
103 #ifdef _WIN32
104 // If [wPath] is a Windows shortcut (.lnk file), read the target path
105 // and store it back into [wPath].
106 extern void readWindowsShortcut(wchar_t *wPath, size_t wPathSize);
107 #endif
108
109 // Create a directory. On Windows, this converts the path from UTF-8
110 // to UCS-2 and calls _wmkdir(), ignoring the mode argument. On other
111 // OSes, this simply calls mkdir().
112 extern int makeDir(const char *path, int mode);
113
114 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
115 // conventions.
116 extern char *getLine(char *buf, int size, FILE *f);
117
118 // Type used by gfseek/gftell for file offsets. This will be 64 bits
119 // on systems that support it.
120 #if HAVE_FSEEKO
121 typedef off_t GFileOffset;
122 #define GFILEOFFSET_MAX 0x7fffffffffffffffLL
123 #elif HAVE_FSEEK64
124 typedef long long GFileOffset;
125 #define GFILEOFFSET_MAX 0x7fffffffffffffffLL
126 #elif HAVE_FSEEKI64
127 typedef __int64 GFileOffset;
128 #define GFILEOFFSET_MAX 0x7fffffffffffffffLL
129 #else
130 typedef long GFileOffset;
131 #define GFILEOFFSET_MAX LONG_MAX
132 #endif
133
134 // Like fseek, but uses a 64-bit file offset if available.
135 extern int gfseek(FILE *f, GFileOffset offset, int whence);
136
137 // Like ftell, but returns a 64-bit file offset if available.
138 extern GFileOffset gftell(FILE *f);
139
140 // On Windows, this gets the Unicode command line and converts it to
141 // UTF-8. On other systems, this is a nop.
142 extern void fixCommandLine(int *argc, char **argv[]);
143
144 #endif