Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I am looking copy files platform-dependently on Linux, Oracle Solaris, MacOS, BSDs, and Windows. I have found some system calls for each platform, namely sendfile(), copy_file_range(), fcopyfile()...
#5: Post edited
- I am looking copy files platform-dependently on Linux, Oracle Solaris, MacOS, BSDs, and Windows.
I have found some system calls for each platform, namely `sendfile()`, `copy_file_range()`, `fcopyfile()`, `CopyFile()` et cetera. But some of them are documented to copy file attributes, whilst some are not. I am uncertain whether better to do a `stat()` + `chmod()` for syscalls that do not copy attributes, or go with the classic route of `open()` + `stat()` + `chmod()` + `read()` + `write()`, that's guaranteed to work across all UNIX-like systems, and perhaps even Windows.- What is each platform's fastest solution to copy a file with attributes?
- I am looking copy files platform-dependently on Linux, Oracle Solaris, MacOS, BSDs, and Windows.
- I have found some system calls for each platform, namely `sendfile()`, `copy_file_range()`, `fcopyfile()`, `CopyFile()` et cetera. But some of them are documented to copy file attributes, whilst some are not. I am uncertain whether it would be better to do a `stat()` + `chmod()` prior the syscalls that do not copy attributes, or go with the classic route of `open()` + `stat()` + `chmod()` + `read()` + `write()`, that's guaranteed to work across all UNIX-like systems, and perhaps even Windows.
- What is each platform's fastest solution to copy a file with attributes?
#4: Post edited
Is Linux's 3 syscalls, and FreeBSD's and Solaris' sendfile function copying file attributes to the new file?
- What's the fastest way to copy, preserving file attributes, on each platform?
I am looking for efficient solutions to copy files platform-dependently and discovered the following functions:* Linux:- `ioctl()` with `FICLONE` (`cp` uses this by default).- `copy_file_range()`.- `sendfile()`.* Solaris:- `sendfile()`.* MacOS:- `clonefile()`. (Apple's `cp -c` uses this).- `fcopyfile()`.* FreeBSD:- `copy_file_range()`.- `fcopyfile()`.* Windows:- `Copyfile()`.Now Windows's [`Copyfile()`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-copyfile?redirectedfrom=MSDN) documents that it copies file attributes to the new file. MacOS's [`clonefile()`](https://www.unix.com/man-page/mojave/2/clonefile/) also documents the same. FreeBSD's and MacOs's `fcopyfile()` will also copy file attribute when specified proper flags.But what about Linux's 3 syscalls, and FreeBSD's and Solaris' `sendfile()`? I did not see it documented in their respective manual pages. Do they copy file attributes as well, or do I have to resort to `stat()`/`fstat()` followed by `chmod()`/`fchmod()` prior to these syscalls to achieve the desired result?
- I am looking copy files platform-dependently on Linux, Oracle Solaris, MacOS, BSDs, and Windows.
- I have found some system calls for each platform, namely `sendfile()`, `copy_file_range()`, `fcopyfile()`, `CopyFile()` et cetera. But some of them are documented to copy file attributes, whilst some are not. I am uncertain whether better to do a `stat()` + `chmod()` for syscalls that do not copy attributes, or go with the classic route of `open()` + `stat()` + `chmod()` + `read()` + `write()`, that's guaranteed to work across all UNIX-like systems, and perhaps even Windows.
- What is each platform's fastest solution to copy a file with attributes?
#3: Post edited
Do these platform-dependent file copying functions copy file attributes?
- Is Linux's 3 syscalls, and FreeBSD's and Solaris' sendfile function copying file attributes to the new file?
#2: Post edited
Do these platform-dependent efficient file copying functions copy file attributes?
- Do these platform-dependent file copying functions copy file attributes?
#1: Initial revision
Do these platform-dependent efficient file copying functions copy file attributes?
I am looking for efficient solutions to copy files platform-dependently and discovered the following functions: * Linux: - `ioctl()` with `FICLONE` (`cp` uses this by default). - `copy_file_range()`. - `sendfile()`. * Solaris: - `sendfile()`. * MacOS: - `clonefile()`. (Apple's `cp -c` uses this). - `fcopyfile()`. * FreeBSD: - `copy_file_range()`. - `fcopyfile()`. * Windows: - `Copyfile()`. Now Windows's [`Copyfile()`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-copyfile?redirectedfrom=MSDN) documents that it copies file attributes to the new file. MacOS's [`clonefile()`](https://www.unix.com/man-page/mojave/2/clonefile/) also documents the same. FreeBSD's and MacOs's `fcopyfile()` will also copy file attribute when specified proper flags. But what about Linux's 3 syscalls, and FreeBSD's and Solaris' `sendfile()`? I did not see it documented in their respective manual pages. Do they copy file attributes as well, or do I have to resort to `stat()`/`fstat()` followed by `chmod()`/`fchmod()` prior to these syscalls to achieve the desired result?