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.
What's the fastest way to copy, preserving file attributes, on each platform?
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 comment threads