unix/SysFileSystem.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Kernel */
40 /* */
41 /* System support for FileSystem operations. */
42 /* */
43 /******************************************************************************/
44 
45 #ifndef Included_SysFileSystem
46 #define Included_SysFileSystem
47 
48 #include <limits.h>
49 #include <stdlib.h>
50 #include <stdio.h>
51 #include <dirent.h>
52 
53 #if defined(PATH_MAX)
54 # define MAXIMUM_PATH_LENGTH PATH_MAX + 1
55 #elif defined(_POSIX_PATH_MAX)
56 # define MAXIMUM_PATH_LENGTH _POSIX_PATH_MAX + 1
57 #else
58 # define MAXIMUM_PATH_LENGTH
59 #endif
60 
61 #if defined(FILENAME_MAX)
62 # define MAXIMUM_FILENAME_LENGTH FILENAME_MAX + 1
63 #elif defined(_MAX_FNAME)
64 # define MAXIMUM_FILENAME_LENGTH _MAX_FNAME + 1
65 #elif defined(_POSIX_NAME_MAX)
66 # define MAXIMUM_FILENAME_LENGTH _POSIX_NAME_MAX + 1
67 #else
68 # define MAXIMUM_FILENAME_LENGTH 256
69 #endif
70 
71 #define NAME_BUFFER_LENGTH (MAXIMUM_PATH_LENGTH + MAXIMUM_FILENAME_LENGTH)
72 
73 class RexxString;
74 
76 {
77 public:
78  enum
79  {
83  };
84 
85  static const char EOF_Marker;
86  static const char *EOL_Marker; // the end-of-line marker
87  static const char PathDelimiter; // directory path delimiter
88 
89  static const char *getTempFileName();
90  static bool searchFileName(const char * name, char *fullName);
91  static void qualifyStreamName(const char *unqualifiedName, char *qualifiedName, size_t bufferSize);
92  static bool fileExists(const char *name);
93  static bool searchName(const char *name, const char *path, const char *extension, char *resolvedName);
94  static bool primitiveSearchName(const char *name, const char *path, const char *extension, char *resolvedName);
95  static bool checkCurrentFile(const char *name, char *resolvedName);
96  static bool searchPath(const char *name, const char *path, char *resolvedName);
97  static bool hasExtension(const char *name);
98  static bool hasDirectory(const char *name);
99  static bool canonicalizeName(char *name);
100  static bool normalizePathName(const char *name, char *resolved);
101  static RexxString *extractDirectory(RexxString *file);
102  static RexxString *extractExtension(RexxString *file);
103  static RexxString *extractFile(RexxString *file);
104 
105  static bool deleteFile(const char *name);
106  static bool deleteDirectory(const char *name);
107  static bool isDirectory(const char *name);
108  static bool isReadOnly(const char *name);
109  static bool isWriteOnly(const char *name);
110  static bool isFile(const char *name);
111  static bool exists(const char *name);
112  static int64_t getLastModifiedDate(const char *name);
113  static uint64_t getFileLength(const char *name);
114  static bool makeDirectory(const char *name);
115  static bool moveFile(const char *oldName, const char *newName);
116  static bool isHidden(const char *name);
117  static bool setLastModifiedDate(const char *name, int64_t time);
118  static bool setFileReadOnly(const char *name);
119  static bool isCaseSensitive();
120  static int getRoots(char *roots);
121  static const char *getSeparator();
122  static const char *getPathSeparator();
123 };
124 
126 {
127 public:
128  SysFileIterator(const char *pattern);
130  void close();
131  bool hasNext();
132  void next(char *buffer);
133 protected:
134  bool completed; // the iteration completed flag
135  struct dirent *entry;
136  DIR *handle;
137 };
138 
139 #endif
140 
void next(char *buffer)
SysFileIterator(const char *pattern)
struct dirent * entry
static bool fileExists(const char *name)
static bool checkCurrentFile(const char *name, char *resolvedName)
static bool moveFile(const char *oldName, const char *newName)
static bool setLastModifiedDate(const char *name, int64_t time)
static bool canonicalizeName(char *name)
static const char * getSeparator()
static bool deleteFile(const char *name)
static bool normalizePathName(const char *name, char *resolved)
static bool deleteDirectory(const char *name)
static RexxString * extractFile(RexxString *file)
static bool setFileReadOnly(const char *name)
static const char * EOL_Marker
static bool hasDirectory(const char *name)
static const char * getTempFileName()
static int64_t getLastModifiedDate(const char *name)
static const char * getPathSeparator()
static int getRoots(char *roots)
static bool primitiveSearchName(const char *name, const char *path, const char *extension, char *resolvedName)
static bool searchName(const char *name, const char *path, const char *extension, char *resolvedName)
static bool makeDirectory(const char *name)
static RexxString * extractDirectory(RexxString *file)
static RexxString * extractExtension(RexxString *file)
static const char PathDelimiter
static bool isDirectory(const char *name)
static bool searchPath(const char *name, const char *path, char *resolvedName)
static bool isCaseSensitive()
static uint64_t getFileLength(const char *name)
static bool isWriteOnly(const char *name)
static void qualifyStreamName(const char *unqualifiedName, char *qualifiedName, size_t bufferSize)
static bool hasExtension(const char *name)
static const char EOF_Marker
static bool searchFileName(const char *name, char *fullName)
static bool isHidden(const char *name)
static bool isReadOnly(const char *name)
static bool exists(const char *name)
static bool isFile(const char *name)
#define MAXIMUM_FILENAME_LENGTH
#define MAXIMUM_PATH_LENGTH
signed __int64 int64_t
unsigned __int64 uint64_t