Copying file to /dev/null

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Jan 24 10:21:34 UTC 2025


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 at 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





More information about the Digitalmars-d-learn mailing list