This PR fixes the problem with handling of irregular file names described in #17612
It also defines a helper function EnsureFileWritable that is used by dumptxoutset and dumpwallet.
This function checks for:
- file name existence (if only a dir-path was given the execution stops with a corresponding JSON error)
- file name validity for the current OS
- write permissions
- file existence (if a file already exists the dump* operation stops, like it was done in previous versions)
The already existing JSON objects and their messages have been preserved to prevent failing of tests and/or 3rd party tools whose parsers maybe rely on them.
A functional test was added in test/functional/rpc_dumptxoutset.py
Closes: #17612
Notice: the original PR was #17615 but due to an error at squashing changes it got automatically closed by GitHub and could not be reopened again.