static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
{
- int fd = -1;
+ VIR_AUTOCLOSE fd = -1;
g_autofree char *file = NULL;
int ret = -1;
g_autofree char *pattern = NULL;
cleanup:
if (st)
virStreamFree(st);
- VIR_FORCE_CLOSE(fd);
if (file != NULL)
unlink(file);
if (conn)
static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
{
- int fd = -1;
+ VIR_AUTOCLOSE fd = -1;
g_autofree char *file = NULL;
int ret = -1;
g_autofree char *pattern = NULL;
cleanup:
if (st)
virStreamFree(st);
- VIR_FORCE_CLOSE(fd);
if (file != NULL)
unlink(file);
if (conn)
g_autofree char *link_path = NULL;
char *spot;
int ret = -1;
- int fd = -1;
+ VIR_AUTOCLOSE fd = -1;
unique_id_path = g_strdup_printf("%s/devices/pci0000:00/%s/unique_id",
fakesysfsdir, devicepath);
ret = 0;
cleanup:
- VIR_FORCE_CLOSE(fd);
return ret;
}
{
off_t offsets[] = {EXTENT, EXTENT, EXTENT, -1};
off_t tmp;
- int fd;
+ VIR_AUTOCLOSE fd = -1;
bool ret = false;
if ((fd = makeSparseFile(offsets, true)) < 0)
ret = true;
cleanup:
- VIR_FORCE_CLOSE(fd);
return ret;
}
testFileInData(const void *opaque)
{
const struct testFileInData *data = opaque;
- int fd = -1;
+ VIR_AUTOCLOSE fd = -1;
int ret = -1;
size_t i;
ret = 0;
cleanup:
- VIR_FORCE_CLOSE(fd);
return ret;
}
size_t ncerts)
{
size_t i;
- int fd;
+ VIR_AUTOCLOSE fd = -1;
int err;
static char buffer[1024*1024];
size_t size;
abort();
}
}
-
- VIR_FORCE_CLOSE(fd);
}
const char *value,
ssize_t len)
{
- int fd = -1;
+ VIR_AUTOCLOSE fd = -1;
g_autofree char *filepath = NULL;
if (value && len == -1)
len = strlen(value);
if (value && safewrite(fd, value, len) != len)
ABORT("Unable to write: %s", filepath);
-
- VIR_FORCE_CLOSE(fd);
}
static void
unlink(filename);
} else {
char buf[1024];
- int fd;
+ VIR_AUTOCLOSE fd = -1;
VIR_DEBUG("Creating %s size %zu", filename, (size_t)size);
if (safewrite(fd, buf, towrite) != towrite) {
fprintf(stderr, "Cannot write to %s\n", filename);
- VIR_FORCE_CLOSE(fd);
return -1;
}
size -= towrite;
}
- VIR_FORCE_CLOSE(fd);
}
return 0;
}