author | eilers <eilers> | 2003-11-03 16:52:18 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-11-03 16:52:18 (UTC) |
commit | d34dc773591a2d467c68875a68a671d6a809f861 (patch) (unidiff) | |
tree | b57e5ae15c51e3d87ca95d57aedfd1ca3db57bfe /library/filemanager.cpp | |
parent | ce84f2d8bdd65c438821f0457cdad6bbbfa73380 (diff) | |
download | opie-d34dc773591a2d467c68875a68a671d6a809f861.zip opie-d34dc773591a2d467c68875a68a671d6a809f861.tar.gz opie-d34dc773591a2d467c68875a68a671d6a809f861.tar.bz2 |
Porting Opie to MacOS-X.
The base system and all platform independent applications and platforms
should work.
Please see $OPIEDIR/development/macosx for details
-rw-r--r-- | library/filemanager.cpp | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp index cc657fa..91986a0 100644 --- a/library/filemanager.cpp +++ b/library/filemanager.cpp | |||
@@ -28,13 +28,22 @@ | |||
28 | 28 | ||
29 | #include <errno.h> | 29 | #include <errno.h> |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
33 | #include <dirent.h> | 33 | #include <dirent.h> |
34 | #include <sys/sendfile.h> | 34 | #ifdef Q_OS_MACX |
35 | // MacOS X does not have sendfile.. :( | ||
36 | // But maybe in the future.. !? | ||
37 | # ifdef SENDFILE | ||
38 | # include <sys/types.h> | ||
39 | # include <sys/socket.h> | ||
40 | # endif | ||
41 | #else | ||
42 | # include <sys/sendfile.h> | ||
43 | #endif /* Q_OS_MACX */ | ||
35 | #include <fcntl.h> | 44 | #include <fcntl.h> |
36 | 45 | ||
37 | /*! | 46 | /*! |
38 | \class FileManager | 47 | \class FileManager |
39 | \brief The FileManager class assists with AppLnk input/output. | 48 | \brief The FileManager class assists with AppLnk input/output. |
40 | */ | 49 | */ |
@@ -213,12 +222,14 @@ bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest ) | |||
213 | QFile::remove( fn.latin1() ); | 222 | QFile::remove( fn.latin1() ); |
214 | } | 223 | } |
215 | 224 | ||
216 | return ok; | 225 | return ok; |
217 | } | 226 | } |
218 | 227 | ||
228 | |||
229 | |||
219 | bool FileManager::copyFile( const QString & src, const QString & dest ) { | 230 | bool FileManager::copyFile( const QString & src, const QString & dest ) { |
220 | bool success = true; | 231 | bool success = true; |
221 | struct stat status; | 232 | struct stat status; |
222 | int read_fd=0; | 233 | int read_fd=0; |
223 | int write_fd=0; | 234 | int write_fd=0; |
224 | struct stat stat_buf; | 235 | struct stat stat_buf; |
@@ -235,23 +246,55 @@ bool FileManager::copyFile( const QString & src, const QString & dest ) { | |||
235 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) | 246 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) |
236 | return success = false; | 247 | return success = false; |
237 | write_fd = destFile.handle(); | 248 | write_fd = destFile.handle(); |
238 | if(write_fd != -1) { | 249 | if(write_fd != -1) { |
239 | int err=0; | 250 | int err=0; |
240 | QString msg; | 251 | QString msg; |
241 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | 252 | #ifdef Q_OS_MACX |
242 | if( err == -1) { | 253 | #ifdef SENDMAIL |
243 | switch(err) { | 254 | /* FreeBSD does support a different kind of |
244 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; | 255 | * sendfile. (eilers) |
245 | case EINVAL: msg = "Descriptor is not valid or locked. "; | 256 | * I took this from Very Secure FTPd |
246 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | 257 | * Licence: GPL |
247 | case EIO: msg = "Unspecified error while reading from in_fd."; | 258 | * Author: Chris Evans |
248 | }; | 259 | * sysdeputil.c |
249 | success = false; | 260 | */ |
250 | } | 261 | /* XXX - start_pos will truncate on 32-bit machines - can we |
251 | } else { | 262 | * say "start from current pos"? |
263 | */ | ||
264 | off_t written = 0; | ||
265 | int retval = 0; | ||
266 | retval = sendfile(read_fd, write_fd, offset, stat_buf.st_size, NULL, | ||
267 | &written, 0); | ||
268 | /* Translate to Linux-like retval */ | ||
269 | if (written > 0) | ||
270 | { | ||
271 | err = (int) written; | ||
272 | } | ||
273 | #else /* SENDMAIL */ | ||
274 | err == -1; | ||
275 | msg = "FAILURE: Using unsupported function \"sendfile()\" Need Workaround !!"; | ||
276 | success = false; | ||
277 | # warning "Need workaround for sendfile!!(eilers)" | ||
278 | #endif /* SENDMAIL */ | ||
279 | |||
280 | #else | ||
281 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | ||
282 | if( err == -1) { | ||
283 | switch(err) { | ||
284 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; | ||
285 | case EINVAL: msg = "Descriptor is not valid or locked. "; | ||
286 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | ||
287 | case EIO: msg = "Unspecified error while reading from in_fd."; | ||
288 | }; | ||
289 | success = false; | ||
290 | } | ||
291 | #endif /* Q_OS_MACX */ | ||
292 | if( !success ) | ||
293 | qWarning( msg ); | ||
294 | } else { | ||
252 | qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); | 295 | qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); |
253 | success = false; | 296 | success = false; |
254 | } | 297 | } |
255 | } else { | 298 | } else { |
256 | qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); | 299 | qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); |
257 | success = false; | 300 | success = false; |