]> git.ipfire.org Git - thirdparty/cups.git/blame - pdftops/gfile.h
Merge changes from CUPS 1.4svn-r7199.
[thirdparty/cups.git] / pdftops / gfile.h
CommitLineData
ef416fc2 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# else
33# include <dirent.h>
34# define NAMLEN(d) strlen((d)->d_name)
35# endif
36#endif
37#include "gtypes.h"
38
39class GString;
40
41//------------------------------------------------------------------------
42
43// Get home directory path.
44extern GString *getHomeDir();
45
46// Get current directory.
47extern 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>.
51extern GString *appendToPath(GString *path, 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.
55extern GString *grabPath(char *fileName);
56
57// Is this an absolute path or file name?
58extern 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 '~').
62extern GString *makePathAbsolute(GString *path);
63
64// Get the modification time for <fileName>. Returns 0 if there is an
65// error.
66extern time_t getModTime(char *fileName);
67
68// Create a temporary file and open it for writing. If <ext> is not
69// NULL, it will be used as the file name extension. Returns both the
70// name and the file pointer. For security reasons, all writing
71// should be done to the returned file pointer; the file may be
72// reopened later for reading, but not for writing. The <mode> string
73// should be "w" or "wb". Returns true on success.
74extern GBool openTempFile(GString **name, FILE **f, char *mode, char *ext);
75
76// Execute <command>. Returns true on success.
77extern GBool executeCommand(char *cmd);
78
79// Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
80// conventions.
81extern char *getLine(char *buf, int size, FILE *f);
82
83//------------------------------------------------------------------------
84// GDir and GDirEntry
85//------------------------------------------------------------------------
86
87class GDirEntry {
88public:
89
90 GDirEntry(char *dirPath, char *nameA, GBool doStat);
91 ~GDirEntry();
92 GString *getName() { return name; }
93 GBool isDir() { return dir; }
94
95private:
96
97 GString *name; // dir/file name
98 GBool dir; // is it a directory?
99};
100
101class GDir {
102public:
103
104 GDir(char *name, GBool doStatA = gTrue);
105 ~GDir();
106 GDirEntry *getNextEntry();
107 void rewind();
108
109private:
110
111 GString *path; // directory path
112 GBool doStat; // call stat() for each entry?
113#if defined(WIN32)
114 WIN32_FIND_DATA ffd;
115 HANDLE hnd;
116#elif defined(ACORN)
117#elif defined(MACOS)
118#else
119 DIR *dir; // the DIR structure from opendir()
120#ifdef VMS
121 GBool needParent; // need to return an entry for [-]
122#endif
123#endif
124};
125
126#endif