summaryrefslogtreecommitdiff
path: root/qmake/tools/qfileinfo_unix.cpp
authorllornkcor <llornkcor>2003-07-10 02:40:10 (UTC)
committer llornkcor <llornkcor>2003-07-10 02:40:10 (UTC)
commit155d68c1e7d7dc0fed2534ac43d6d77ce2781f55 (patch) (unidiff)
treee6edaa5a7040fe6c224c3943d1094dcf02e4f74c /qmake/tools/qfileinfo_unix.cpp
parent86703e8a5527ef114facd02c005b6b3a7e62e263 (diff)
downloadopie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.zip
opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.gz
opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.bz2
update qmake to 1.05a
Diffstat (limited to 'qmake/tools/qfileinfo_unix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qfileinfo_unix.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/qmake/tools/qfileinfo_unix.cpp b/qmake/tools/qfileinfo_unix.cpp
index f7c3a97..364f219 100644
--- a/qmake/tools/qfileinfo_unix.cpp
+++ b/qmake/tools/qfileinfo_unix.cpp
@@ -25,307 +25,307 @@
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "qplatformdefs.h" 38#include "qplatformdefs.h"
39#include "qfileinfo.h" 39#include "qfileinfo.h"
40#include "qfiledefs_p.h" 40#include "qfiledefs_p.h"
41#include "qdatetime.h" 41#include "qdatetime.h"
42#include "qdir.h" 42#include "qdir.h"
43 43
44#include <limits.h> 44#include <limits.h>
45 45
46 46
47void QFileInfo::slashify( QString& ) 47void QFileInfo::slashify( QString& )
48{ 48{
49 return; 49 return;
50} 50}
51 51
52 52
53void QFileInfo::makeAbs( QString & ) 53void QFileInfo::makeAbs( QString & )
54{ 54{
55 return; 55 return;
56} 56}
57 57
58/*! 58/*!
59 Returns TRUE if this object points to a file. Returns FALSE if the 59 Returns TRUE if this object points to a file. Returns FALSE if the
60 object points to something which isn't a file, e.g. a directory or 60 object points to something which isn't a file, e.g. a directory or
61 a symlink. 61 a symlink.
62 62
63 \sa isDir(), isSymLink() 63 \sa isDir(), isSymLink()
64*/ 64*/
65bool QFileInfo::isFile() const 65bool QFileInfo::isFile() const
66{ 66{
67 if ( !fic || !cache ) 67 if ( !fic || !cache )
68 doStat(); 68 doStat();
69 return fic ? (fic->st.st_mode & S_IFMT) == S_IFREG : FALSE; 69 return fic ? (fic->st.st_mode & S_IFMT) == S_IFREG : FALSE;
70} 70}
71 71
72/*! 72/*!
73 Returns TRUE if this object points to a directory or to a symbolic 73 Returns TRUE if this object points to a directory or to a symbolic
74 link to a directory; otherwise returns FALSE. 74 link to a directory; otherwise returns FALSE.
75 75
76 \sa isFile(), isSymLink() 76 \sa isFile(), isSymLink()
77*/ 77*/
78bool QFileInfo::isDir() const 78bool QFileInfo::isDir() const
79{ 79{
80 if ( !fic || !cache ) 80 if ( !fic || !cache )
81 doStat(); 81 doStat();
82 return fic ? (fic->st.st_mode & S_IFMT) == S_IFDIR : FALSE; 82 return fic ? (fic->st.st_mode & S_IFMT) == S_IFDIR : FALSE;
83} 83}
84 84
85/*! 85/*!
86 Returns TRUE if this object points to a symbolic link (or to a 86 Returns TRUE if this object points to a symbolic link (or to a
87 shortcut on Windows); otherwise returns FALSE. 87 shortcut on Windows); otherwise returns FALSE.
88 88
89 \sa isFile(), isDir(), readLink() 89 \sa isFile(), isDir(), readLink()
90*/ 90*/
91 91
92bool QFileInfo::isSymLink() const 92bool QFileInfo::isSymLink() const
93{ 93{
94 if ( !fic || !cache ) 94 if ( !fic || !cache )
95 doStat(); 95 doStat();
96 return symLink; 96 return symLink;
97} 97}
98 98
99/*! 99/*!
100 Returns the name a symlink (or shortcut on Windows) points to, or 100 Returns the name a symlink (or shortcut on Windows) points to, or
101 a QString::null if the object isn't a symbolic link. 101 a QString::null if the object isn't a symbolic link.
102 102
103 This name may not represent an existing file; it is only a string. 103 This name may not represent an existing file; it is only a string.
104 QFileInfo::exists() returns TRUE if the symlink points to an 104 QFileInfo::exists() returns TRUE if the symlink points to an
105 existing file. 105 existing file.
106 106
107 \sa exists(), isSymLink(), isDir(), isFile() 107 \sa exists(), isSymLink(), isDir(), isFile()
108*/ 108*/
109 109
110QString QFileInfo::readLink() const 110QString QFileInfo::readLink() const
111{ 111{
112 QString r; 112 QString r;
113 113
114#if defined(Q_OS_UNIX) && !defined(Q_OS_OS2EMX) 114#if defined(Q_OS_UNIX) && !defined(Q_OS_OS2EMX)
115 char s[PATH_MAX+1]; 115 char s[PATH_MAX+1];
116 if ( !isSymLink() ) 116 if ( !isSymLink() )
117 return QString(); 117 return QString();
118 int len = readlink( QFile::encodeName(fn).data(), s, PATH_MAX ); 118 int len = readlink( QFile::encodeName(fn).data(), s, PATH_MAX );
119 if ( len >= 0 ) { 119 if ( len >= 0 ) {
120 s[len] = '\0'; 120 s[len] = '\0';
121 r = QFile::decodeName(s); 121 r = QFile::decodeName(s);
122 } 122 }
123#endif 123#endif
124 124
125 return r; 125 return r;
126} 126}
127 127
128static const uint nobodyID = (uint) -2; 128static const uint nobodyID = (uint) -2;
129 129
130/*! 130/*!
131 Returns the owner of the file. On Windows, on systems where files 131 Returns the owner of the file. On Windows, on systems where files
132 do not have owners, or if an error occurs, QString::null is 132 do not have owners, or if an error occurs, QString::null is
133 returned. 133 returned.
134 134
135 This function can be time consuming under Unix (in the order of 135 This function can be time consuming under Unix (in the order of
136 milliseconds). 136 milliseconds).
137 137
138 \sa ownerId(), group(), groupId() 138 \sa ownerId(), group(), groupId()
139*/ 139*/
140 140
141QString QFileInfo::owner() const 141QString QFileInfo::owner() const
142{ 142{
143 passwd *pw = getpwuid( ownerId() ); 143 passwd *pw = getpwuid( ownerId() );
144 if ( pw ) 144 if ( pw )
145 return QFile::decodeName( pw->pw_name ); 145 return QFile::decodeName( pw->pw_name );
146 return QString::null; 146 return QString::null;
147} 147}
148 148
149/*! 149/*!
150 Returns the id of the owner of the file. 150 Returns the id of the owner of the file.
151 151
152 On Windows and on systems where files do not have owners this 152 On Windows and on systems where files do not have owners this
153 function returns ((uint) -2). 153 function returns ((uint) -2).
154 154
155 \sa owner(), group(), groupId() 155 \sa owner(), group(), groupId()
156*/ 156*/
157 157
158uint QFileInfo::ownerId() const 158uint QFileInfo::ownerId() const
159{ 159{
160 if ( !fic || !cache ) 160 if ( !fic || !cache )
161 doStat(); 161 doStat();
162 if ( fic ) 162 if ( fic )
163 return fic->st.st_uid; 163 return fic->st.st_uid;
164 return nobodyID; 164 return nobodyID;
165} 165}
166 166
167/*! 167/*!
168 Returns the group of the file. On Windows, on systems where files 168 Returns the group of the file. On Windows, on systems where files
169 do not have groups, or if an error occurs, QString::null is 169 do not have groups, or if an error occurs, QString::null is
170 returned. 170 returned.
171 171
172 This function can be time consuming under Unix (in the order of 172 This function can be time consuming under Unix (in the order of
173 milliseconds). 173 milliseconds).
174 174
175 \sa groupId(), owner(), ownerId() 175 \sa groupId(), owner(), ownerId()
176*/ 176*/
177 177
178QString QFileInfo::group() const 178QString QFileInfo::group() const
179{ 179{
180 struct group *gr = getgrgid( groupId() ); 180 struct group *gr = getgrgid( groupId() );
181 if ( gr ) 181 if ( gr )
182 return QFile::decodeName( gr->gr_name ); 182 return QFile::decodeName( gr->gr_name );
183 return QString::null; 183 return QString::null;
184} 184}
185 185
186/*! 186/*!
187 Returns the id of the group the file belongs to. 187 Returns the id of the group the file belongs to.
188 188
189 On Windows and on systems where files do not have groups this 189 On Windows and on systems where files do not have groups this
190 function always returns (uint) -2. 190 function always returns (uint) -2.
191 191
192 \sa group(), owner(), ownerId() 192 \sa group(), owner(), ownerId()
193*/ 193*/
194 194
195uint QFileInfo::groupId() const 195uint QFileInfo::groupId() const
196{ 196{
197 if ( !fic || !cache ) 197 if ( !fic || !cache )
198 doStat(); 198 doStat();
199 if ( fic ) 199 if ( fic )
200 return fic->st.st_gid; 200 return fic->st.st_gid;
201 return nobodyID; 201 return nobodyID;
202} 202}
203 203
204 204
205/*! 205/*!
206 Tests for file permissions. The \a permissionSpec argument can be 206 Tests for file permissions. The \a permissionSpec argument can be
207 several flags of type \c PermissionSpec OR-ed together to check 207 several flags of type \c PermissionSpec OR-ed together to check
208 for permission combinations. 208 for permission combinations.
209 209
210 On systems where files do not have permissions this function 210 On systems where files do not have permissions this function
211 always returns TRUE. 211 always returns TRUE.
212 212
213 Example: 213 Example:
214 \code 214 \code
215 QFileInfo fi( "/tmp/archive.tar.gz" ); 215 QFileInfo fi( "/tmp/archive.tar.gz" );
216 if ( fi.permission( QFileInfo::WriteUser | QFileInfo::ReadGroup ) ) 216 if ( fi.permission( QFileInfo::WriteUser | QFileInfo::ReadGroup ) )
217 qWarning( "I can change the file; my group can read the file."); 217 qWarning( "I can change the file; my group can read the file" );
218 if ( fi.permission( QFileInfo::WriteGroup | QFileInfo::WriteOther ) ) 218 if ( fi.permission( QFileInfo::WriteGroup | QFileInfo::WriteOther ) )
219 qWarning( "The group or others can change the file!" ); 219 qWarning( "The group or others can change the file" );
220 \endcode 220 \endcode
221 221
222 \sa isReadable(), isWritable(), isExecutable() 222 \sa isReadable(), isWritable(), isExecutable()
223*/ 223*/
224 224
225bool QFileInfo::permission( int permissionSpec ) const 225bool QFileInfo::permission( int permissionSpec ) const
226{ 226{
227 if ( !fic || !cache ) 227 if ( !fic || !cache )
228 doStat(); 228 doStat();
229 if ( fic ) { 229 if ( fic ) {
230 uint mask = 0; 230 uint mask = 0;
231 if ( permissionSpec & ReadUser ) 231 if ( permissionSpec & ReadUser )
232 mask |= S_IRUSR; 232 mask |= S_IRUSR;
233 if ( permissionSpec & WriteUser ) 233 if ( permissionSpec & WriteUser )
234 mask |= S_IWUSR; 234 mask |= S_IWUSR;
235 if ( permissionSpec & ExeUser ) 235 if ( permissionSpec & ExeUser )
236 mask |= S_IXUSR; 236 mask |= S_IXUSR;
237 if ( permissionSpec & ReadGroup ) 237 if ( permissionSpec & ReadGroup )
238 mask |= S_IRGRP; 238 mask |= S_IRGRP;
239 if ( permissionSpec & WriteGroup ) 239 if ( permissionSpec & WriteGroup )
240 mask |= S_IWGRP; 240 mask |= S_IWGRP;
241 if ( permissionSpec & ExeGroup ) 241 if ( permissionSpec & ExeGroup )
242 mask |= S_IXGRP; 242 mask |= S_IXGRP;
243 if ( permissionSpec & ReadOther ) 243 if ( permissionSpec & ReadOther )
244 mask |= S_IROTH; 244 mask |= S_IROTH;
245 if ( permissionSpec & WriteOther ) 245 if ( permissionSpec & WriteOther )
246 mask |= S_IWOTH; 246 mask |= S_IWOTH;
247 if ( permissionSpec & ExeOther ) 247 if ( permissionSpec & ExeOther )
248 mask |= S_IXOTH; 248 mask |= S_IXOTH;
249 if ( mask ) { 249 if ( mask ) {
250 return (fic->st.st_mode & mask) == mask; 250 return (fic->st.st_mode & mask) == mask;
251 } else { 251 } else {
252#if defined(QT_CHECK_NULL) 252#if defined(QT_CHECK_NULL)
253 qWarning( "QFileInfo::permission: permissionSpec is 0" ); 253 qWarning( "QFileInfo::permission: permissionSpec is 0" );
254#endif 254#endif
255 return TRUE; 255 return TRUE;
256 } 256 }
257 } else { 257 } else {
258 return FALSE; 258 return FALSE;
259 } 259 }
260} 260}
261 261
262void QFileInfo::doStat() const 262void QFileInfo::doStat() const
263{ 263{
264 QFileInfo *that = ((QFileInfo*)this);// mutable function 264 QFileInfo *that = ((QFileInfo*)this);// mutable function
265 if ( !that->fic ) 265 if ( !that->fic )
266 that->fic = new QFileInfoCache; 266 that->fic = new QFileInfoCache;
267 that->symLink = FALSE; 267 that->symLink = FALSE;
268 struct stat *b = &that->fic->st; 268 struct stat *b = &that->fic->st;
269#if defined(Q_OS_UNIX) && defined(S_IFLNK) 269#if defined(Q_OS_UNIX) && defined(S_IFLNK)
270 if ( ::lstat( QFile::encodeName(fn), b ) == 0 ) { 270 if ( ::lstat( QFile::encodeName(fn), b ) == 0 ) {
271 if ( S_ISLNK( b->st_mode ) ) 271 if ( S_ISLNK( b->st_mode ) )
272 that->symLink = TRUE; 272 that->symLink = TRUE;
273 else 273 else
274 return; 274 return;
275 } 275 }
276#endif 276#endif
277 277
278 int r = ::stat( QFile::encodeName(fn), b ); 278 int r = ::stat( QFile::encodeName(fn), b );
279 if ( r != 0 && !that->symLink ) { 279 if ( r != 0 && !that->symLink ) {
280 delete that->fic; 280 delete that->fic;
281 that->fic = 0; 281 that->fic = 0;
282 } 282 }
283} 283}
284 284
285/*! 285/*!
286 Returns the file's path. 286 Returns the file's path.
287 287
288 If \a absPath is TRUE an absolute path is returned. 288 If \a absPath is TRUE an absolute path is returned.
289 289
290 \sa dir(), filePath(), fileName(), isRelative() 290 \sa dir(), filePath(), fileName(), isRelative()
291*/ 291*/
292#ifndef QT_NO_DIR 292#ifndef QT_NO_DIR
293QString QFileInfo::dirPath( bool absPath ) const 293QString QFileInfo::dirPath( bool absPath ) const
294{ 294{
295 QString s; 295 QString s;
296 if ( absPath ) 296 if ( absPath )
297 s = absFilePath(); 297 s = absFilePath();
298 else 298 else
299 s = fn; 299 s = fn;
300 int pos = s.findRev( '/' ); 300 int pos = s.findRev( '/' );
301 if ( pos == -1 ) { 301 if ( pos == -1 ) {
302 return QString::fromLatin1( "." ); 302 return QString::fromLatin1( "." );
303 } else { 303 } else {
304 if ( pos == 0 ) 304 if ( pos == 0 )
305 return QString::fromLatin1( "/" ); 305 return QString::fromLatin1( "/" );
306 return s.left( pos ); 306 return s.left( pos );
307 } 307 }
308} 308}
309#endif 309#endif
310 310
311/*! 311/*!
312 Returns the name of the file, excluding the path. 312 Returns the name of the file, excluding the path.
313 313
314 Example: 314 Example:
315 \code 315 \code
316 QFileInfo fi( "/tmp/archive.tar.gz" ); 316 QFileInfo fi( "/tmp/archive.tar.gz" );
317 QString name = fi.fileName(); // name = "archive.tar.gz" 317 QString name = fi.fileName(); // name = "archive.tar.gz"
318 \endcode 318 \endcode
319 319
320 \sa isRelative(), filePath(), baseName(), extension() 320 \sa isRelative(), filePath(), baseName(), extension()
321*/ 321*/
322 322
323QString QFileInfo::fileName() const 323QString QFileInfo::fileName() const
324{ 324{
325 int p = fn.findRev( '/' ); 325 int p = fn.findRev( '/' );
326 if ( p == -1 ) { 326 if ( p == -1 ) {
327 return fn; 327 return fn;
328 } else { 328 } else {
329 return fn.mid( p + 1 ); 329 return fn.mid( p + 1 );
330 } 330 }
331} 331}