respectively. The last argument is the number of bytes
available in the destination string; if a copy of the source
string (including a \0) will not fit into the destination, no
- bytes are copied and the routine returns NULL. Otherwise, n
+ bytes are copied and the routine returns <0. Otherwise, n
bytes from the source are copied into the destination and a
trailing \0 is appended.
</p>
memset(nodeinfo, 0, sizeof(*nodeinfo));
- if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) == NULL)
+ if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) < 0)
return -1;
if (virHostMemGetInfo(&memorybytes, NULL) < 0)
}
if (virtPortProfileID &&
- !virStrcpyStatic(virtPort->profileID, virtPortProfileID)) {
+ virStrcpyStatic(virtPort->profileID, virtPortProfileID) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("profileid parameter too long"));
goto error;
{
const char *errmsg = NULL;
- if (virStrcpyStatic(item->u.ipset.setname, val->c) == NULL) {
+ if (virStrcpyStatic(item->u.ipset.setname, val->c) < 0) {
errmsg = _("ipset name is too long");
goto arg_err_exit;
}
goto cleanup;
}
- if (!virStrcpyStatic(vCenterIPAddress,
- potentialVCenterIPAddress)) {
+ if (virStrcpyStatic(vCenterIPAddress,
+ potentialVCenterIPAddress) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vCenter IP address %s too big for destination"),
potentialVCenterIPAddress);
++ptr;
}
- if (!virStrcpyStatic(nodeinfo->model, dynamicProperty->val->string)) {
+ if (virStrcpyStatic(nodeinfo->model, dynamicProperty->val->string) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("CPU Model %s too long for destination"),
dynamicProperty->val->string);
if (VIR_ALLOC_N(buffer, size + 1) < 0)
return 0;
- if (!virStrncpy(buffer, info, size, size + 1)) {
+ if (virStrncpy(buffer, info, size, size + 1) < 0) {
VIR_FREE(buffer);
return 0;
}
return -1;
}
- if (!virStrcpyStatic(value, dateTime->value)) {
+ if (virStrcpyStatic(value, dateTime->value) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("xsd:dateTime value '%s' too long for destination"),
dateTime->value);
}
/* Fill struct */
- if (virStrcpyStatic(info->model, processorList->data.common->Name) == NULL) {
+ if (virStrcpyStatic(info->model, processorList->data.common->Name) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("CPU model %s too long for destination"),
processorList->data.common->Name);
goto cleanup;
}
- if (virStrcpyStatic(info->model, virArchToString(hostarch)) == NULL) {
+ if (virStrcpyStatic(info->model, virArchToString(hostarch)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("machine type %s too big for destination"),
virArchToString(hostarch));
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0)
goto error;
- if (!virStrcpyStatic(ls.name,
- VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE)) {
+ if (virStrcpyStatic(ls.name,
+ VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Lockspace path '%s' exceeded %d characters"),
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE,
}
ls.host_id = 0; /* Doesn't matter for initialization */
ls.flags = 0;
- if (!virStrcpy(ls.host_id_disk.path, path, SANLK_PATH_LEN)) {
+ if (virStrcpy(ls.host_id_disk.path, path, SANLK_PATH_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Lockspace path '%s' exceeded %d characters"),
path, SANLK_PATH_LEN);
res->flags = shared ? SANLK_RES_SHARED : 0;
res->num_disks = 1;
- if (!virStrcpy(res->name, name, SANLK_NAME_LEN)) {
+ if (virStrcpy(res->name, name, SANLK_NAME_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Resource name '%s' exceeds %d characters"),
name, SANLK_NAME_LEN);
for (i = 0; i < nparams; i++) {
if (STREQ(params[i].key, "path")) {
- if (!virStrcpy(res->disks[0].path, params[i].value.str, SANLK_PATH_LEN)) {
+ if (virStrcpy(res->disks[0].path, params[i].value.str, SANLK_PATH_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Lease path '%s' exceeds %d characters"),
params[i].value.str, SANLK_PATH_LEN);
} else if (STREQ(params[i].key, "offset")) {
res->disks[0].offset = params[i].value.ul;
} else if (STREQ(params[i].key, "lockspace")) {
- if (!virStrcpy(res->lockspace_name, params[i].value.str, SANLK_NAME_LEN)) {
+ if (virStrcpy(res->lockspace_name, params[i].value.str, SANLK_NAME_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Resource lockspace '%s' exceeds %d characters"),
params[i].value.str, SANLK_NAME_LEN);
res->num_disks = 1;
if (virCryptoHashString(VIR_CRYPTO_HASH_MD5, name, &hash) < 0)
goto cleanup;
- if (!virStrcpy(res->name, hash, SANLK_NAME_LEN)) {
+ if (virStrcpy(res->name, hash, SANLK_NAME_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("MD5 hash '%s' unexpectedly larger than %d characters"),
hash, (SANLK_NAME_LEN - 1));
if (virAsprintf(&path, "%s/%s",
driver->autoDiskLeasePath, res->name) < 0)
goto cleanup;
- if (!virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN)) {
+ if (virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Lease path '%s' exceeds %d characters"),
path, SANLK_PATH_LEN);
goto cleanup;
}
- if (!virStrcpy(res->lockspace_name,
- VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE,
- SANLK_NAME_LEN)) {
+ if (virStrcpy(res->lockspace_name,
+ VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE,
+ SANLK_NAME_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Resource lockspace '%s' exceeds %d characters"),
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE, SANLK_NAME_LEN);
|| caps->host.secModels[0].model == NULL)
goto cleanup;
- if (!virStrcpy(secmodel->model, caps->host.secModels[0].model,
- VIR_SECURITY_MODEL_BUFLEN)) {
+ if (virStrcpy(secmodel->model, caps->host.secModels[0].model,
+ VIR_SECURITY_MODEL_BUFLEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security model string exceeds max %d bytes"),
VIR_SECURITY_MODEL_BUFLEN - 1);
goto cleanup;
}
- if (!virStrcpy(secmodel->doi, caps->host.secModels[0].doi,
- VIR_SECURITY_DOI_BUFLEN)) {
+ if (virStrcpy(secmodel->doi, caps->host.secModels[0].doi,
+ VIR_SECURITY_DOI_BUFLEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("security DOI string exceeds max %d bytes"),
VIR_SECURITY_DOI_BUFLEN-1);
req->threadStatus = THREAD_STATUS_NONE;
- if (virStrcpyStatic(req->ifkey, ifkey) == NULL ||
+ if (virStrcpyStatic(req->ifkey, ifkey) < 0||
virMutexInitRecursive(&req->lock) < 0)
goto err_free_req;
return -1;
}
- if (!virStrcpy(buf, val, bufsize)) {
+ if (virStrcpy(buf, val, bufsize) < 0) {
const char *varName;
varName = virNWFilterVarAccessGetVarName(item->varAccess);
break;
case DATATYPE_IPSETNAME:
- if (virStrcpy(buf, item->u.ipset.setname, bufsize) == NULL) {
+ if (virStrcpy(buf, item->u.ipset.setname, bufsize) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Buffer to small for ipset name"));
return -1;
flags = virBufferContentAndReset(&vb);
- if (virStrcpy(buf, flags, bufsize) == NULL) {
+ if (virStrcpy(buf, flags, bufsize) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Buffer too small for IPSETFLAGS type"));
VIR_FREE(flags);
goto err_exit;
}
- if (virStrcpyStatic(ifaceLock->ifname, ifname) == NULL) {
+ if (virStrcpyStatic(ifaceLock->ifname, ifname) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("interface name %s does not fit into "
"buffer "),
if (VIR_ALLOC_N(net->ifname, len+1) < 0)
goto error;
- if (virStrncpy(net->ifname, p, len, len+1) == NULL) {
+ if (virStrncpy(net->ifname, p, len, len+1) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Network ifname %s too long for destination"), p);
goto error;
if (VIR_ALLOC_N(net->data.bridge.brname, len+1) < 0)
goto error;
- if (virStrncpy(net->data.bridge.brname, p, len, len+1) == NULL) {
+ if (virStrncpy(net->data.bridge.brname, p, len, len+1) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Bridge name %s too long for destination"), p);
goto error;
_("Wrong length MAC address"));
goto error;
}
- if (virStrncpy(cpy_temp, p, len, sizeof(cpy_temp)) == NULL) {
+ if (virStrncpy(cpy_temp, p, len, sizeof(cpy_temp)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("MAC address %s too long for destination"), p);
goto error;
uuidbuf = strtok_r(NULL, "\n", &saveptr);
if (iden != NULL && uuidbuf != NULL && STREQ(iden, "#UUID:")) {
- if (virStrcpy(uuidstr, uuidbuf, len) == NULL) {
+ if (virStrcpy(uuidstr, uuidbuf, len) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid uuid %s"), uuidbuf);
goto cleanup;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- if (virStrcpyStatic(addr.sun_path, monitor) == NULL) {
+ if (virStrcpyStatic(addr.sun_path, monitor) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Agent path %s too big for destination"), monitor);
goto error;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- if (virStrcpyStatic(addr.sun_path, dev->data.nix.path) == NULL) {
+ if (virStrcpyStatic(addr.sun_path, dev->data.nix.path) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("UNIX socket path '%s' too long"),
dev->data.nix.path);
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- if (virStrcpyStatic(addr.sun_path, monitor) == NULL) {
+ if (virStrcpyStatic(addr.sun_path, monitor) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Monitor path %s too big for destination"), monitor);
goto error;
/* Deserialise the result. */
for (i = 0; i < *nparams; ++i) {
- if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) == NULL) {
+ if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Stats %s too big for destination"),
ret.params.params_val[i].field);
/* Deserialise the result. */
for (i = 0; i < *nparams; ++i) {
- if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) == NULL) {
+ if (virStrcpyStatic(params[i].field, ret.params.params_val[i].field) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Stats %s too big for destination"),
ret.params.params_val[i].field);
virConnectCredential retr_passphrase;
int cred_type;
char *actual_prompt = NULL;
- char *p;
+ int p;
/* request user's key password */
if (!sess->cred || !sess->cred->cb) {
p = virStrncpy(buf, retr_passphrase.result,
retr_passphrase.resultlen, len);
VIR_DISPOSE_STRING(retr_passphrase.result);
- if (!p) {
+ if (p < 0) {
virReportError(VIR_ERR_LIBSSH, "%s",
_("passphrase is too long for the buffer"));
goto error;
}
addr.data.un.sun_family = AF_UNIX;
- if (virStrcpyStatic(addr.data.un.sun_path, path) == NULL) {
+ if (virStrcpyStatic(addr.data.un.sun_path, path) < 0) {
virReportSystemError(ENAMETOOLONG,
_("Path %s too long for unix socket"), path);
goto error;
}
remoteAddr.data.un.sun_family = AF_UNIX;
- if (virStrcpyStatic(remoteAddr.data.un.sun_path, path) == NULL) {
+ if (virStrcpyStatic(remoteAddr.data.un.sun_path, path) < 0) {
virReportSystemError(ENOMEM, _("Path %s too long for unix socket"), path);
goto cleanup;
}
}
if (virStrcpy(sec->label, profile_name,
- VIR_SECURITY_LABEL_BUFLEN) == NULL) {
+ VIR_SECURITY_LABEL_BUFLEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("error copying profile name"));
goto cleanup;
if (strlen(optarg) > PROFILE_NAME_SIZE - 1)
vah_error(ctl, 1, _("invalid UUID"));
if (virStrcpy((char *)ctl->uuid, optarg,
- PROFILE_NAME_SIZE) == NULL)
+ PROFILE_NAME_SIZE) < 0)
vah_error(ctl, 1, _("error copying UUID"));
break;
default:
int totalLen = baseLen + strlen(filename) + 1;
if (VIR_ALLOC_N(absFile, totalLen) < 0)
return NULL;
- if (virStrncpy(absFile, relativeTo, baseLen, totalLen) == NULL) {
+ if (virStrncpy(absFile, relativeTo, baseLen, totalLen) < 0) {
VIR_FREE(absFile);
return NULL;
}
str = virXPathString("string(/node/cpu/model[1])", ctxt);
if (str != NULL) {
- if (virStrcpyStatic(nodeInfo->model, str) == NULL) {
+ if (virStrcpyStatic(nodeInfo->model, str) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Model %s too big for destination"), str);
VIR_FREE(str);
memset(addr, 0, sizeof(*addr));
addr->sun_family = AF_UNIX;
- if (virStrcpyStatic(addr->sun_path, sockname) == NULL) {
+ if (virStrcpyStatic(addr->sun_path, sockname) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unix path %s too long for destination"), sockname);
retval = -1;
cmd, req.length);
return -1;
}
- if (virStrcpyStatic(req.data, cmd) == NULL) {
+ if (virStrcpyStatic(req.data, cmd) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Command %s too long for destination"), cmd);
return -1;
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
if (abstract) {
- if (virStrcpy(sa.sun_path+1, path, sizeof(sa.sun_path)-1) == NULL)
+ if (virStrcpy(sa.sun_path+1, path, sizeof(sa.sun_path)-1) < 0)
goto error;
sa.sun_path[0] = '\0';
} else {
- if (virStrcpyStatic(sa.sun_path, path) == NULL)
+ if (virStrcpyStatic(sa.sun_path, path) < 0)
goto error;
}
for (i = 0; cpu_map[i].field != NULL; i++) {
virNodeCPUStatsPtr param = ¶ms[i];
- if (virStrcpyStatic(param->field, cpu_map[i].field) == NULL) {
+ if (virStrcpyStatic(param->field, cpu_map[i].field) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Field '%s' too long for destination"),
cpu_map[i].field);
const char *name,
unsigned long long value)
{
- if (virStrcpyStatic(param->field, name) == NULL) {
+ if (virStrcpyStatic(param->field, name) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("kernel cpu time field is too long"
" for the destination"));
}
param = ¶ms[j++];
- if (virStrcpyStatic(param->field, sysctl_map[i].field) == NULL) {
+ if (virStrcpyStatic(param->field, sysctl_map[i].field) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Field '%s' too long for destination"),
sysctl_map[i].field);
"vfs.bufspace");
return -1;
}
- if (virStrcpyStatic(param->field, VIR_NODE_MEMORY_STATS_BUFFERS) == NULL) {
+ if (virStrcpyStatic(param->field, VIR_NODE_MEMORY_STATS_BUFFERS) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Field '%s' too long for destination"),
VIR_NODE_MEMORY_STATS_BUFFERS);
if (STREQ(meminfo_hdr, convp->meminfo_hdr)) {
virNodeMemoryStatsPtr param = ¶ms[k++];
- if (virStrcpyStatic(param->field, convp->field) == NULL) {
+ if (virStrcpyStatic(param->field, convp->field) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Field kernel memory too long for destination"));
goto cleanup;
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
- if (!virStrcpyStatic(sa.sun_path, "/run/systemd/journal/socket"))
+ if (virStrcpyStatic(sa.sun_path, "/run/systemd/journal/socket") < 0)
return;
memset(&mh, 0, sizeof(mh));
if (ifr && ifname) {
memset(ifr, 0, sizeof(*ifr));
- if (virStrcpyStatic(ifr->ifr_name, ifname) == NULL) {
+ if (virStrcpyStatic(ifr->ifr_name, ifname) < 0) {
virReportSystemError(ERANGE,
_("Network interface name '%s' is too long"),
ifname);
return -1;
# ifdef HAVE_STRUCT_IFREQ_IFR_NEWNAME
- if (virStrcpyStatic(ifr.ifr_newname, newifname) == NULL) {
+ if (virStrcpyStatic(ifr.ifr_newname, newifname) < 0) {
virReportSystemError(ERANGE,
_("Network interface name '%s' is too long"),
newifname);
memset(&ifreq, 0, sizeof(ifreq));
- if (virStrcpyStatic(ifreq.ifr_name, ifname) == NULL) {
+ if (virStrcpyStatic(ifreq.ifr_name, ifname) < 0) {
virReportSystemError(ERANGE,
_("invalid interface name %s"),
ifname);
return -1;
}
- if (virStrcpyStatic(vlanargs.device1, ifname) == NULL) {
+ if (virStrcpyStatic(vlanargs.device1, ifname) < 0) {
virReportSystemError(ERANGE,
_("invalid interface name %s"),
ifname);
mcast->idx = num;
break;
case VIR_MCAST_TYPE_NAME_TOKEN:
- if (virStrcpy(mcast->name, token, VIR_MCAST_NAME_LEN) == NULL) {
+ if (virStrcpy(mcast->name, token, VIR_MCAST_NAME_LEN) < 0) {
virReportSystemError(EINVAL,
_("Failed to parse network device name from '%s'"),
buf);
return -1;
}
- if (virStrcpyStatic(ifd.ifd_name, brname) == NULL) {
+ if (virStrcpyStatic(ifd.ifd_name, brname) < 0) {
virReportSystemError(ERANGE,
_("Network interface name '%s' is too long"),
brname);
struct ifbreq req;
memset(&req, 0, sizeof(req));
- if (virStrcpyStatic(req.ifbr_ifsname, ifname) == NULL) {
+ if (virStrcpyStatic(req.ifbr_ifsname, ifname) < 0) {
virReportSystemError(ERANGE,
_("Network interface name '%s' is too long"),
ifname);
struct ifbreq req;
memset(&req, 0, sizeof(req));
- if (virStrcpyStatic(req.ifbr_ifsname, ifname) == NULL) {
+ if (virStrcpyStatic(req.ifbr_ifsname, ifname) < 0) {
virReportSystemError(ERANGE,
_("Network interface name '%s' is too long"),
ifname);
ifr.ifr_flags |= IFF_VNET_HDR;
# endif
- if (virStrcpyStatic(ifr.ifr_name, *ifname) == NULL) {
+ if (virStrcpyStatic(ifr.ifr_name, *ifname) < 0) {
virReportSystemError(ERANGE,
_("Network interface name '%s' is too long"),
*ifname);
memset(&try, 0, sizeof(struct ifreq));
try.ifr_flags = IFF_TAP|IFF_NO_PI;
- if (virStrcpyStatic(try.ifr_name, ifname) == NULL) {
+ if (virStrcpyStatic(try.ifr_name, ifname) < 0) {
virReportSystemError(ERANGE,
_("Network interface name '%s' is too long"),
ifname);
orig->profileID, mods->profileID);
return -1;
}
- if (virStrcpyStatic(orig->profileID, mods->profileID) == NULL) {
+ if (virStrcpyStatic(orig->profileID, mods->profileID) < 0) {
/* this should never happen - it indicates mods->profileID
* isn't properly null terminated. */
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
break;
if (tb[IFLA_IFNAME]) {
- if (!virStrcpy(parent_ifname, (char*)RTA_DATA(tb[IFLA_IFNAME]),
- IFNAMSIZ)) {
+ if (virStrcpy(parent_ifname, (char*)RTA_DATA(tb[IFLA_IFNAME]),
+ IFNAMSIZ) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("buffer for root interface name is too small"));
rc = -1;
* A safe version of strncpy. The last parameter is the number of bytes
* available in the destination string, *not* the number of bytes you want
* to copy. If the destination is not large enough to hold all n of the
- * src string bytes plus a \0, NULL is returned and no data is copied.
+ * src string bytes plus a \0, <0 is returned and no data is copied.
* If the destination is large enough to hold the n bytes plus \0, then the
- * string is copied and a pointer to the destination string is returned.
+ * string is copied and 0 is returned.
*/
-char *
+int
virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
{
- char *ret;
-
if (n > (destbytes - 1))
- return NULL;
+ return -1;
- ret = strncpy(dest, src, n);
+ strncpy(dest, src, n);
/* strncpy NULL terminates iff the last character is \0. Therefore
* force the last byte to be \0
*/
dest[n] = '\0';
- return ret;
+ return 0;
}
/**
* A safe version of strcpy. The last parameter is the number of bytes
* available in the destination string, *not* the number of bytes you want
* to copy. If the destination is not large enough to hold all n of the
- * src string bytes plus a \0, NULL is returned and no data is copied.
+ * src string bytes plus a \0, <0 is returned and no data is copied.
* If the destination is large enough to hold the source plus \0, then the
- * string is copied and a pointer to the destination string is returned.
+ * string is copied and 0 is returned.
*/
-char *
+int
virStrcpy(char *dest, const char *src, size_t destbytes)
{
return virStrncpy(dest, src, strlen(src), destbytes);
bool virStringIsEmpty(const char *str);
-char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
+int virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
ATTRIBUTE_RETURN_CHECK;
-char *virStrcpy(char *dest, const char *src, size_t destbytes)
+int virStrcpy(char *dest, const char *src, size_t destbytes)
ATTRIBUTE_RETURN_CHECK;
# define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest))
if (VIR_RESIZE_N(keys, nkeysalloc, nkeys, 1) < 0)
goto cleanup;
- if (virStrcpyStatic(keys[nkeys].field, name) == NULL) {
+ if (virStrcpyStatic(keys[nkeys].field, name) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Field name '%s' too long"), name);
goto cleanup;
va_start(ap, type);
- if (virStrcpyStatic(param->field, name) == NULL) {
+ if (virStrcpyStatic(param->field, name) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
name);
goto cleanup;
goto cleanup;
}
- if (virStrcpyStatic(param->field, name) == NULL) {
+ if (virStrcpyStatic(param->field, name) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
name);
goto cleanup;
virTypedParameterRemotePtr remote_param = remote_params + i;
if (virStrcpyStatic(param->field,
- remote_param->field) == NULL) {
+ remote_param->field) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("parameter %s too big for destination"),
remote_param->field);
if (xen_host_cpu_get_all(session, &host_cpu_set)) {
host_cpu = host_cpu_set->contents[0];
xen_host_cpu_get_modelname(session, &modelname, host_cpu);
- if (!virStrncpy(info->model, modelname,
- MIN(strlen(modelname), LIBVIRT_MODELNAME_LEN - 1),
- LIBVIRT_MODELNAME_LEN)) {
+ if (virStrncpy(info->model, modelname,
+ MIN(strlen(modelname), LIBVIRT_MODELNAME_LEN - 1),
+ LIBVIRT_MODELNAME_LEN) < 0) {
virReportOOMError();
xen_host_cpu_set_free(host_cpu_set);
VIR_FREE(modelname);
return NULL;
if (!(nextkey = strchr(key, ':')))
return NULL;
- if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) == NULL) {
+ if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Domain %s too big for destination"), key);
return NULL;
key = nextkey + 1;
if (!(nextkey = strchr(key, ':')))
return NULL;
- if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) == NULL) {
+ if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Bus %s too big for destination"), key);
return NULL;
key = nextkey + 1;
if (!(nextkey = strchr(key, '.')))
return NULL;
- if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) == NULL) {
+ if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Slot %s too big for destination"), key);
return NULL;
key = nextkey + 1;
if (strlen(key) != 1)
return NULL;
- if (virStrncpy(func, key, 1, sizeof(func)) == NULL) {
+ if (virStrncpy(func, key, 1, sizeof(func)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Function %s too big for destination"), key);
return NULL;
char vfb[MAX_VFB];
char *key = vfb;
- if (virStrcpyStatic(vfb, list->list->str) == NULL) {
+ if (virStrcpyStatic(vfb, list->list->str) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("VFB %s too big for destination"),
list->list->str);
if (STRPREFIX(key, "mac=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(mac, data, len, sizeof(mac)) == NULL) {
+ if (virStrncpy(mac, data, len, sizeof(mac)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("MAC address %s too big for destination"),
data);
}
} else if (STRPREFIX(key, "bridge=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(bridge, data, len, sizeof(bridge)) == NULL) {
+ if (virStrncpy(bridge, data, len, sizeof(bridge)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Bridge %s too big for destination"),
data);
return NULL;
} else if (STRPREFIX(key, "model=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(model, data, len, sizeof(model)) == NULL) {
+ if (virStrncpy(model, data, len, sizeof(model)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Model %s too big for destination"),
data);
}
} else if (STRPREFIX(key, "type=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
+ if (virStrncpy(type, data, len, sizeof(type)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Type %s too big for destination"),
data);
}
} else if (STRPREFIX(key, "vifname=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(vifname, data, len, sizeof(vifname)) == NULL) {
+ if (virStrncpy(vifname, data, len, sizeof(vifname)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Vifname %s too big for destination"),
data);
}
} else if (STRPREFIX(key, "ip=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(ip, data, len, sizeof(ip)) == NULL) {
+ if (virStrncpy(ip, data, len, sizeof(ip)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("IP %s too big for destination"), data);
return NULL;
}
} else if (STRPREFIX(key, "rate=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(rate, data, len, sizeof(rate)) == NULL) {
+ if (virStrncpy(rate, data, len, sizeof(rate)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("rate %s too big for destination"), data);
return NULL;
len = (offset2 - offset);
else
len = strlen(offset);
- if (virStrncpy(model, offset, len, sizeof(model)) == NULL) {
+ if (virStrncpy(model, offset, len, sizeof(model)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Sound model %s too big for destination"),
offset);
if (STRPREFIX(str, "pnode")) {
unsigned int cellid;
- if (!virStrcpyStatic(vtoken, data)) {
+ if (virStrcpyStatic(vtoken, data) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vnuma vnode %zu pnode '%s' too long for destination"),
vnodeCnt, data);
}
pnode = cellid;
} else if (STRPREFIX(str, "size")) {
- if (!virStrcpyStatic(vtoken, data)) {
+ if (virStrcpyStatic(vtoken, data) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vnuma vnode %zu size '%s' too long for destination"),
vnodeCnt, data);
virDomainNumaSetNodeMemorySize(numa, vnodeCnt, (kbsize * 1024));
} else if (STRPREFIX(str, "vcpus")) {
- if (!virStrcpyStatic(vtoken, data)) {
+ if (virStrcpyStatic(vtoken, data) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vnuma vnode %zu vcpus '%s' too long for destination"),
vnodeCnt, data);
size_t i, ndistances;
unsigned int value;
- if (!virStrcpyStatic(vtoken, data)) {
+ if (virStrcpyStatic(vtoken, data) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vnuma vnode %zu vdistances '%s' too long for destination"),
vnodeCnt, data);
if (STRPREFIX(key, "type=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
+ if (virStrncpy(type, data, len, sizeof(type)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("type %s invalid"),
data);
}
} else if (STRPREFIX(key, "version=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(version, data, len, sizeof(version)) == NULL) {
+ if (virStrncpy(version, data, len, sizeof(version)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("version %s invalid"),
data);
goto skipusbctrl;
} else if (STRPREFIX(key, "ports=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(ports, data, len, sizeof(ports)) == NULL) {
+ if (virStrncpy(ports, data, len, sizeof(ports)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("version %s invalid"),
data);
if (STRPREFIX(key, "hostbus=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(bus, data, len, sizeof(bus)) == NULL) {
+ if (virStrncpy(bus, data, len, sizeof(bus)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("bus %s too big for destination"),
data);
}
} else if (STRPREFIX(key, "hostaddr=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(device, data, len, sizeof(device)) == NULL) {
+ if (virStrncpy(device, data, len, sizeof(device)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("device %s too big for destination"),
data);
if (STRPREFIX(key, "connection=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
- if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
+ if (virStrncpy(type, data, len, sizeof(type)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("connection %s too big"), data);
goto skipchannel;
goto error;
if (virStrncpy(disk->dst, head, offset - head,
- (offset - head) + 1) == NULL) {
+ (offset - head) + 1) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Dest file %s too big for destination"), head);
goto error;