]> git.ipfire.org Git - thirdparty/cups.git/blob - pdftops/gfile.h
Copyright update.
[thirdparty/cups.git] / pdftops / gfile.h
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 <stdio.h>
15 #include <stdlib.h>
16 #include <stddef.h>
17 #if defined(WIN32)
18 # include <sys/stat.h>
19 # ifdef FPTEX
20 # include <win32lib.h>
21 # else
22 # include <windows.h>
23 # endif
24 #elif defined(ACORN)
25 #elif defined(MACOS)
26 # include <ctime.h>
27 #else
28 # include <unistd.h>
29 # include <sys/types.h>
30 # ifdef VMS
31 # include "vms_dirent.h"
32 # elif HAVE_DIRENT_H
33 # include <dirent.h>
34 # define NAMLEN(d) strlen((d)->d_name)
35 # else
36 # define dirent direct
37 # define NAMLEN(d) (d)->d_namlen
38 # if HAVE_SYS_NDIR_H
39 # include <sys/ndir.h>
40 # endif
41 # if HAVE_SYS_DIR_H
42 # include <sys/dir.h>
43 # endif
44 # if HAVE_NDIR_H
45 # include <ndir.h>
46 # endif
47 # endif
48 #endif
49 #include "gtypes.h"
50
51 class GString;
52
53 //------------------------------------------------------------------------
54
55 // Get home directory path.
56 extern GString *getHomeDir();
57
58 // Get current directory.
59 extern GString *getCurrentDir();
60
61 // Append a file name to a path string. <path> may be an empty
62 // string, denoting the current directory). Returns <path>.
63 extern GString *appendToPath(GString *path, char *fileName);
64
65 // Grab the path from the front of the file name. If there is no
66 // directory component in <fileName>, returns an empty string.
67 extern GString *grabPath(char *fileName);
68
69 // Is this an absolute path or file name?
70 extern GBool isAbsolutePath(char *path);
71
72 // Make this path absolute by prepending current directory (if path is
73 // relative) or prepending user's directory (if path starts with '~').
74 extern GString *makePathAbsolute(GString *path);
75
76 // Get the modification time for <fileName>. Returns 0 if there is an
77 // error.
78 extern time_t getModTime(char *fileName);
79
80 // Create a temporary file and open it for writing. If <ext> is not
81 // NULL, it will be used as the file name extension. Returns both the
82 // name and the file pointer. For security reasons, all writing
83 // should be done to the returned file pointer; the file may be
84 // reopened later for reading, but not for writing. The <mode> string
85 // should be "w" or "wb". Returns true on success.
86 extern GBool openTempFile(GString **name, FILE **f, char *mode, char *ext);
87
88 // Execute <command>. Returns true on success.
89 extern GBool executeCommand(char *cmd);
90
91 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
92 // conventions.
93 extern char *getLine(char *buf, int size, FILE *f);
94
95 //------------------------------------------------------------------------
96 // GDir and GDirEntry
97 //------------------------------------------------------------------------
98
99 class GDirEntry {
100 public:
101
102 GDirEntry(char *dirPath, char *nameA, GBool doStat);
103 ~GDirEntry();
104 GString *getName() { return name; }
105 GBool isDir() { return dir; }
106
107 private:
108
109 GString *name; // dir/file name
110 GBool dir; // is it a directory?
111 };
112
113 class GDir {
114 public:
115
116 GDir(char *name, GBool doStatA = gTrue);
117 ~GDir();
118 GDirEntry *getNextEntry();
119 void rewind();
120
121 private:
122
123 GString *path; // directory path
124 GBool doStat; // call stat() for each entry?
125 #if defined(WIN32)
126 WIN32_FIND_DATA ffd;
127 HANDLE hnd;
128 #elif defined(ACORN)
129 #elif defined(MACOS)
130 #else
131 DIR *dir; // the DIR structure from opendir()
132 #ifdef VMS
133 GBool needParent; // need to return an entry for [-]
134 #endif
135 #endif
136 };
137
138 #endif