]> www.fi.muni.cz Git - evince.git/blob - pdf/goo/gfile.h
Synched with Xpdf 0.92
[evince.git] / pdf / goo / gfile.h
1 //========================================================================
2 //
3 // gfile.h
4 //
5 // Miscellaneous file and directory name manipulation.
6 //
7 // Copyright 1996 Derek B. Noonburg
8 //
9 //========================================================================
10
11 #ifndef GFILE_H
12 #define GFILE_H
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <stddef.h>
17 extern "C" {
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(MACOS)
27 #  include <ctime.h>
28 #else
29 #  include <unistd.h>
30 #  include <sys/types.h>
31 #  ifdef VMS
32 #    include "vms_dirent.h"
33 #  elif HAVE_DIRENT_H
34 #    include <dirent.h>
35 #    define NAMLEN(d) strlen((d)->d_name)
36 #  else
37 #    define dirent direct
38 #    define NAMLEN(d) (d)->d_namlen
39 #    if HAVE_SYS_NDIR_H
40 #      include <sys/ndir.h>
41 #    endif
42 #    if HAVE_SYS_DIR_H
43 #      include <sys/dir.h>
44 #    endif
45 #    if HAVE_NDIR_H
46 #      include <ndir.h>
47 #    endif
48 #  endif
49 #endif
50 }
51 #include "gtypes.h"
52
53 class GString;
54
55 //------------------------------------------------------------------------
56
57 // Get home directory path.
58 extern GString *getHomeDir();
59
60 // Get current directory.
61 extern GString *getCurrentDir();
62
63 // Append a file name to a path string.  <path> may be an empty
64 // string, denoting the current directory).  Returns <path>.
65 extern GString *appendToPath(GString *path, char *fileName);
66
67 // Grab the path from the front of the file name.  If there is no
68 // directory component in <fileName>, returns an empty string.
69 extern GString *grabPath(char *fileName);
70
71 // Is this an absolute path or file name?
72 extern GBool isAbsolutePath(char *path);
73
74 // Make this path absolute by prepending current directory (if path is
75 // relative) or prepending user's directory (if path starts with '~').
76 GString *makePathAbsolute(GString *path);
77
78 // Get the modification time for <fileName>.  Returns 0 if there is an
79 // error.
80 time_t getModTime(char *fileName);
81
82 // Create a temporary file and open it for writing.  If <ext> is not
83 // NULL, it will be used as the file name extension.  Returns both the
84 // name and the file pointer.  For security reasons, all writing
85 // should be done to the returned file pointer; the file may be
86 // reopened later for reading, but not for writing.  The <mode> string
87 // should be "w" or "wb".  Returns true on success.
88 GBool openTempFile(GString **name, FILE **f, char *mode, char *ext);
89
90 //------------------------------------------------------------------------
91 // GDir and GDirEntry
92 //------------------------------------------------------------------------
93
94 class GDirEntry {
95 public:
96
97   GDirEntry(char *dirPath, char *name1, GBool doStat);
98   ~GDirEntry();
99   GString *getName() { return name; }
100   GBool isDir() { return dir; }
101
102 private:
103
104   GString *name;                // dir/file name
105   GBool dir;                    // is it a directory?
106 };
107
108 class GDir {
109 public:
110
111   GDir(char *name, GBool doStat1 = gTrue);
112   ~GDir();
113   GDirEntry *getNextEntry();
114   void rewind();
115
116 private:
117
118   GString *path;                // directory path
119   GBool doStat;                 // call stat() for each entry?
120 #if defined(WIN32)
121   WIN32_FIND_DATA ffd;
122   HANDLE hnd;
123 #elif defined(ACORN)
124 #elif defined(MACOS)
125 #else
126   DIR *dir;                     // the DIR structure from opendir()
127 #ifdef VMS
128   GBool needParent;             // need to return an entry for [-]
129 #endif
130 #endif
131 };
132
133 #endif