Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gfile.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // gfile.h
00004 //
00005 // Miscellaneous file and directory name manipulation.
00006 //
00007 // Copyright 1996 Derek B. Noonburg
00008 //
00009 //========================================================================
00010 
00011 #ifndef GFILE_H
00012 #define GFILE_H
00013 
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <stddef.h>
00017 #if defined(WIN32)
00018 #  include <sys/stat.h>
00019 #  ifdef FPTEX
00020 #    include <win32lib.h>
00021 #  else
00022 #    include <windows.h>
00023 #  endif
00024 #elif defined(ACORN)
00025 #elif defined(MACOS)
00026 #  include <ctime.h>
00027 #else
00028 #  include <unistd.h>
00029 #  include <sys/types.h>
00030 #  ifdef VMS
00031 #    include "vms_dirent.h"
00032 #  elif HAVE_DIRENT_H
00033 #    include <dirent.h>
00034 #    define NAMLEN(d) strlen((d)->d_name)
00035 #  else
00036 #    define dirent direct
00037 #    define NAMLEN(d) (d)->d_namlen
00038 #    if HAVE_SYS_NDIR_H
00039 #      include <sys/ndir.h>
00040 #    endif
00041 #    if HAVE_SYS_DIR_H
00042 #      include <sys/dir.h>
00043 #    endif
00044 #    if HAVE_NDIR_H
00045 #      include <ndir.h>
00046 #    endif
00047 #  endif
00048 #endif
00049 #include "gtypes.h"
00050 
00051 class GString;
00052 
00053 //------------------------------------------------------------------------
00054 
00055 // Get home directory path.
00056 extern GString *getHomeDir();
00057 
00058 // Get current directory.
00059 extern GString *getCurrentDir();
00060 
00061 // Append a file name to a path string.  <path> may be an empty
00062 // string, denoting the current directory).  Returns <path>.
00063 extern GString *appendToPath(GString *path, char *fileName);
00064 
00065 // Grab the path from the front of the file name.  If there is no
00066 // directory component in <fileName>, returns an empty string.
00067 extern GString *grabPath(char *fileName);
00068 
00069 // Is this an absolute path or file name?
00070 extern GBool isAbsolutePath(char *path);
00071 
00072 // Make this path absolute by prepending current directory (if path is
00073 // relative) or prepending user's directory (if path starts with '~').
00074 extern GString *makePathAbsolute(GString *path);
00075 
00076 // Get the modification time for <fileName>.  Returns 0 if there is an
00077 // error.
00078 extern time_t getModTime(char *fileName);
00079 
00080 // Create a temporary file and open it for writing.  If <ext> is not
00081 // NULL, it will be used as the file name extension.  Returns both the
00082 // name and the file pointer.  For security reasons, all writing
00083 // should be done to the returned file pointer; the file may be
00084 // reopened later for reading, but not for writing.  The <mode> string
00085 // should be "w" or "wb".  Returns true on success.
00086 extern GBool openTempFile(GString **name, FILE **f, char *mode, char *ext);
00087 
00088 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
00089 // conventions.
00090 extern char *getLine(char *buf, int size, FILE *f);
00091 
00092 //------------------------------------------------------------------------
00093 // GDir and GDirEntry
00094 //------------------------------------------------------------------------
00095 
00096 class GDirEntry {
00097 public:
00098 
00099   GDirEntry(char *dirPath, char *nameA, GBool doStat);
00100   ~GDirEntry();
00101   GString *getName() { return name; }
00102   GBool isDir() { return dir; }
00103 
00104 private:
00105 
00106   GString *name;                // dir/file name
00107   GBool dir;                    // is it a directory?
00108 };
00109 
00110 class GDir {
00111 public:
00112 
00113   GDir(char *name, GBool doStatA = gTrue);
00114   ~GDir();
00115   GDirEntry *getNextEntry();
00116   void rewind();
00117 
00118 private:
00119 
00120   GString *path;                // directory path
00121   GBool doStat;                 // call stat() for each entry?
00122 #if defined(WIN32)
00123   WIN32_FIND_DATA ffd;
00124   HANDLE hnd;
00125 #elif defined(ACORN)
00126 #elif defined(MACOS)
00127 #else
00128   DIR *dir;                     // the DIR structure from opendir()
00129 #ifdef VMS
00130   GBool needParent;             // need to return an entry for [-]
00131 #endif
00132 #endif
00133 };
00134 
00135 #endif

Generated on Sat Nov 5 16:18:11 2005 for OPIE by  doxygen 1.4.2