Upstream tarball 20080929
[amule.git] / src / PlatformSpecific.h
blob9c73084daf6fef2af015b0efd6dd9f86def13745
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #ifndef PLATFORMSPECIFIC_H
26 #define PLATFORMSPECIFIC_H
28 #include <common/Path.h>
29 #include "Types.h"
32 namespace PlatformSpecific {
35 /**
36 * Create sparse file.
38 * This function will create the named file sparse if possible.
40 * @param name The file to be created (sparse if possible).
41 * @param size The desired size of the file.
42 * @return true, if creating the file succeeded, false otherwise.
44 bool CreateSparseFile(const CPath& name, uint64_t size);
47 /**
48 * Returns the max number of connections the current OS can handle.
50 * Currently anything but windows will return the default value (-1);
52 #ifdef __WXMSW__
53 int GetMaxConnections();
54 #else
55 inline int GetMaxConnections() { return -1; }
56 #endif
59 /**
60 * File system types returned by GetFilesystemType
62 enum EFSType {
63 fsFAT, //! File Allocation Table
64 fsNTFS, //! New Technology File System
65 fsHFS, //! Hierarchical File System
66 fsHPFS, //! High Performace File System
67 fsMINIX, //! Minix file system
68 fsOther //! Unknown, other
71 /**
72 * Find out the filesystem type of the given path.
74 * @param path The path for which the filesystem type should be checked.
75 * @return The filesystem type of the given path.
77 * This function returns fsOther on unknown or network file systems (because the
78 * real filesystem type cannot be determined).
80 EFSType GetFilesystemType(const CPath& path);
83 /**
84 * Checks if the filesystem can handle special chars.
86 * @param path The path for which the file system should be checked.
87 * @return true if the underlying filesystem can handle special chars.
89 * This function checks if the file system of the given path can handle
90 * special chars e.g. ':' in file names. This function will always return
91 * false on MSW, since Windows cannot handle those characters on any file system.
93 * Based on http://en.wikipedia.org/wiki/Comparison_of_file_systems
95 #ifdef __WXMSW__
96 inline bool CanFSHandleSpecialChars(const CPath& WXUNUSED(path)) { return false; }
97 #else
98 // Other filesystem types may be added
99 inline bool CanFSHandleSpecialChars(const CPath& path)
101 switch (GetFilesystemType(path)) {
102 case fsFAT:
103 case fsHFS:
104 return false;
105 default:
106 return true;
109 #endif
113 * Check if the filesystem can handle large files.
115 * @param path The path for which the filesystem should be checked.
116 * @return true if the underlying filesystem can handle large files.
118 * This function checks if the file system of the given path can handle
119 * large files (>4GB).
121 * Based on http://en.wikipedia.org/wiki/Comparison_of_file_systems
123 inline bool CanFSHandleLargeFiles(const CPath& path)
125 switch (GetFilesystemType(path)) {
126 case fsFAT:
127 case fsHFS:
128 case fsHPFS:
129 case fsMINIX:
130 return false;
131 default:
132 return true;
137 }; /* namespace PlatformSpecific */
139 #endif /* PLATFORMSPECIFIC_H */