1 /*****************************************************************************/
2 /* */
3 /* FILESYS.H */
4 /* */
5 /* (C) 1995 Ullrich von Bassewitz */
6 /* Zwehrenbuehlstrasse 33 */
7 /* D-72070 Tuebingen */
8 /* EMail: uz@ibb.schwaben.com */
9 /* */
10 /*****************************************************************************/
11
12
13
14 //
15 // $Id$
16 //
17 // $Log$
18 //
19 //
20
21
22
23 #ifndef __FILESYS_H
24 #define __FILESYS_H
25
26
27
28 #include "str.h"
29
30
31
32 /*****************************************************************************/
33 /* File system & OS dependent constants */
34 /*****************************************************************************/
35
36
37
38 // The following constants describe features of the file system. To avoid
39 // compiler warnings (regarding dead code) the constants are not declared as
40 // static but as extern. This will result in somewhat larger code because
41 // in some places code is included that is never executed, but as there are
42 // only a few places, I thought it would be safer to get rid of the compiler
43 // warnings than to minimize code size.
44
45 extern const char FileSysPathSep; // Path separator
46 extern const char FileSysListSep; // Path list separator
47 extern const int FileSysMaxPath; // Maximum path length
48 extern const int FileSysMaxDir; // Maximum directory length
49 extern const int FileSysMaxName; // Maximum file name length
50 extern const int FileSysMaxExt; // Maximum extension length (including the dot)
51
52
53
54 /*****************************************************************************/
55 /* struct FileSysInfo */
56 /*****************************************************************************/
57
58
59
60 struct FileSysInfo {
61 char fsName [80]; // Name of the file system
62 // char fsValidChars [32]; // Bitset, 1 == valid file name char
63 unsigned fsMaxPath; // Maximum length of a path
64 unsigned fsMaxDir; // Maximum length of a directory
65 unsigned fsMaxName; // Maximum length of a file name
66 unsigned fsMaxExt; // Maximum length of a extension (including the dot)
67 char fsCurDir [256]; // Current directory
68 int fsPreservesCase; // 1 if filesys preserves case
69 int fsIgnoresCase; // 1 if filesys ignores case
70 };
71
72
73
74 /*****************************************************************************/
75 /* Code */
76 /*****************************************************************************/
77
78
79
80 int FileSysGetDrive ();
81 // Return the current drive. 1 = A:, 2 = B: and so on. On error, -1 is returned.
82 // This function may be called only if the system supports drives!
83
84 int FileSysSetDrive (unsigned Drive);
85 // Set the current drive. 1 = A:, 2 = B: and so on. On error, -1 is returned,
86 // otherwise zero. This function may be called only if the system supports
87 // drives!
88
89 int FileSysExtractDrive (const String& Path);
90 // Return the drive spec from the given path. If none given or if the os
91 // does not support drives (linux), the return value will be zero (== current).
92
93 void FileSysGetInfo (FileSysInfo& Info, int Drive = 0);
94 // Return detailed information regarding the file system on the given drive.
95 // See declaration of struct FileSysInfo above.
96
FileSysGetInfo(FileSysInfo & Info,const String & Path)97 inline void FileSysGetInfo (FileSysInfo& Info, const String& Path)
98 // Return detailed information regarding the file system on the given drive.
99 // See declaration of struct FileSysInfo above.
100 {
101 FileSysGetInfo (Info, FileSysExtractDrive (Path));
102 }
103
104 int FileSysPreservesCase (int Drive = 0);
105 // Return 1 if the file system on the given drive preserves the case in
106 // filenames
107
FileSysPreservesCase(const String & Path)108 inline int FileSysPreservesCase (const String& Path)
109 // Return 1 if the file system on the given drive preserves the case in
110 // filenames
111 {
112 return FileSysPreservesCase (FileSysExtractDrive (Path));
113 }
114
115 int FileSysIgnoresCase (int Drive = 0);
116 // Return 1 if the file system on the given drive ignores the case in file
117 // names. Beware: This is not the same as FileSysPreservesCase! The latter
118 // will return true if the file system preserves case in file names given,
119 // but when searching for files, the case can be ignored (this is the case
120 // with OS/2's HPFS file systems).
121
FileSysIgnoresCase(const String & Path)122 inline int FileSysIgnoresCase (const String& Path)
123 // Return 1 if the file system on the given drive ignores the case in file
124 // names. Beware: This is not the same as FileSysPreservesCase! The latter
125 // will return true if the file system preserves case in file names given,
126 // but when searching for files, the case can be ignored (this is the case
127 // with OS/2's HPFS file systems).
128 {
129 return FileSysIgnoresCase (FileSysExtractDrive (Path));
130 }
131
132 int FileSysValidChar (const char C);
133 // Return 1 if the given char is a valid part of a directory or file name.
134 // Because the function has no information about the file system, it assumes
135 // "worst case" and rejects every character that may be illegal on any of the
136 // supported file systems.
137
138 int FileSysValidName (const String& Path);
139 // Return 1 if the given path name consists of valid chars for the given
140 // file system. Beware: This function does not check if the path exists!
141
142 #ifdef FILESYS_HAS_DRIVES
143 String FileSysCurrentDir (int IncludeDrive = 1, int Drive = 0);
144 #else
145 String FileSysCurrentDir (int IncludeDrive = 0, int Drive = 0);
146 #endif
147 // Return the current directory. If IncludeDrive is true, the drive letter is
148 // included in the current directory. The default is to include the drive
149 // letter on systems that support drives. If the given drive is invalid, an
150 // empty string is returned.
151 // The returned path includes a trailing path separator.
152
153
154
155 // End of FILESYS.H
156
157 #endif
158
159
160
161
162
163