if (!(f = fopen(tmp, "w"))) {
istmp = false;
if (!(f = fopen(path, "w"))) {
- rc = errno;
+ rc = -errno;
goto cleanup;
}
}
for (i = 0; i < nhosts; i++) {
if (fputs(hosts[i].ip, f) == EOF || fputc('\t', f) == EOF) {
- rc = errno;
+ rc = -errno;
VIR_FORCE_FCLOSE(f);
if (istmp)
for (ii = 0; ii < hosts[i].nhostnames; ii++) {
if (fputs(hosts[i].hostnames[ii], f) == EOF || fputc('\t', f) == EOF) {
- rc = errno;
+ rc = -errno;
VIR_FORCE_FCLOSE(f);
if (istmp)
}
if (fputc('\n', f) == EOF) {
- rc = errno;
+ rc = -errno;
VIR_FORCE_FCLOSE(f);
if (istmp)
}
if (VIR_FCLOSE(f) == EOF) {
- rc = errno;
+ rc = -errno;
goto cleanup;
}
- if (istmp) {
- if (rename(tmp, path) < 0) {
- rc = errno;
- unlink(tmp);
- goto cleanup;
- }
-
- if (unlink(tmp) < 0) {
- rc = errno;
- goto cleanup;
- }
+ if (istmp && rename(tmp, path) < 0) {
+ rc = -errno;
+ unlink(tmp);
+ goto cleanup;
}
cleanup:
addnhostsfile->nhosts);
if (err < 0) {
- virReportSystemError(err, _("cannot write config file '%s'"),
+ virReportSystemError(-err, _("cannot write config file '%s'"),
addnhostsfile->path);
return -1;
}
goto cleanup;
}
- if (istmp) {
- if (rename(tmp, path) < 0) {
- rc = -errno;
- unlink(tmp);
- goto cleanup;
- }
-
- if (unlink(tmp) < 0) {
- rc = -errno;
- goto cleanup;
- }
+ if (istmp && rename(tmp, path) < 0) {
+ rc = -errno;
+ unlink(tmp);
+ goto cleanup;
}
cleanup:
hostsfile->nhosts);
if (err < 0) {
- virReportSystemError(err, _("cannot write config file '%s'"),
+ virReportSystemError(-err, _("cannot write config file '%s'"),
hostsfile->path);
return -1;
}