KDELibs4Support

kde_file.h
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3  Copyright (C) 2001 Waldo Bastian <[email protected]>
4  Copyright (C) 2004 JarosÅ‚aw Staniek <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef _KDE_FILE_H_
22 #define _KDE_FILE_H_
23 
33 #include <fcntl.h>
34 #include <sys/stat.h>
35 #include <unistd.h>
36 #include <utime.h>
37 #if defined _WIN32 || defined _WIN64
38 #include <kde_file_win.h>
39 #endif
40 #include <kdelibs4support_export.h>
41 
42 /* added not for Solaris and OpenSolaris platforms */
43 
44 #if (defined _LFS64_LARGEFILE) && (defined _LARGEFILE64_SOURCE) && (!defined _GNU_SOURCE) && (!defined __sun)
45 /*
46  * This section provides portable defines for large file support.
47  * To use this you must compile your code with _LARGEFILE64_SOURCE
48  * defined and use the KDE_xxx defines instead of the normal
49  * C functions and structures.
50  *
51  * Please note that not every platform supports 64 bit file structures,
52  * in that case the normal 32 bit functions will be used.
53  *
54  * @see http://www.suse.de/~aj/linux_lfs.html
55  * @see http://ftp.sas.com/standards/large.file/xopen/x_open.05Mar96.html
56  *
57  * KDE makes use of the "Transitional Extensions" since we can not ensure
58  * that all modules and libraries used by KDE will be compiled with
59  * 64-bit support.
60  * (A.3.2.3 Mixed API and Compile Environments within a Single Process)
61  */
62 #define KDE_stat ::stat64
63 #define KDE_lstat ::lstat64
64 #define KDE_fstat ::fstat64
65 #define KDE_open ::open64
66 #define KDE_lseek ::lseek64
67 #define KDE_fseek ::fseek64
68 #define KDE_ftell ::ftell64
69 #define KDE_fgetpos ::fgetpos64
70 #define KDE_fsetpos ::fsetpos64
71 #define KDE_readdir ::readdir64
72 #define KDE_sendfile ::sendfile64
73 #define KDE_struct_stat struct stat64
74 #define KDE_struct_dirent struct dirent64
75 #define KDE_rename ::rename
76 #define KDE_mkdir ::mkdir
77 /* TODO: define for win32 */
78 
79 #else /* !_LFS64_LARGEFILE */
80 
81 /*
82  * This section defines portable defines for standard file support.
83  */
84 
85 /*
86  Platform specific definitions for Solaris and OpenSolaris tested with gcc 4.3.2
87 */
88 #if defined __sun__
89 #define KDE_stat ::stat
90 #define KDE_lstat ::lstat
91 #define KDE_fstat ::fstat
92 #define KDE_open ::open
93 #define KDE_lseek ::lseek
94 #define KDE_fseek ::fseek
95 #define KDE_ftell ::ftell
96 #define KDE_fgetpos ::fgetpos
97 #define KDE_fsetpos ::fsetpos
98 #define KDE_readdir ::readdir
99 #define KDE_sendfile ::sendfile
100 #define KDE_struct_stat struct stat
101 #define KDE_struct_dirent struct dirent
102 #define KDE_rename ::rename
103 #define KDE_mkdir ::mkdir
104 
105 #else
106 
107 #if defined _WIN32 || defined _WIN64
108 #define KDE_stat kdewin32_stat
109 #define KDE_lstat kdewin32_lstat
110 #define KDE_open kdewin32_open
111 #define KDE_rename kdewin32_rename
112 #define KDE_mkdir kdewin32_mkdir
113 #else /* unix */
114 #define KDE_stat ::stat
115 #define KDE_lstat ::lstat
116 #define KDE_open ::open
117 #define KDE_rename ::rename
118 #define KDE_mkdir ::mkdir
119 #endif
120 
121 #define KDE_fstat ::fstat
122 #define KDE_lseek ::lseek
123 #define KDE_fseek ::fseek
124 #define KDE_ftell ::ftell
125 #define KDE_fgetpos ::fgetpos
126 #define KDE_fsetpos ::fsetpos
127 #define KDE_readdir ::readdir
128 #define KDE_sendfile ::sendfile
129 #define KDE_struct_stat struct stat
130 #define KDE_struct_dirent struct dirent
131 #endif
132 
133 #ifdef _LFS64_STDIO
134 #define KDE_fopen ::fopen64
135 #define KDE_freopen ::freopen64
136 /* TODO: define for win32 */
137 #else
138 #if defined _WIN32 || defined _WIN64
139 #define KDE_fopen kdewin32_fopen
140 #define KDE_freopen kdewin32_freopen
141 #else /* unix */
142 #define KDE_fopen ::fopen
143 #endif
144 #endif
145 #endif
146 
147 /* functions without 64-bit version but wrapped for compatibility reasons */
148 #if defined _WIN32 || defined _WIN64
149 #define KDE_fdopen kdewin32_fdopen
150 #define KDE_signal kdewin32_signal
151 #else /* unix */
152 #define KDE_fdopen ::fdopen
153 #define KDE_signal ::signal
154 #endif
155 
156 #include <QFile>
157 class QString;
158 namespace KDE
159 {
161 KDELIBS4SUPPORT_DEPRECATED_EXPORT int access(const QString &path, int mode);
163 KDELIBS4SUPPORT_DEPRECATED_EXPORT int chmod(const QString &path, mode_t mode);
165 KDELIBS4SUPPORT_DEPRECATED_EXPORT FILE *fopen(const QString &pathname, const char *mode);
167 KDELIBS4SUPPORT_DEPRECATED_EXPORT int lstat(const QString &path, KDE_struct_stat *buf);
169 KDELIBS4SUPPORT_DEPRECATED_EXPORT int mkdir(const QString &pathname, mode_t mode);
171 KDELIBS4SUPPORT_DEPRECATED_EXPORT int open(const QString &pathname, int flags, mode_t mode = 0);
173 KDELIBS4SUPPORT_DEPRECATED_EXPORT int rename(const QString &in, const QString &out);
175 KDELIBS4SUPPORT_DEPRECATED_EXPORT int stat(const QString &path, KDE_struct_stat *buf);
177 KDELIBS4SUPPORT_DEPRECATED_EXPORT int utime(const QString &filename, struct utimbuf *buf);
178 #ifndef Q_OS_WIN
179 inline int access(const QString &path, int mode)
180 {
181  return ::access(QFile::encodeName(path).constData(), mode);
182 }
183 inline int chmod(const QString &path, mode_t mode)
184 {
185  return ::chmod(QFile::encodeName(path).constData(), mode);
186 }
187 inline FILE *fopen(const QString &pathname, const char *mode)
188 {
189  return KDE_fopen(QFile::encodeName(pathname).constData(), mode);
190 }
191 inline int lstat(const QString &path, KDE_struct_stat *buf)
192 {
193  return KDE_lstat(QFile::encodeName(path).constData(), buf);
194 }
195 inline int mkdir(const QString &pathname, mode_t mode)
196 {
197  return KDE_mkdir(QFile::encodeName(pathname).constData(), mode);
198 }
199 inline int open(const QString &pathname, int flags, mode_t mode)
200 {
201  return KDE_open(QFile::encodeName(pathname).constData(), flags, mode);
202 }
203 inline int rename(const QString &in, const QString &out)
204 {
205  return KDE_rename(QFile::encodeName(in).constData(), QFile::encodeName(out).constData());
206 }
207 inline int stat(const QString &path, KDE_struct_stat *buf)
208 {
209  return KDE_stat(QFile::encodeName(path).constData(), buf);
210 }
211 inline int utime(const QString &filename, struct utimbuf *buf)
212 {
213  return ::utime(QFile::encodeName(filename).constData(), buf);
214 }
215 #endif
216 }
217 
218 #if defined _WIN32 || defined _WIN64
219 #define KPATH_SEPARATOR ';'
220 #else
221 #ifndef O_BINARY
222 #define O_BINARY 0 /* for open() */
223 #endif
224 #define KPATH_SEPARATOR ':'
225 #endif
226 
227 #endif /* _KDE_FILE_H_ */
FILE * fopen(const QString &pathname, const char *mode)
replacement for fopen()/::fopen64() to handle filenames in a platform independent way ...
Definition: kde_file.h:187
int mkdir(const QString &pathname, mode_t mode)
replacement for mkdir() to handle pathnames in a platform independent way
Definition: kde_file.h:195
int stat(const QString &path, KDE_struct_stat *buf)
replacement for stat()/::stat64() to handle filenames in a platform independent way ...
Definition: kde_file.h:207
int rename(const QString &in, const QString &out)
replacement for rename() to handle pathnames in a platform independent way
Definition: kde_file.h:203
int chmod(const QString &path, mode_t mode)
replacement for chmod() to handle filenames in a platform independent way
Definition: kde_file.h:183
Namespace for general KDE functions.
Definition: kde_file.h:158
int lstat(const QString &path, KDE_struct_stat *buf)
replacement for lstat()/::lstat64() to handle filenames in a platform independent way ...
Definition: kde_file.h:191
int open(const QString &pathname, int flags, mode_t mode=0)
replacement for open()/::open64() to handle filenames in a platform independent way ...
Definition: kde_file.h:199
int access(const QString &path, int mode)
replacement for access() to handle filenames in a platform independent way
Definition: kde_file.h:179
int utime(const QString &filename, struct utimbuf *buf)
replacement for utime() to handle filenames in a platform independent way
Definition: kde_file.h:211
QByteArray encodeName(const QString &fileName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Oct 22 2020 23:02:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.