int
virTestLoadFile(const char *file, char **buf)
{
- FILE *fp = fopen(file, "r");
+ g_autoptr(FILE) fp = fopen(file, "r");
struct stat st;
char *tmp;
int len, tmplen, buflen;
if (fstat(fileno(fp), &st) < 0) {
fprintf(stderr, "%s: failed to fstat: %s\n", file, g_strerror(errno));
- VIR_FORCE_FCLOSE(fp);
return -1;
}
}
if (ferror(fp)) {
fprintf(stderr, "%s: read failed: %s\n", file, g_strerror(errno));
- VIR_FORCE_FCLOSE(fp);
VIR_FREE(*buf);
return -1;
}
}
- VIR_FORCE_FCLOSE(fp);
return 0;
}
int ret = -1;
g_autofree char *actualData = NULL;
virNodeInfo nodeinfo;
- FILE *cpuinfo;
+ g_autoptr(FILE) cpuinfo = NULL;
cpuinfo = fopen(cpuinfofile, "r");
if (!cpuinfo) {
if (virGetLastErrorCode())
VIR_TEST_DEBUG("\n%s", virGetLastErrorMessage());
}
- VIR_FORCE_FCLOSE(cpuinfo);
goto fail;
}
- VIR_FORCE_FCLOSE(cpuinfo);
actualData = g_strdup_printf("CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, "
"Cores: %u, Threads: %u\n",
{
int ret = -1;
g_autofree char *actualData = NULL;
- FILE *cpustat = NULL;
+ g_autoptr(FILE) cpustat = NULL;
virNodeCPUStatsPtr params = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
ret = 0;
fail:
- VIR_FORCE_FCLOSE(cpustat);
VIR_FREE(params);
return ret;
}