File indexing completed on 2024-03-24 15:27:20

0001 /*
0002    This file is part of the KDE libraries
0003    Copyright (C) 2001 Waldo Bastian <bastian@kde.org>
0004    Copyright (C) 2004 Jarosław Staniek <staniek@kde.org>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License version 2 as published by the Free Software Foundation.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef _KDE_FILE_H_
0022 #define _KDE_FILE_H_
0023 
0024 /**
0025  * \file kde_file.h
0026  * \brief This file provides portable defines for file support.
0027  *
0028  * Use the KDE_xxx defines instead of the normal C
0029  * functions and structures.
0030  * \since 3.3
0031  */
0032 
0033 #include <fcntl.h>
0034 #include <sys/stat.h>
0035 #include <unistd.h>
0036 #include <utime.h>
0037 #if defined _WIN32 || defined _WIN64
0038 #include <kde_file_win.h>
0039 #endif
0040 #include <kdelibs4support_export.h>
0041 
0042 /* added not for Solaris and OpenSolaris platforms */
0043 
0044 #if (defined _LFS64_LARGEFILE) && (defined _LARGEFILE64_SOURCE) && (!defined _GNU_SOURCE) && (!defined __sun)
0045 /*
0046  * This section provides portable defines for large file support.
0047  * To use this you must compile your code with _LARGEFILE64_SOURCE
0048  * defined and use the KDE_xxx defines instead of the normal
0049  * C functions and structures.
0050  *
0051  * Please note that not every platform supports 64 bit file structures,
0052  * in that case the normal 32 bit functions will be used.
0053  *
0054  * @see http://www.suse.de/~aj/linux_lfs.html
0055  * @see http://ftp.sas.com/standards/large.file/xopen/x_open.05Mar96.html
0056  *
0057  * KDE makes use of the "Transitional Extensions" since we can not ensure
0058  * that all modules and libraries used by KDE will be compiled with
0059  * 64-bit support.
0060  * (A.3.2.3 Mixed API and Compile Environments within a Single Process)
0061  */
0062 #define KDE_stat        ::stat64
0063 #define KDE_lstat       ::lstat64
0064 #define KDE_fstat       ::fstat64
0065 #define KDE_open        ::open64
0066 #define KDE_lseek       ::lseek64
0067 #define KDE_fseek       ::fseek64
0068 #define KDE_ftell       ::ftell64
0069 #define KDE_fgetpos     ::fgetpos64
0070 #define KDE_fsetpos     ::fsetpos64
0071 #define KDE_readdir     ::readdir64
0072 #define KDE_sendfile        ::sendfile64
0073 #define KDE_struct_stat     struct stat64
0074 #define KDE_struct_dirent   struct dirent64
0075 #define KDE_rename      ::rename
0076 #define KDE_mkdir       ::mkdir
0077 /* TODO: define for win32 */
0078 
0079 #else /* !_LFS64_LARGEFILE */
0080 
0081 /*
0082  * This section defines portable defines for standard file support.
0083  */
0084 
0085 /*
0086      Platform specific definitions for Solaris and OpenSolaris tested with gcc 4.3.2
0087 */
0088 #if defined __sun__
0089 #define KDE_stat        ::stat
0090 #define KDE_lstat       ::lstat
0091 #define KDE_fstat       ::fstat
0092 #define KDE_open        ::open
0093 #define KDE_lseek       ::lseek
0094 #define KDE_fseek       ::fseek
0095 #define KDE_ftell       ::ftell
0096 #define KDE_fgetpos     ::fgetpos
0097 #define KDE_fsetpos     ::fsetpos
0098 #define KDE_readdir     ::readdir
0099 #define KDE_sendfile        ::sendfile
0100 #define KDE_struct_stat     struct stat
0101 #define KDE_struct_dirent   struct dirent
0102 #define KDE_rename      ::rename
0103 #define KDE_mkdir       ::mkdir
0104 
0105 #else
0106 
0107 #if defined _WIN32 || defined _WIN64
0108 #define KDE_stat        kdewin32_stat
0109 #define KDE_lstat       kdewin32_lstat
0110 #define KDE_open        kdewin32_open
0111 #define KDE_rename      kdewin32_rename
0112 #define KDE_mkdir       kdewin32_mkdir
0113 #else /* unix */
0114 #define KDE_stat        ::stat
0115 #define KDE_lstat       ::lstat
0116 #define KDE_open        ::open
0117 #define KDE_rename      ::rename
0118 #define KDE_mkdir       ::mkdir
0119 #endif
0120 
0121 #define KDE_fstat       ::fstat
0122 #define KDE_lseek       ::lseek
0123 #define KDE_fseek       ::fseek
0124 #define KDE_ftell       ::ftell
0125 #define KDE_fgetpos     ::fgetpos
0126 #define KDE_fsetpos     ::fsetpos
0127 #define KDE_readdir     ::readdir
0128 #define KDE_sendfile        ::sendfile
0129 #define KDE_struct_stat     struct stat
0130 #define KDE_struct_dirent   struct dirent
0131 #endif
0132 
0133 #ifdef _LFS64_STDIO
0134 #define KDE_fopen       ::fopen64
0135 #define KDE_freopen     ::freopen64
0136 /* TODO: define for win32 */
0137 #else
0138 #if defined _WIN32 || defined _WIN64
0139 #define KDE_fopen       kdewin32_fopen
0140 #define KDE_freopen     kdewin32_freopen
0141 #else /* unix */
0142 #define KDE_fopen       ::fopen
0143 #endif
0144 #endif
0145 #endif
0146 
0147 /* functions without 64-bit version but wrapped for compatibility reasons */
0148 #if defined _WIN32 || defined _WIN64
0149 #define KDE_fdopen  kdewin32_fdopen
0150 #define KDE_signal  kdewin32_signal
0151 #else /* unix */
0152 #define KDE_fdopen  ::fdopen
0153 #define KDE_signal  ::signal
0154 #endif
0155 
0156 #include <QFile>
0157 class QString;
0158 namespace KDE
0159 {
0160 /** replacement for ::access() to handle filenames in a platform independent way */
0161 KDELIBS4SUPPORT_DEPRECATED_EXPORT int access(const QString &path, int mode);
0162 /** replacement for ::chmod() to handle filenames in a platform independent way */
0163 KDELIBS4SUPPORT_DEPRECATED_EXPORT int chmod(const QString &path, mode_t mode);
0164 /** replacement for ::fopen()/::fopen64() to handle filenames in a platform independent way */
0165 KDELIBS4SUPPORT_DEPRECATED_EXPORT FILE *fopen(const QString &pathname, const char *mode);
0166 /** replacement for ::lstat()/::lstat64() to handle filenames in a platform independent way */
0167 KDELIBS4SUPPORT_DEPRECATED_EXPORT int lstat(const QString &path, KDE_struct_stat *buf);
0168 /** replacement for ::mkdir() to handle pathnames in a platform independent way */
0169 KDELIBS4SUPPORT_DEPRECATED_EXPORT int mkdir(const QString &pathname, mode_t mode);
0170 /** replacement for ::open()/::open64() to handle filenames in a platform independent way */
0171 KDELIBS4SUPPORT_DEPRECATED_EXPORT int open(const QString &pathname, int flags, mode_t mode = 0);
0172 /** replacement for ::rename() to handle pathnames in a platform independent way */
0173 KDELIBS4SUPPORT_DEPRECATED_EXPORT int rename(const QString &in, const QString &out);
0174 /** replacement for ::stat()/::stat64() to handle filenames in a platform independent way */
0175 KDELIBS4SUPPORT_DEPRECATED_EXPORT int stat(const QString &path, KDE_struct_stat *buf);
0176 /** replacement for ::utime() to handle filenames in a platform independent way */
0177 KDELIBS4SUPPORT_DEPRECATED_EXPORT int utime(const QString &filename, struct utimbuf *buf);
0178 #ifndef Q_OS_WIN
0179 inline int access(const QString &path, int mode)
0180 {
0181     return ::access(QFile::encodeName(path).constData(), mode);
0182 }
0183 inline int chmod(const QString &path, mode_t mode)
0184 {
0185     return ::chmod(QFile::encodeName(path).constData(), mode);
0186 }
0187 inline FILE *fopen(const QString &pathname, const char *mode)
0188 {
0189     return KDE_fopen(QFile::encodeName(pathname).constData(), mode);
0190 }
0191 inline int lstat(const QString &path, KDE_struct_stat *buf)
0192 {
0193     return KDE_lstat(QFile::encodeName(path).constData(), buf);
0194 }
0195 inline int mkdir(const QString &pathname, mode_t mode)
0196 {
0197     return KDE_mkdir(QFile::encodeName(pathname).constData(), mode);
0198 }
0199 inline int open(const QString &pathname, int flags, mode_t mode)
0200 {
0201     return KDE_open(QFile::encodeName(pathname).constData(), flags, mode);
0202 }
0203 inline int rename(const QString &in, const QString &out)
0204 {
0205     return KDE_rename(QFile::encodeName(in).constData(), QFile::encodeName(out).constData());
0206 }
0207 inline int stat(const QString &path, KDE_struct_stat *buf)
0208 {
0209     return KDE_stat(QFile::encodeName(path).constData(), buf);
0210 }
0211 inline int utime(const QString &filename, struct utimbuf *buf)
0212 {
0213     return ::utime(QFile::encodeName(filename).constData(), buf);
0214 }
0215 #endif
0216 }
0217 
0218 #if defined _WIN32 || defined _WIN64
0219 #define KPATH_SEPARATOR ';'
0220 #else
0221 #ifndef O_BINARY
0222 #define O_BINARY 0 /* for open() */
0223 #endif
0224 #define KPATH_SEPARATOR ':'
0225 #endif
0226 
0227 #endif /* _KDE_FILE_H_ */