On 24.01.2014 23:02, Eric Blake wrote: > On 01/23/2014 06:44 AM, Michal Privoznik wrote: >> The mocking will be used in later commits to mock all calls to the >> virCommandRun(). This is easier to do than cutting off the command >> creation and run into two separate pieces. >> >> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- >> tests/Makefile.am | 9 ++++ >> tests/virnetdevbandwidthmock.c | 106 >> +++++++++++++++++++++++++++++++++++++++++ >> tests/virnetdevbandwidthtest.c | 21 +++++++- 3 files changed, 135 >> insertions(+), 1 deletion(-) create mode 100644 >> tests/virnetdevbandwidthmock.c > >> + + if ((fd = open(outfile, O_WRONLY | O_APPEND | O_CREAT, >> S_IRUSR | S_IWUSR)) == -1) { + STDERR("unable to open file: >> %s %d", outfile, errno); + goto cleanup; + } + + if >> (safewrite(fd, buf, strlen(buf)) < 0 || + safewrite(fd, >> "\n", 1) < 0) { + STDERR("unable to write to file: %s %d", >> outfile, errno); + goto cleanup; + } > > This could be simplified with virFileWriteStr(). Not really. I need to append to the file, while virFileWriteStr() truncate the file prior to writing to it. Always. > >> + + if (VIR_STRDUP_QUIET(outfile, OUTFILETEMPLATE) < 0) { + >> fprintf(stderr, "Out of memory\n"); + abort(); + } + + if >> (!mktemp(outfile)) { > > I'd prefer mkstemp(), for safety. > Uh.. okay. Michal -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list