1 //========================================================================
5 // Miscellaneous file and directory name manipulation.
7 // Copyright 1996-2003 Glyph & Cog, LLC
9 //========================================================================
18 # include <sys/stat.h>
20 # include <win32lib.h>
29 # include <sys/types.h>
31 # include "vms_dirent.h"
34 # define NAMLEN(d) strlen((d)->d_name)
36 # define dirent direct
37 # define NAMLEN(d) (d)->d_namlen
39 # include <sys/ndir.h>
53 //------------------------------------------------------------------------
55 // Get home directory path.
56 extern GString
*getHomeDir();
58 // Get current directory.
59 extern GString
*getCurrentDir();
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
);
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
);
69 // Is this an absolute path or file name?
70 extern GBool
isAbsolutePath(char *path
);
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
);
76 // Get the modification time for <fileName>. Returns 0 if there is an
78 extern time_t getModTime(char *fileName
);
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
);
88 // Execute <command>. Returns true on success.
89 extern GBool
executeCommand(char *cmd
);
91 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
93 extern char *getLine(char *buf
, int size
, FILE *f
);
95 //------------------------------------------------------------------------
97 //------------------------------------------------------------------------
102 GDirEntry(char *dirPath
, char *nameA
, GBool doStat
);
104 GString
*getName() { return name
; }
105 GBool
isDir() { return dir
; }
109 GString
*name
; // dir/file name
110 GBool dir
; // is it a directory?
116 GDir(char *name
, GBool doStatA
= gTrue
);
118 GDirEntry
*getNextEntry();
123 GString
*path
; // directory path
124 GBool doStat
; // call stat() for each entry?
131 DIR *dir
; // the DIR structure from opendir()
133 GBool needParent
; // need to return an entry for [-]