digitalmars.D.learn - Copying file to /dev/null
- axricard (18/20) Jan 24 ``` D
- Jonathan M Davis (6/26) Jan 24 Per copy's documentation, it preserve's the file's timestamps, and looki...
``` D
import std;
void main()
{
auto sourceName = deleteme ~ "source";
auto source = File(sourceName, "w");
source.write("source");
copy(sourceName, "/dev/null");
}
```
The copy to /dev/null fails :
`std.file.FileException std/file.d(4348): /dev/null: Invalid
argument`, which is a little surprising. Why would it be an
invalid argument ?
The cp command for example doesn't raise any error :
```
cp source /dev/null
echo $?
0
```
Jan 24
On Friday, January 24, 2025 2:57:05 AM MST axricard via Digitalmars-d-learn
wrote:
``` D
import std;
void main()
{
auto sourceName = deleteme ~ "source";
auto source = File(sourceName, "w");
source.write("source");
copy(sourceName, "/dev/null");
}
```
The copy to /dev/null fails :
`std.file.FileException std/file.d(4348): /dev/null: Invalid
argument`, which is a little surprising. Why would it be an
invalid argument ?
The cp command for example doesn't raise any error :
```
cp source /dev/null
echo $?
0
```
Per copy's documentation, it preserve's the file's timestamps, and looking
at where the exception is coming from, setting the access and modification
times on /dev/null is apparently illegal (which isn't particularly
surprising).
- Jonathan M Davis
Jan 24








Jonathan M Davis <newsgroup.d jmdavisprog.com>