1 //========================================================================
5 // Miscellaneous file and directory name manipulation.
7 // Copyright 1996-2003 Glyph & Cog, LLC
9 //========================================================================
19 # include <sys/stat.h>
21 # include <win32lib.h>
31 # include <sys/types.h>
33 # include "vms_dirent.h"
36 # define NAMLEN(d) strlen((d)->d_name)
38 # define dirent direct
39 # define NAMLEN(d) (d)->d_namlen
41 # include <sys/ndir.h>
55 //------------------------------------------------------------------------
57 // Get home directory path.
58 extern GString *getHomeDir();
60 // Get current directory.
61 extern GString *getCurrentDir();
63 /* create a temporary filename */
64 char* mktmpname(char*ptr);
66 // Append a file name to a path string. <path> may be an empty
67 // string, denoting the current directory). Returns <path>.
68 extern GString *appendToPath(GString *path, char *fileName);
70 // Grab the path from the front of the file name. If there is no
71 // directory component in <fileName>, returns an empty string.
72 extern GString *grabPath(char *fileName);
74 // Is this an absolute path or file name?
75 extern GBool isAbsolutePath(char *path);
77 // Make this path absolute by prepending current directory (if path is
78 // relative) or prepending user's directory (if path starts with '~').
79 extern GString *makePathAbsolute(GString *path);
81 // Get the modification time for <fileName>. Returns 0 if there is an
83 extern time_t getModTime(char *fileName);
85 // Create a temporary file and open it for writing. If <ext> is not
86 // NULL, it will be used as the file name extension. Returns both the
87 // name and the file pointer. For security reasons, all writing
88 // should be done to the returned file pointer; the file may be
89 // reopened later for reading, but not for writing. The <mode> string
90 // should be "w" or "wb". Returns true on success.
91 extern GBool openTempFile(GString **name, FILE **f, char *mode, char *ext);
93 // Execute <command>. Returns true on success.
94 extern GBool executeCommand(char *cmd);
96 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
98 extern char *getLine(char *buf, int size, FILE *f);
100 //------------------------------------------------------------------------
101 // GDir and GDirEntry
102 //------------------------------------------------------------------------
107 GDirEntry(char *dirPath, char *nameA, GBool doStat);
109 GString *getName() { return name; }
110 GBool isDir() { return dir; }
114 GString *name; // dir/file name
115 GBool dir; // is it a directory?
121 GDir(char *name, GBool doStatA = gTrue);
123 GDirEntry *getNextEntry();
128 GString *path; // directory path
129 GBool doStat; // call stat() for each entry?
136 DIR *dir; // the DIR structure from opendir()
138 GBool needParent; // need to return an entry for [-]