Writes to a file.
write-file writes <content> to <file>. If an optional "append" is used, the <content> is appended to the file; otherwise the file is overwritten with <content>, unless "position" clause is used in which case file is not overwritten and <content> is written at byte <position>.
File is created if it does not exist (even if "append" is used), unless "position" clause is used in which case it must exist. If optional "length" clause is used, then only <length> bytes are written to the file. The status of writing can be obtained via "status" clause, so <status> will be the number of bytes written (0 or positive), VV_ERR_OPEN if cannot open file, VV_ERR_WRITE if cannot write and VV_ERR_POSITION if cannot position in the file. Note that if less than requested number of bytes is written, that is considered an error and VV_ERR_WRITE will be reported.
You can specify full path of the file or a path relative to the application home directory (see
vv).
If "length" is not used, then a string is written, and the number of bytes written is the length of that string. If "length" is specified, then exactly <length> bytes is written and <content> can hold a binary value or a string.
To overwrite file "/path/to/file" with "Hello World":
write-file "/path/to/file" from "Hello World"
To append "Hello World" to file:
char *path="/path/to/file";
char *cont="Hello World";
write-file path from cont append
To write only 5 bytes (i.e. "Hello") and get status (if successful, number variable "st" would be "5"):
char *cont="Hello World";
write-file "file" from cont length 5 status define st
To write a string "Hello" at byte position 3 in the existing "file":
char *cont="Hello";
write-file "file" from cont position 3 status define st