mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
internal: Introduce virCheckNonEmptyStringArgGoto and reuse it
The helper makes sure that strings passed to APIs are non-NULL and non-empty. This allows to drop some inlined checks where it does not make sense.
This commit is contained in:
parent
d637017f9b
commit
14062e6fe5
@ -446,6 +446,17 @@
|
||||
goto label; \
|
||||
} \
|
||||
} while (0)
|
||||
# define virCheckNonEmptyStringArgGoto(argname, label) \
|
||||
do { \
|
||||
if (argname == NULL) { \
|
||||
virReportInvalidNonNullArg(argname); \
|
||||
goto label; \
|
||||
} \
|
||||
if (*argname == '\0') { \
|
||||
virReportInvalidEmptyStringArg(argname); \
|
||||
goto label; \
|
||||
} \
|
||||
} while (0)
|
||||
# define virCheckPositiveArgGoto(argname, label) \
|
||||
do { \
|
||||
if (argname <= 0) { \
|
||||
|
@ -6065,7 +6065,7 @@ virDomainBlockPeek(virDomainPtr dom,
|
||||
conn = dom->conn;
|
||||
|
||||
virCheckReadOnlyGoto(conn->flags, error);
|
||||
virCheckNonNullArgGoto(disk, error);
|
||||
virCheckNonEmptyStringArgGoto(disk, error);
|
||||
|
||||
/* Allow size == 0 as an access test. */
|
||||
if (size > 0)
|
||||
@ -6333,7 +6333,7 @@ virDomainGetBlockInfo(virDomainPtr domain, const char *disk,
|
||||
memset(info, 0, sizeof(*info));
|
||||
|
||||
virCheckDomainReturn(domain, -1);
|
||||
virCheckNonNullArgGoto(disk, error);
|
||||
virCheckNonEmptyStringArgGoto(disk, error);
|
||||
virCheckNonNullArgGoto(info, error);
|
||||
|
||||
conn = domain->conn;
|
||||
|
@ -11530,12 +11530,6 @@ qemuDomainBlockPeek(virDomainPtr dom,
|
||||
if (virDomainBlockPeekEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!path || path[0] == '\0') {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
"%s", _("NULL or empty path"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Check the path belongs to this domain. */
|
||||
if (!(actual = virDomainDiskPathByName(vm->def, path))) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
@ -11821,11 +11815,6 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
|
||||
if (virDomainGetBlockInfoEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!path || path[0] == '\0') {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s", _("NULL or empty path"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Technically, we only need a job if we are going to query the
|
||||
* monitor, which is only for active domains that are using
|
||||
* non-raw block devices. But it is easier to share code if we
|
||||
|
@ -95,6 +95,17 @@ void virReportSystemErrorFull(int domcode,
|
||||
0, 0, \
|
||||
_("%s in %s must not be NULL"), \
|
||||
#argname, __FUNCTION__)
|
||||
# define virReportInvalidEmptyStringArg(argname) \
|
||||
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
||||
VIR_FROM_THIS, \
|
||||
VIR_ERR_INVALID_ARG, \
|
||||
VIR_ERR_ERROR, \
|
||||
__FUNCTION__, \
|
||||
#argname, \
|
||||
NULL, \
|
||||
0, 0, \
|
||||
_("string %s in %s must not be empty"), \
|
||||
#argname, __FUNCTION__)
|
||||
# define virReportInvalidPositiveArg(argname) \
|
||||
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
||||
VIR_FROM_THIS, \
|
||||
|
Loading…
x
Reference in New Issue
Block a user